€•ZkŒsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ4/translations/zh_CN/filesystems/bcachefs/CodingStyle”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ4/translations/zh_TW/filesystems/bcachefs/CodingStyle”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ4/translations/it_IT/filesystems/bcachefs/CodingStyle”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ4/translations/ja_JP/filesystems/bcachefs/CodingStyle”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ4/translations/ko_KR/filesystems/bcachefs/CodingStyle”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ4/translations/sp_SP/filesystems/bcachefs/CodingStyle”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒcomment”“”)”}”(hŒ SPDX-License-Identifier: GPL-2.0”h]”hŒ SPDX-License-Identifier: GPL-2.0”…””}”hh£sbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1h¡hhhžhhŸŒN/var/lib/git/docbuild/linux/Documentation/filesystems/bcachefs/CodingStyle.rst”h KubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒbcachefs coding style”h]”hŒbcachefs coding style”…””}”(hh»hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¹hh¶hžhhŸh³h KubhŒ paragraph”“”)”}”(hXGood development is like gardening, and codebases are our gardens. Tend to them every day; look for little things that are out of place or in need of tidying. A little weeding here and there goes a long way; don't wait until things have spiraled out of control.”h]”hXGood development is like gardening, and codebases are our gardens. Tend to them every day; look for little things that are out of place or in need of tidying. A little weeding here and there goes a long way; don’t wait until things have spiraled out of control.”…””}”(hhËhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h Khh¶hžhubhÊ)”}”(hŒThings don't always have to be perfect - nitpicking often does more harm than good. But appreciate beauty when you see it - and let people know.”h]”hŒ’Things don’t always have to be perfect - nitpicking often does more harm than good. But appreciate beauty when you see it - and let people know.”…””}”(hhÙhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h K hh¶hžhubhÊ)”}”(hŒNThe code that you are afraid to touch is the code most in need of refactoring.”h]”hŒNThe code that you are afraid to touch is the code most in need of refactoring.”…””}”(hhçhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h Khh¶hžhubhÊ)”}”(hŒ3A little organizing here and there goes a long way.”h]”hŒ3A little organizing here and there goes a long way.”…””}”(hhõhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h Khh¶hžhubhÊ)”}”(hŒ.Put real thought into how you organize things.”h]”hŒ.Put real thought into how you organize things.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h Khh¶hžhubhÊ)”}”(hŒ^Good code is readable code, where the structure is simple and leaves nowhere for bugs to hide.”h]”hŒ^Good code is readable code, where the structure is simple and leaves nowhere for bugs to hide.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h Khh¶hžhubhÊ)”}”(hX„Assertions are one of our most important tools for writing reliable code. If in the course of writing a patchset you encounter a condition that shouldn't happen (and will have unpredictable or undefined behaviour if it does), or you're not sure if it can happen and not sure how to handle it yet - make it a BUG_ON(). Don't leave undefined or unspecified behavior lurking in the codebase.”h]”hXŠAssertions are one of our most important tools for writing reliable code. If in the course of writing a patchset you encounter a condition that shouldn’t happen (and will have unpredictable or undefined behaviour if it does), or you’re not sure if it can happen and not sure how to handle it yet - make it a BUG_ON(). Don’t leave undefined or unspecified behavior lurking in the codebase.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h Khh¶hžhubhÊ)”}”(hXÎBy the time you finish the patchset, you should understand better which assertions need to be handled and turned into checks with error paths, and which should be logically impossible. Leave the BUG_ON()s in for the ones which are logically impossible. (Or, make them debug mode assertions if they're expensive - but don't turn everything into a debug mode assertion, so that we're not stuck debugging undefined behaviour should it turn out that you were wrong).”h]”hXÔBy the time you finish the patchset, you should understand better which assertions need to be handled and turned into checks with error paths, and which should be logically impossible. Leave the BUG_ON()s in for the ones which are logically impossible. (Or, make them debug mode assertions if they’re expensive - but don’t turn everything into a debug mode assertion, so that we’re not stuck debugging undefined behaviour should it turn out that you were wrong).”…””}”(hj-hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h Khh¶hžhubhÊ)”}”(hŒVAssertions are documentation that can't go out of date. Good assertions are wonderful.”h]”hŒXAssertions are documentation that can’t go out of date. Good assertions are wonderful.”…””}”(hj;hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h K%hh¶hžhubhÊ)”}”(hŒeGood assertions drastically and dramatically reduce the amount of testing required to shake out bugs.”h]”hŒeGood assertions drastically and dramatically reduce the amount of testing required to shake out bugs.”…””}”(hjIhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h K(hh¶hžhubhÊ)”}”(hŒ‡Good assertions are based on state, not logic. To write good assertions, you have to think about what the invariants on your state are.”h]”hŒ‡Good assertions are based on state, not logic. To write good assertions, you have to think about what the invariants on your state are.”…””}”(hjWhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h K+hh¶hžhubhÊ)”}”(hX7Good invariants and assertions will hold everywhere in your codebase. This means that you can run them in only a few places in the checked in version, but should you need to debug something that caused the assertion to fail, you can quickly shotgun them everywhere to find the codepath that broke the invariant.”h]”hX7Good invariants and assertions will hold everywhere in your codebase. This means that you can run them in only a few places in the checked in version, but should you need to debug something that caused the assertion to fail, you can quickly shotgun them everywhere to find the codepath that broke the invariant.”…””}”(hjehžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h K.hh¶hžhubhÊ)”}”(hX.A good assertion checks something that the compiler could check for us, and elide - if we were working in a language with embedded correctness proofs that the compiler could check. This is something that exists today, but it'll likely still be a few decades before it comes to systems programming languages. But we can still incorporate that kind of thinking into our code and document the invariants with runtime checks - much like the way people working in dynamically typed languages may add type annotations, gradually making their code statically typed.”h]”hX0A good assertion checks something that the compiler could check for us, and elide - if we were working in a language with embedded correctness proofs that the compiler could check. This is something that exists today, but it’ll likely still be a few decades before it comes to systems programming languages. But we can still incorporate that kind of thinking into our code and document the invariants with runtime checks - much like the way people working in dynamically typed languages may add type annotations, gradually making their code statically typed.”…””}”(hjshžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h K3hh¶hžhubhÊ)”}”(hŒ”Looking for ways to make your assertions simpler - and higher level - will often nudge you towards making the entire system simpler and more robust.”h]”hŒ”Looking for ways to make your assertions simpler - and higher level - will often nudge you towards making the entire system simpler and more robust.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhŸh³h K