6 ms·
As someone who has gone back and read my old code as well as a lot of others old code, there is no such thing as good code. IMHO, the problem is one of cultural
by imoverclocked 3y ago
As someone who has gone back and read my old code as well as a lot of others old code, there is no such thing as good code. IMHO, the problem is one of cultural context which is often not shared between generations of coders. Languages and best practices can change so violently that best-practices one decade are often anti-patterns in the next.
As a codebase outlives its best-practices, do you stick with them and extend with those same anti-patterns or do you implement new things with a different mindset than the rest of the code?
-- If you break with tradition then you are making it harder to understand the codebase as a whole.
eg: why do we have a mix of procedural/OO/functional/... methodologies with spaghetti code at the core?
-- If you refactor everything then you are definitely breaking something.
eg: you have a 10M+ line java codebase with transformations bringing you into the 2020s from coders who originally knew C and Java 1.4.
-- If you keep with tradition then are you writing the best code possible?
eg: would you willingly use goto of some variant in new code if you jumped into a Cobol 74 codebase?
I think what the article really wants to talk about is "clear" code or "understandable" code and not "good" code.
- woooooo 3y agoStyle changes over time, but factoring is evergreen. Something could be written using Java 1.4 idioms with good organization and factoring, or using the latest functional hoohas with everything all mashed together. Or the inverse, of course. If the structure of the code matches the structure of the problem, the implementation style is a much smaller deal.
- 38 3y ago> there is no such thing as good code definitely not true. this is good code: https://github.com/torvalds/linux/blob/master/fs/file.c https://github.com/torvalds/linux/blob/master/fs/file.c this is good code: https://github.com/golang/go/blob/master/src/strconv/atoc.go https://github.com/golang/go/blob/master/src/strconv/atoc.go its formatted, commented, direct. the fact that you struggle with writing time tested code does not mean that everyone does.
- grepfru_it 3y agoI wrote some code that was years ahead of a distinguished engineer's existing code. He immediately saw where I was going and adjusted his code accordingly (by dropping my branch and authoring a new branch. I assume because he didn't understand git, but I believe he was protecting his future performance review). Some people won't admit someone else can write better than them.
- jiggawatts 3y agoBy linking to those examples you confirmed the point you were trying to refute. From my personal perspective this is mediocre code at best. It’s written in an unsafe language. Littered with macros, which in C are not hygienic and are land mines in waiting. Constants defined with lowercase and not actually marked as const. Double underscores everywhere, which are the bad alternative to namespaces seen in weak languages like C. WTF does “BITBIT_NR(nr)” do!? Does it “bit” the “bits”? What is NR? Is it a “number”? Then why not use “n” and drop it from the macro name? Abbreviations everywhere: ofdr, nfdt, fds, fs, etc… Then there is a long-winded explanation of how they pack bits into an array of longs. Okay, why not make this a reusable module of code? Because C is a weak language, or because the Linux kernel is spaghetti with a dozen implementations of bit maps? \* * Note that this can drive nr *below* what we had passed if sysctl_nr_open * had been set lower between the check in expand_files() and here. Deal * with that in caller, it's cheaper that way. Huuuurk. Sorry… did I just see a data race just casually commented as “okay because it is faster if it’s horrifically unsafe? Yes? No? Maybe? Do you even know?
- cookiengineer 3y agoI think I just fell in love with you. Finally a sane person <3 Honestly, I never understood why so many developers abbreviate function names or variables. Is it so much pain to type abc<tab> for auto completion? Why not simply name fd file_descriptor? Short names are a mental barrier and a level of abstraction that can easily be avoided.
- sudosysgen 3y ago
- munificent 3y agoI think about this all the time when it comes to evolving systems. I work on a programming language, and these tensions are core to my job. In the context of a language, I think it can be: * Modern, where the language's features and idioms reflect the best way we know to write good, clean code today. * Compatible, where code written in the language years ago continues to run the same as when first written. * Simple, where the language has relatively few concepts that compose in clean ways and where there are few ways to accomplish the same goal. But you only get to pick two.
- stefanos82 3y agoYou mean your work on Dart at Google or are you working on a new programming language right now? If it's the latter, I need more info please!
- munificent 3y agoDart, but this is true of my various hobby languages too (though those have the delicious advantage of almost no users to worry about breaking).
- za_creature 3y ago> there is no such thing as good code. nor is there such a thing as a good love letter
- bryanrasmussen 3y agowell there probably are a few, but most love letters you wouldn't want to read if it wasn't for you - and even then maybe not.
- darepublic 3y agomaybe there's no good code but there's degrees of terribleness. It can make all the difference in the ability to safely add to it in a timely manner or not.
- fnordpiglet 3y agoI disagree. Good code is code that is indistinguishable in style and convention from all adjacent code. I always advise juniors two things: 1) your code will be written once but read a thousand times 2) if you want to make your mark with style and convention start an OSS project of your own, otherwise make your mark through the simplicity and elegance of your logic, not the way your code contrasts from the code base.
- avg_dev 3y agoi don't agree with this take at all. good code solves the problem at hand. good code is as simple as possible. good code is testable and tested. good code is minimal. good code is performant. good code is maintainable. good code is understandable. yes it matters somewhat that you have some consistency of the way you code. that's a secondary thing
- PartiallyTyped 3y agoGood code is sound.
- deelly 3y agoagree. good code is a code easy to read and easy to modify. thats all.
- raincole 3y ago> there is no such thing as good code But do you think there is bad code? If so, I'll give you the official definition of good code: code that isn't bad code.
- 000ooo000 3y agoSuits me. Us programmers being such a negative bunch, surely we can easily build a checklist of bad code attributes and then just call any code with few ticks on the list "good code". Does it need to be much more complicated than that?
- otikik 3y agoThere's another, perhaps a bit nihilistic possibility: all code is bad, and the only good code is no code at all.
- mattgreenrocks 3y agoIf there is no such thing as good code, why does it spark so much discussion? Why care at all?
- imoverclocked 3y agoWe can all be passionate about what we care about and strive to be better. For me, this is what looking back at my old code means. When I see that I could have done something better, it means that I have grown. It also means that whatever I produce now could probably be improved upon. The biggest trap (for me) in this endeavor is to not be a perfectionist; One can spend a lifetime improving/optimizing/refactoring/etc. By accepting that there is no single encompassing definition of "good code," I am freed to choose the attributes that I think matter most for a particular piece of code.
- WalterBright 3y agoInterestingly, this is exactly what my upcoming talk at DConf is about: https://dconf.org/2023/index.html#walterb https://dconf.org/2023/index.html#walterb I've got the talk about half-written. I'm concentrating on things that are timeless about writing understandable code. Although the examples will be in D, and will use D features, the concepts are transferable to many languages. It will be livestreamed for those unable to attend.
- patrulek 3y agoBut thats exactly good code. Code that is clear (well-formatted/readable), works and can be easily proven that is really working.
- deleted 3y ago[deleted]