by bitfield on 4/18/23, 9:22 AM with 167 comments
by clnq on 4/18/23, 9:49 AM
S - Spaghetti: write tapestry of code like a chef.
I - Interlinked: if the project has modules, they should all depend on each other (we are strongest when we can depend on one another).
M - Micromanaged: if the product owner doesn’t expect reports in the daily stand-up, do they even care?
P - Perplex: diversity for the codebase.
L - Lazy: Bill Gates once said “I choose a lazy person to do a hard job, because a lazy person will find an easy way to do it”, for example, without testing, collaborating with team members, or ensuring the feature works with anything else in the codebase.
E - Opinionated: because I believe E should stand for opinionated and everyone else will have to work around this with adapters. But E should mean Opinionated because Uncle Bab said so.
by dkdbejwi383 on 4/18/23, 10:27 AM
by edumucelli on 4/18/23, 9:42 AM
by mekoka on 4/18/23, 4:39 PM
Correctness: the primary objective. Code that does what it's supposed to, bug free.
Readable: strive to write code that will be understandable by others (and your future self). Review what you wrote for clarity and be your own critic.
Idiomatic: Write code the way people in your community expect to read. Don't surprise them with your own quirky and clever conventions, when there are well established and perfectly acceptable ones already.
Simple: Your code should do what it says it does directly, with no funky side-effects. Repetition is not always a sin, don't DRY things up just for the sake of it. Don't do too many things. Be parsimonious.
Performant: be aware of RAM (a bit of a letdown, was expecting "code to data structures" advice).
---
Author concludes with a few interesting take-away points. Some highlights (paraphrasing):
- don't trust foolproof software engineering methodologies sold using a neat backronym.
- words like "clean", "simple", and "readable" are as vague as "freedom", "justice", or "equality".
- neat slogan like "don't repeat yourself" or "clean code" are moot.
- correctness above all else.
- tests only prove that the code can pass the test.
- No info is better than bad info. No tests is better than bad tests.
- all software has two types of bugs: those you've found and those you have yet to find.
- we all want readable code, but we have different definitions of "readability".
...
by gregfjohnson on 4/18/23, 3:20 PM
Similarly for writing software: First, get it right. Then, as with writing in general, rewrite ruthlessly until it is clean, beautiful, and simple.
Simplicity might be "defined" the way Justice Stewart (non-)defined pornography: "I can't give you a definition of it, but I know it when I see it."
There is the well-known programming experience of struggling with a crufty, complex piece of code. Then a new idea pops up, the code gets rewritten in a flash, and two thirds of it disappear. The result is obvious and inevitable.
Pair programming can really help here: As the author, you develop internal state that leads to a form of myopia about your code. A pairing partner can look at the code with fresh eyes and say, "WTF is going on here?" Can we rename that method or class or file to give the reader a clue?
It also reminds me of Paul Erdos' idea of "The Book", where God keeps all of the simplest and most beautiful proofs. As Erdos said, "You don't need to believe in God, but you should definitely believe in The Book!" His (and Selberg's) elementary proof of the prime number theorem, developed 60 years after the original proof, would be a great example of this.
by themodelplumber on 4/18/23, 9:46 AM
DRY, for example, is instantly transferable to a bunch of other life practices and disciplines; people from dry cleaning to graphic design will hear about it and go "oh my god, I'm not really DRY but I totally could be" so it was really neat to discover.
In the case of CRISP, the "Correct" criterion somehow seems far less tractable to me than the other terms, and even less tractable than "Clean" for some reason.
To me it reads like a hint at subjective, self-contained logic. That's great, insofar it's instrumental to how code either works or doesn't.
But "Correct" is also kind of getting negative connotations these days, for a lot of reasons.
(Imagine also, receiving "your code could be more DRY" feedback, vs. "your code could be more CRISP," wherein you look up the latter and think, "oh right, my code could be more _correct_!")
And then the author even takes the argument in the ad-infinitum direction by referring to e.g. what _else_ isn't correct here? My tests? My purpose? My gut biome? (Ok not the last one). But there's a reason why Correctness is a thing in science, and a big part of that is scope constraint.
Maybe "Cogent" is more fitting in such a case? It has less of an absolutist ring to it. It expresses a bar to measure up to, with more of a qualitative, less-checkboxy feel.
I would also guess that a word like "Contractual" or "Compliant" would provide more leverage toward the same outcome. But those are already used around code in other ways, I guess...
Anyway, it's interesting to think about, because these little acronyms can really help when applied, if they reveal some traction that's been missing.
(This also made me wonder...why is one of the world's most popular crispy rice chocolate bars called a Crunch bar, and not a CRISP bar. Hmm)
by djvu97 on 4/18/23, 10:28 AM
Even porn sites need to write great code to handle huge traffic. I am offended by this
by BulgarianIdiot on 4/18/23, 9:34 AM
Correct
Readable
Idiomatic
Simple
Performant
Notice that all this is just well-wishing and suitably vague, so that you feel the need to buy a book & hire a consultant to explain it to you. The trick is there's nothing to explain.
by BulgarianIdiot on 4/18/23, 9:38 AM
Beneath Utterly Ludicrous Labels, Salespeople Hawk Ineffective Tricks.
Bogus Utterances (with) Little Legitimacy, Sold (to) Helpless IT Teams.
Business Units Love Lingo, Selling Hyped IT Truisms.
Credit: ChatGPT.
by jiggywiggy on 4/18/23, 10:16 AM
by ModestBee on 4/24/23, 6:40 AM
C - Confusing: Write code that is hard to understand, ensuring that only you can maintain it, thus securing your position in the company.
H - Hodgepodge: Mix programming paradigms, libraries, and styles to create a unique blend of code that reflects your artistic side.
A - Arbitrary: Make decisions about architecture, data structures, and algorithms without any specific reasoning, allowing for a more spontaneous and whimsical development process.
O - Obfuscation: Deliberately make your code difficult to read and comprehend by using cryptic variable names, nested loops, and a lack of comments.
T - Tinkering: Constantly make small, undocumented changes to the codebase to keep your teammates on their toes and to give yourself an excuse to fix "bugs" that you secretly introduced.
I - Inconsistent: Use different naming conventions, indentation styles, and language features throughout your code to keep things interesting and unpredictable.
C - Cluttered: Avoid modularization and organization, and instead cram as much functionality into a single file as possible. This will create an exciting challenge for anyone attempting to decipher your masterpiece.
Embrace the CHAOTIC way and create a memorable, one-of-a-kind codebase that will leave a lasting impression on your colleagues and ensure your job security!
by adamors on 4/18/23, 9:29 AM
by suralind on 4/18/23, 11:25 AM
by dgellow on 4/18/23, 11:08 AM
I’m not even joking, that’s basically my process since ChatGPT-4 has been released :) That’s a dream for boilerplate heavy languages like Go, C#, and C++.
by eternityforest on 4/18/23, 11:10 AM
I'd much rather have DRY than simplicity, because repetition creates the possibility for later divergence and incompatibility and stuff left behind. What if there's a bug in the thing you repeated and only 9 out of 10 get fixed because of an oversight?
by nuancebydefault on 4/18/23, 11:09 AM
- code, when executed, should do what is expected.
- code should be maintainable.
All the rest are just some ways to get there, but not must-haves.
One great way to get there is:
- discuss architecture, nomenclature and design choices. Document those.
- have your code and docs reviewed and discuss/rework accordingly.
The above in a rinse and repeat manner.
by KyeRussell on 4/18/23, 9:34 AM
by urig on 4/18/23, 10:02 AM
* - Granted the book was written by an asshole.
by akasakahakada on 4/18/23, 11:11 AM
what's wrong with this false assumption?
by edu on 4/18/23, 9:48 AM
by waltertamboer on 4/18/23, 10:19 AM
I don't agree with this statement at all. From my experience this is perfectly possible. Maybe I'm misunderstanding the statement... why would it be hard to write methods that only do one thing?
by omeid2 on 4/18/23, 10:31 AM
by nextlevelwizard on 4/18/23, 10:13 AM
by highfrequency on 4/18/23, 1:31 PM
by moralestapia on 4/18/23, 10:07 AM
* starts writing CRISP code *
by Warwolt on 4/18/23, 5:12 PM
by Manjuuu on 4/18/23, 10:35 AM
by lakomen on 4/18/23, 12:28 PM
by Derbasti on 4/18/23, 2:14 PM
by anti_con_men on 4/18/23, 10:57 AM
by zokier on 4/18/23, 5:23 PM
by EVa5I7bHFq9mnYK on 4/19/23, 8:14 AM
by Alex3917 on 4/18/23, 10:44 AM
In most cases, readability is more important than correctness. If you have readable code, you can always make it work correctly later. But if you have code that merely works correctly, it isn't necessarily easy to back and make it more readable.
by chillbill on 4/18/23, 12:07 PM
Plain, exciting, refreshable, fast, entertaining, code (with) tabs.
by booleandilemma on 4/18/23, 2:37 PM
by mawadev on 4/18/23, 2:33 PM
by dathinab on 4/18/23, 11:43 AM
Is never simple as people can just not at all agree on what simple means. Even experienced programmers. This isn't even a question of training. It's deeply embedded into human nature due to peoples thought process differing and in turn what they find simple.
P - Performant
While a certain baseline performance does matter often (not always) anything beyond that yields increasingly diminishing returns. Discarding even large chunks of performance in rarely run non time critical code in favor of otherwise "better" code can sometimes be a very good decision.
Somewhat derived from "simplicity" and readability but not any less important is making code easy to change (by literally changing it, not by making it configurable or parametrized).
The problem with DRY and similar isn't that it's bad practice but that people take it too far and try to have rules they can just always blindly strictly always apply ignoring imperfections of e.g. other tools they use.
For example DRY is about not repeating "business logic" (1) but people try to forcefully apply it to language structure and things which just happen to be similar. They then often do so by using abstractions which make future changes to the code harder by put constraints on about what is possible. Another common failure is to not diverge (i.e. copy) you code when business logic diverges through a change of requirements but instead try to handle it by additional parameterizeation/genericity often using means which make the code again harder to change.
I.e. TL;DR: DRY isn't bad but like most things it's not a rule you can blindly apply but a tool/skill you need to learn to properly use, including when to not use it.
(1): What counts as "business logic" differs depending on the abstraction level/context you are looking at the code; That doesn't make it easier to use.
by BaculumMeumEst on 4/18/23, 10:44 AM
by ElfinTrousers on 4/18/23, 1:27 PM
by atoav on 4/18/23, 10:34 AM
by throwaway5371 on 4/18/23, 10:14 AM
the sooner the better
by awestroke on 4/18/23, 9:33 AM
I don't foresee this one catching on