Reversed tableflip3/15/2023 It’s simpler to delete the code inside a function than it is to delete a function. The programmers using your function will not rely on what you document, but what they observe. The code that calls your function will rely on both the intentional and the unintentional behaviours of the implementation behind it. Once you make something a shared API, you make it harder to change. It’s good to copy-paste code a couple of times, rather than making a library function, just to get a handle on how it will be used. On the plus side, you’re probably re-using a lot of code already by just using the file-system, why worry that much? A little redundancy is healthy. A million line monolith is going to be more annoying than a ten thousand line one and significantly more time, money, and effort to replace.Īlthough the more code you have the harder it is to get rid of, saving one line of code saves absolutely nothing on its own.Įven so, the easiest code to delete is the code you avoided writing in the first place.īuilding reusable code is something that’s easier to do in hindsight with a couple of examples of use in the code base, than foresight of ones you might want later. The number of lines of code doesn’t tell us much on its own, but the magnitude does 50, 500 5,000, 10,000, 25,000, etc. Don’t try to do all of these things at the same time, and maybe don’t write so much code in the first place. Don’t hard code every choice, and maybe allow changing a few at runtime. Split your code: isolate the hard-to-write and the likely-to-change parts from the rest of the code, and each other. Layer your code too: build simple-to-use APIs out of simpler-to-implement but clumsy-to-use parts. To write code that’s easy to delete: repeat yourself to avoid creating dependencies, but don’t repeat yourself to manage them. I don’t need to tell you that deleting code is more fun than writing it. Instead of building re-usable software, we should try to build disposable software. If we see ‘lines of code’ as ‘lines spent’, then when we delete lines of code, we are lowering the cost of maintenance. My point today is that, if we wish to count lines of code, we should not regard them as “lines produced” but as “lines spent” EWD 1036 Managing how the code fits together, or which parts depend on others, is a significant problem in large scale systems, and it gets harder as your project grows older. Similarly, the more you rely on an third-party api, the more you suffer when it changes. The more consumers of an API you have, the more code you must rewrite to introduce changes. ![]() The problem with code re-use is that it gets in the way of changing your mind later on. To avoid paying for a lot of code, we build reusable software. “Every line of code is written without reason, maintained out of weakness, and deleted by chance” Jean-Paul Sartre’s Programming in ANSI C.Įvery line of code written comes at a price: maintenance. Write code that is easy to delete, not easy to extend.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |