Hacker News new | past | comments | ask | show | jobs | submit login

> Is it weird that not only have I never heard of the "rule" this post argues against

This "rule" is known mostly because it is featured in the "Clean Code" book by Robert C. Martin (Uncle Bob). You should have heard of it ;)




Heard of it, but never read it.

Looking at the Amazon listing and a third-party summary[0] it seems to be the sort of wool-brained code astrology that was popular twenty years ago when people were trying to push "extreme programming" and TDD.

[0] https://gist.github.com/wojteklu/73c6914cc446146b8b533c0988c...


Wait what's wrong with XP and TDD? Where I'm from those are absolutely considered best practice for most situations


Perhaps the author is better off not having heard of it then, and by implication, not having read "Clean Code" in the first place. The book is full of anti-patterns.


Are there any "rules" in Clean Code that don't need to be disregarded and burned? https://qntm.org/clean


There's plenty of sensible advice in there it's just that he argues for the sensible stuff and the idiotic stuff with equal levels of conviction and if you are junior you aren't going to be able to distinguish them.

It would be easier if it were all terrible advice.


Fortunately you readily find the good advice in lots of other places, so you can simply ignore that book.


Where in that book is the rule stated? I ask because I have heard the author explicitly state that multiple assertions are fine (using essentially the same explanation as TrianguloY did in this comment: https://news.ycombinator.com/item?id=33480120).


Chapter 9 talks about unit tests and there is a paragraph called 'Single Assert per Test', where he says it is a good concept but that he is not afraid to put more asserts in his tests.

That paragraph is followed by 'Single Concept per Test' where he starts with: 'Perhaps a better rule is that we want to test a single concept per test.'

So, technically he doesn't say it.


That maps better with the lectures I've seen of him on YouTube, and I concur with it.

When I first wrote tests years ago, I would try to test everything in one test function. I think juniors have a tendency to do that in functions overall - it's par to see 30-100+ line functions that might be doing just a little too much on their own, and test functions are no different.


It feels as if folks are splitting hairs where a haircut (or at least a half-hearted attempt at grooming) is required. Use good judgment, and do not blindly follow "rules" without understanding their effects.


The book is so full of bad advice I'm not surprised this "rule" comes from there as well.


As MikeDelta reports¹, the book doesn’t actually say that.

I’ve come to learn to completely disregard any non-specific criticism of that book (and its author). There is apparently a large group of people who hate everything he does and also, seemingly, him personally. Everywhere he (or any of his books) is mentioned, the haters come out, with their vague “it’s all bad” and the old standard “I don’t know where to begin”. Serious criticism can be found (if you look for it), and the author himself welcomes it, but the enormous hate parade is scary to see.

1. https://news.ycombinator.com/item?id=33480517




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: