from Hacker News

Don't write clean code, write CRISP code

by bitfield on 4/18/23, 9:22 AM with 167 comments

  • by clnq on 4/18/23, 9:49 AM

    Since we’re adding new backronyms every day, I propose SIMPLE.

    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

    DRY is probably my least favourite programming meme. There are far too many overzealous juniors who learned it and have a bee in their bonnet about creating absurd abstractions around any two lines of code (or config) that have vague or imagined similarities, locking in all sorts of annoying indirection.
  • by edumucelli on 4/18/23, 9:42 AM

    It is laughable talk about "Don't Repeat Yourself principle" on a strongly biased towards Golang article. A language that took 13 years to add a simple method (Index) that helped the programmer to find an element in an array (slice). Before that you had to write a for loop every time you wanted something from an array. Talk about "DRY" ... That is everything but "simple" as described in the article.
  • by mekoka on 4/18/23, 4:39 PM

    A summary.

    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

    This essay is great. Regarding simplicity, a couple of amusing observations: "I apologize for such a long letter - I didn't have time to write a short one." - Mark Twain (a variation of the French original by Blaise Pascal)

    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

    I like to read these kinds of prospective acronyms, because sometimes they provide new perspectives or leverage points that other, existing acronyms don't. And they are easier to remember than, say, an essay.

    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

    > Who wants to write dirty code, unless maybe it's for a porn site?

    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

    What CRISP is supposed to mean:

    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

    Well, since we're in a fancy acronym thread, here are some for your attention:

    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

    Very often it's the design pattern people that make code unreadable.
  • by ModestBee on 4/24/23, 6:40 AM

    Introducing the new coding acronym, CHAOTIC!

    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

    Uh, another acronym to be tortured by in interviews.
  • by suralind on 4/18/23, 11:25 AM

    What an excellent post! What I would add though, is that you can gain some simplicity by removing abstractions (e.g. interfaces) and sometimes it's just worth it. For example, a good practice may be to abstract away all implementations and use interfaces instead, but for things like logger (which may be a bit complex to abstract depending on it's API), you may be just fine logging to some buffer instead of maintaining mocks (and in Go you'll probably make expectations what they should be called with). Focus on things that matter - if you want to check logs in your tests too, make it as effortless as it can be (e.g. use snapshots for those).
  • by dgellow on 4/18/23, 11:08 AM

    Don’t write clean code, write the best way to express your idea without caring too much about how dirty that looks like, and let the AI chat bot rewrite it in the cleanest version that follows all the best practices!

    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

    Completely agree, except that simplicity is kind of redundant. If the code is correct and readable, I don't see why I need to simplify it any further, to me it's probably simple enough if the complexity isn't causing problems. It seems like engineers, and humans in general, really love simplicity for its own sake, in some deep way I that makes me wonder if I'm secretly a bad person, since it seems to so often be praised as connected to so many other virtues and most every philosopher ever seems to love it.

    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

    In fact there only a few things that matter:

    - 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

    So, which of these criteria were contrived, and which were left out, all to make this fit into “CRISP”?
  • by urig on 4/18/23, 10:02 AM

    Don't follow the concrete practices in the best-selling book* vetted by industry leaders for years, instead follow this set of 5 high level goals that I've generally described and grouped together into a catchy acronym. Yay me!

    * - Granted the book was written by an asshole.

  • by akasakahakada on 4/18/23, 11:11 AM

    > performance genuinely matters. Not as many as you might think, though: computers are pretty fast these days, and since most of what they do is in the service of us humans

    what's wrong with this false assumption?

  • by edu on 4/18/23, 9:48 AM

    Code should be CODE: "Clean, Optimized, Documented, Efficient".
  • by waltertamboer on 4/18/23, 10:19 AM

    "The problem, of course, is that few of us can agree on what "clean code" means, and how to get there. A rule like "methods should only do one thing" looks great on a T-shirt, but it's not so easy to apply in practice. What counts as "one thing"?

    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

    I can't stand the insistence on "idiomatic". Taken to extreme it is essentially gate-keeping and dogma: "We have always done it so."
  • by nextlevelwizard on 4/18/23, 10:13 AM

    If you could just write good code that would be fine.
  • by highfrequency on 4/18/23, 1:31 PM

    Make it work, make it simple to understand for people with no context, make it robust to edge cases and bad inputs.
  • by moralestapia on 4/18/23, 10:07 AM

    Ok.

    * starts writing CRISP code *

  • by Warwolt on 4/18/23, 5:12 PM

    Pretty decent article. People on this site fucking love getting riled up about stuff.
  • by Manjuuu on 4/18/23, 10:35 AM

    The "simple" part is so hard to understand even for people with high seniority. Once asking for simplicity I got back a mass of low effort code that seemed written out of spite, even if that was not the original intent.
  • by lakomen on 4/18/23, 12:28 PM

    I like John. What I don't like is dogma. There's a lot in HR. Also hype.
  • by Derbasti on 4/18/23, 2:14 PM

    This article was way too long for what it said. Not very crisp, one might say.
  • by anti_con_men on 4/18/23, 10:57 AM

    Don't write XYZ code, write code that works and that you can maintain.
  • by zokier on 4/18/23, 5:23 PM

    Considering most software already fails on the first aspect, do the other four points really matter at all?
  • by EVa5I7bHFq9mnYK on 4/19/23, 8:14 AM

    Any manager would tell you, don't develop clean or CRISP, develop by the deadline.
  • by Alex3917 on 4/18/23, 10:44 AM

    > So, while readability isn't quite as important as correctness, it's more important than anything else.

    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

    Don’t write CRISP, write PERFECT.

    Plain, exciting, refreshable, fast, entertaining, code (with) tabs.

  • by booleandilemma on 4/18/23, 2:37 PM

    Is this another acronym I'm going to have to learn for interviews?
  • by mawadev on 4/18/23, 2:33 PM

    I'm feeling more crunchy today, I will try crisp coding tomorrow
  • by dathinab on 4/18/23, 11:43 AM

    S - Simple

    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

    you are not going to solve the problem that the meaning of "clean code" is vague and subjective by introducing a new set of terminology that is also vague and subjective
  • by ElfinTrousers on 4/18/23, 1:27 PM

    Mind-blowing: I had been writing incorrect, unreadable, idiosyncratic, complicated, and slow code this whole time, thinking that was the thing to do. But now I see my mistake and will cease forthwith. Thanks, Captain Obvious!
  • by atoav on 4/18/23, 10:34 AM

    Don't write crisp code write deep fried code.
  • by throwaway5371 on 4/18/23, 10:14 AM

    i just try to write code that can be deleted later

    the sooner the better

  • by awestroke on 4/18/23, 9:33 AM

    Americans love their acronyms.

    I don't foresee this one catching on