Live data from Hacker News

Don't write clean code, write CRISP code

bitfieldconsulting.com

41–50 of 170 posts

Re: Don't write clean code, write CRISP code

#41

"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 th…

Because it's an artificial constraint that makes code worse. You end up with a whole bunch of functions that have only a single call-site and half a dozen parameters that don't make much sense. If you can only understand what a function does by looking at the call site then the function is no longer a self-contained piece of functionality and it shouldn't exist.

When you write very simple code you can have short functions that do one thing. When you work on more complex projects some functions will just be 300 lines long and breaking them up will just make the code harder to understand and harder to work with.

Take sqlite for instance: https://github.com/smparkes/sqlite/blob/master/src/vdbeaux.c

You'll find plenty of cases where functions do multiple things in sequence and those functions are long-ish because of it, and some "clean code" type programmers would feel compelled to refactor the code and make it way worse.

Re: Don't write clean code, write CRISP code

#42
post #13

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.

> Before that you had to write a for loop every time you wanted something from an array. How often do you do that? I mean, it comes up - but if you're linearly scanning every time you want to select something from a list, that sounds like a surefire way to write slow code to me. Is there a reason you aren't using a map?

Linearly scanning a small array is very likely to be faster than looking up a key in a map. Especially if we factor in memory cost and not just speed.

Re: Don't write clean code, write CRISP code

#44

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.

This is kind of how I felt about the S in single responsibility of SOLID too. I wonder if there are any principles out there which are actually objective/measurable.

There are plenty of code metrics. I'm not aware of any that I would recommend, though (other than basic ones like keep function LoC <= 50, keep indentation level <= 3). But if you're interested, you can research this topic. I saw tools for Java which measure those code metrics.

Re: Don't write clean code, write CRISP code

#45

"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 th…

why would it be hard to write methods that only do one thing?

Two big problems with this approach. First of all reasonable people can disagree on what "one thing" actually means. Let's say you want to take a csv file of numbers and return a numeric array-of-arrays. How many 'things' is that, 1 or 4 (read, parse, validate, convert)?

Secondly it is many time both computationally more efficient and 'aesthetic' to do everything in one in-line sweep rather than:

  x=f(x)
  x=g(x)
  x=h(x)
  ...
While both approaches can be taken to extremes, I generally agree with what John Carmack wrote on the topic many years ago http://number-none.com/blow/blog/programming/2014/09/26/carm...

Re: Don't write clean code, write CRISP code

#48

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.

For best results, set your DRY dial to 8 or 9 out of 10. Settings higher than 9 result in premature or excessive abstraction.

But if you hate DRY so much, imagine a word where people set it to 1 or 2. I wouldn’t want to work in that code base.

Re: Don't write clean code, write CRISP code

#49
post #39

> 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

If that's meant seriously rather than as a joke: I think you're misunderstanding. They aren't saying "porn sites don't care about code quality", they're making a pun on the word "dirty".

Re: Don't write clean code, write CRISP code

#50

Earlier quoted context omitted.

Could you elaborate on the last point?

Uncle Bob has been widely criticized for his political stances, basically being a MAGA republican. This also spilled into some critiques of Clean Code which are sometimes colored by this.

Eh, I don’t even know anything about his politics but I read his Clean Architecture and I saw immediately what a hot pile of garbage it is. The book is full of platitudes, the author is so conceited that he cites his other works to justify his statements, and he’s far more concerned about being immortalized or revered in the industry for his coinages of principles, than by coming up with a mechanistic model of what makes a good computer program and ways of measuring that quality.
Post reply on HN