13 ms·
It's probably time to stop recommending Clean Code
- LAC-Tech 5y agoJudging from reddit, I think there's an appetite in the tech community to 'cancel' Bob Martin for his political beliefs. If it also turns out that his technical ideas are wrong, then that will make it much easier. It's like our little mini version of the moscow show trials.
- redisman 5y agoHad a quick look - wow what a low bar for controversy. Can we all just deliver Twitter and stfu
- skinkestek 5y agoI think this is correct. Here is my somewhat simplified but as far as I know not too far from the truth version of what happened based on following from the sidelines of Twitter and HN, please correct me if I'm wrong (feel free to adjust my score as well, I don't care about that, but tell me what I got wrong): (Oh yes, as I mentioned to someone else earlier today I'm so utterly fed up about how we treat certain topics. I actually respect actual climate scientists but I don't to same degree respect people who are out to punish climate heretics.) As far as I can see Bob was everyones uncle, generally popular, not infallible but widely respected until he did the grave sin of not paying enough respect to climate scientists or something to that effect. In fact there is a chance he just asked questions, but that is a sin so grave it got its own derogatory term, JAQ-ing. As everyone should know by know asking questions isn't good scientific behaviors and everyone who ever does it only ever do it to it to derail constructive discussions. After that he became pretty clueless and his books became dumb and useless. All he knew about programming is wrong and it turns out he never helped any project.
- MauranKilom 5y agoIf this is supposed to be related to the article, you've completely the mark. The article presents a very nuanced view on the book, including its historical context, the wealth of good advice, but ultimately also the impractical or antithetical parts. I hadn't heard of Uncle Bob being cancelled before this thread, but I have voiced my reservations about Clean Code to colleagues multiple times before. You're not doing anyone a favor by painting all criticism of his work like that. It's meaningless polarizing nonsense.
- LAC-Tech 5y agoJust speaking for myself - I agree the article is a good technical criticism. It's the timing of posting the article again that's suspect. But maybe I should give the benefit of the doubt.
- skinkestek 5y ago> If this is supposed to be related to the article, you've completely the mark. It was not related to the article but to the comment. Sorry for the confusion.
- coolgeek 5y agoGood article. But discussed with 800+ comments five months ago https://news.ycombinator.com/item?id=27276706 https://news.ycombinator.com/item?id=27276706
- 0des 5y agoDoes your code work? Can your interested peers tell what's going on? If yes, great, your code is fine. Clean code is a meme foisted upon us by bloggers and the equivalent of dev influencers. Edit: Can we have one thread without the political topics overtaking the discussion? It's Friday, come on.
- 0n34n7 5y agoGoes a bit deeper. Can you replace a source of data with another in a few lines (besides the new implementation) and not break a whole chain of dependencies and associates unit tests? (apart from "does someone knows what's going on") - i.e. code at scale.
- mdoms 5y agoCan your code be easily changed, or will a change in one place cause a domino effect all over your code base? Does a simple change in requirements require a change in one (or a few) places or is it a "shotgun surgery"? Is the difficulty of changing your codebase negatively affecting the viability of your business? This type of attitude to what's "fine" is immature and in my opinion represents a clear and present danger to businesses. I have seen several companies brought to their knees because their codebases were so difficult to change. And that's not even touching on issues like security, performance, reliability, etc. Code quality matters.
- danielrhodes 5y agoMy criteria is: how long does code last during product iteration and spec changes. If it’s immediately thrown away every time requirements change, the code probably ain’t that great. If it is relatively easy to evolve, something has gone well. However, if you can’t change the code because it’s such a complex web of interdependencies where you musta modify the requirements, the code is very bad.
- deleted 5y ago[deleted]
- backoncemore 5y agoPleasantly surprised to see that this is a technical discussion instead of a critique against Bob's political views. I went into it fully expecting the latter.
- elzbardico 5y agoUnfortunately I think that the motivation for that is the same.
- frenchyatwork 5y agoRegardless of what you think the motivation is, these things should be debated on their own merits, otherwise you run commit the other ad hominem fallacy where you reject criticism of an idea because of where the idea came from.
- usefulcat 5y ago> Martin asserts that an ideal function is two to four lines of code long This is the kind of assertion that's going to need a very compelling, realistic example in order to avoid being seen as anything other than some sort of purely theoretical fantasy.
- ugjka 5y agoI've seen a lot of Go code where things are chopped or abstracted on purpose just to make it look nice on "paper" but it is actually really hard to follow what the code does
- blaerk 5y agoI thought it was me being new to go that made some code bases hard to figure out
- deleted 5y ago[deleted]
- capableweb 5y agoA tip from someone who programmed professionally in probably 10 different languages by now, this happen in every single language where you can create abstractions, not just in Go. Could be that it's easier/harder in some languages, but crap programmers exists everywhere.
- 0des 5y agoGolang Channels are like this, in my experience. Like little tubular black boxes where data goes in this Wonka-esque tunnel of wonder.
- Swizec 5y agoThe easiest way to write unreadable code is by splitting your functionality across 20 clean small functions.
- 5y ago
- T3RMINATED 5y agoMartin is horrible, why would people read his books in the first place? Charles Petzold is King... Martin is a little kitty.
- zz865 5y agoThe problem I have with Clean Code and other design philosophies is there are so test driven. TDD adherants will tell you that lots of unit tests will make the code clearer, but I'm not convinced. All the hoops people have to jump through with dependency injection, test code overhead I'm not convinced any more that all this clean code is better than the stuff we wrote 20 years ago that was just tested at the final product level.
- skybrian 5y agoWhether and how to use mocks is a different decision than how much to test. There are people who write a lot of tests and also dislike mocks.
- nowherebeen 5y agoI kind of agree on some level. The amount of work required doesn't necessarily justify the benefits. Especially for non-critical features.
- mike_d 5y agoI write concise procedural PHP with 0% test coverage for all my personal projects. They handle easily 2-3x the traffic of $dayjob and don't fall over on a regular basis. We need to go back to writing code like we are on resource constrained systems, which forced you to be explicit in what you did and think about why you were doing it.
- barbazoo 5y agoI've grown to rely much more heavily on integration level testing for that exact reason. One still has to mock certain dependencies such as 3rd party APIs but it's far more reusable to figure out how to do that imo than figuring out how to mock every single class you're interacting with.
- kqr 5y agoNow I'm feeling dumb but... why would you ever need to mock every single class you're interacting with? I'm often test-driving stuff with unit level tests and the only times I have to mock collaborators are when the collaborators are - third party services, - badly designed, or - not built yet. This has nothing to do with unit/integration level testing.
- cloogshicer 5y agoI've had problems with the ideas in Clean Code for a while, but I couldn't really effectively communicate them, until I watched this video by Brian Will. I think it is excellent: https://www.youtube.com/watch?v=QM1iUe6IofM https://www.youtube.com/watch?v=QM1iUe6IofM
- poulsbohemian 5y agoI'd say it's long time past recommending "clean" anything. Every time I hear someone talk about "clean" writing, "clean" design, "clean" code, or anything else I want to vomit because it's meaningless noise. You challenge that same person to define clean and they spew out nonsense. Production of any creative work, whether it's architecture, code, writing, design, etc is hard and messy. Compromises are made. I can't help but think of Christoper Alexander, IE: the timeless way - yes, there is a something there, and it tends to be minimalistic, but is that "clean?" I just want to have conversations without pithy language.
- 46756e 5y agoClean code is specifically a book about how to write code well. This isn't criticizing writing clean code, but specifically what that book recommends programmers do. I wouldn't say the mission of trying to create "clean" code is a bad one. Certainly there is terrible code to read and maintain, which implies there are good ways to write code.
- poulsbohemian 5y agoI completely understand that it's about a specific book. My beef is with the fluffy, imprecise language that gets used when discussing quality standards.
- mnd999 5y ago“Modern” is the same. It means basically fuck all.
- poulsbohemian 5y agoAmen brother / sister! "Premium" is another that chaps my hide.
- throwaway19937 5y agoModern normally means either that it's an unattractive building/artwork/sculpture or that it's implemented in JavaScript.
- mkl95 5y agoWith enough time and effort, anyone can write code that adheres to some coding guideline. Meanwhile a disproportionate amount of developers struggle to provide practical, concise documentation of their code. I don't want to dive into Mr Clean's legacy code to find out how to call the stuff needed to develop some feature because he's too smart to write it down somewhere. I'd rather have a more informal codebase where the developers have taken the time to explain what each relevant thing does and the quirks of each non trivial function.
- chrisseaton 5y agoThe problem with almost all of Martin's advice, and the advice of all those other full-time conference speakers who apparently never actually write any code, is that it's entirely unsupported. It's random opinions thrown out there. Where is the data or evidence for his ideas? Nowhere. Even a few that call themselves 'scientists' still don't offer any evidence. I don't know why we tolerate it. Why doesn't someone shout out 'where's your data' at their talks?
- skybrian 5y agoBecause it's not practical. There are few people in a position to do research on entire software teams. Also, even when it's possible to research something, external validity (whether it applies in another situation) is often a matter of opinion anyway. We still need ways to share what we've learned from experience. But I think case studies, telling stories about what we learned in particular situations, are about the best we can do.
- deleted 5y ago[deleted]
- chrisseaton 5y agoCan Martin point to _any_ major successful project that he's influenced with his ideas? If not, then that's clearly a astronomically enormous red flag. If his ideas are that good he should be shipping successful stuff left, right, and centre. I don't think he is. I'd listen to someone who's shipped great things. I don't think he's shipped anything substantial at all, let alone anything great.
- skybrian 5y agoI don't what he's been doing either. I guess if anyone is curious, they could check it out?
- deleted 5y ago[deleted]
- 5y ago
- lido 5y agoYeah, what we really need is elements of programming style written in C, Python, or Go.
- marginalia_nu 5y agoIn the context it was written, it was pretty good advice. Maybe a bit too far on some points, but it was a solid step in a good direction. This caused the book to be praised. But we tend to elevate praised books well beyond what's reasonable, dogmatically follow their advice even when they cause problems, and recommend them even though they're responses to a discussion that nobody has been having for 15 years. Same with Gang of Four and a bunch of other books.
- lcuff 5y agoSandy Metz, a Ruby lecturer, also advocates 5 line functions. I'm keen to have functions limited to 24 lines, because as someone with significant vision challenges who uses large fonts, that's as many lines as I can get on a screen, and I want to see the whole function at once. But I also think it's worth asking "what language are we in"? When I'm writing in C, I'm going to be maxing out that 24 lines, because it's sufficiently low level that seems appropriate. With powerful languages like Python and Ruby, you can accomplish so much with 3 lines of code, maxing at 5 doesn't seem terrible. With Java (yuck, not a fan), one of the problems is there's so much boilerplate for every function that it just seems like the screen is filled with non-informative blah-blah-blah.
- blippage 5y ago"provided that we aren't too dogmatic about how we define 'one thing'" And herein lies the problem. If I define a function that calls two other functions, does the caller do one thing, or is it two? The main() function ultimately does everything. Does that mean that main() is the worst function in an application? I studied programming in the 80's, and I seem to recall that evidence suggested that large functions were not necessarily more unreadable nor unmaintainable than small functions. So in the end, are we are forced back into a circular argument: good programs are written by good programmers, and bad programs are written by bad programmers. How do we know that they're good programmers? Because they write good code! Parenthetically, I've always been suspicious of his "Uncle" moniker. "Functions should have no side effects." So, Haskell it is, then. No printf for you, monads is where it's at. "output arguments are to be avoided in favour of return values." So what about functions that affect multiple values? Are we supposed to use structs everywhere? What about error conditions? Are we supposed to use hybrid variables, which are often regarded as a source of problems? No silver bullet.
- mysterydip 5y agoI used to only make a function if a block of code was used in more than one place. But now if performance isn't an issue (for example a block of code that isn't in a tight loop), I'll take a chunk that together does one thing and make it a self-descriptive function for readability purposes. Instead of: function foo() { // this does abc big block of code // this does def big block of code ... etc } and having a function I have to scroll pages through, I now do this: function foo() { DoABC() DoDEF() }
- pmcollins 5y agoif i could distill clean code into one word it would be “small”. small functions, classes, files, changes, and iterations. i don’t see anything wrong with this but understand there are differing points of view. what i do think is important is that developers get placed on a team that is aligned with their taste. how you feel about uncle bob can be a revealing interview question.
- zmmmmm 5y agoMost of the discussion is about the rather secondary topic of function length, but the actual article is much more indepth. I love the dissection of the render method (which is in fact, only 4 lines long): So... imagine that someone enters a kitchen, because they want to show you how to make a cup of coffee. As you watch carefully, they flick a switch on the wall. The switch looks like a light switch, but none of the lights in the kitchen turn on or off. Next, they open a cabinet and take down a mug, set it on the worktop, and then tap it twice with a teaspoon. They wait for thirty seconds, and finally they reach behind the refrigerator, where you can't see, and pull out a different mug, this one full of fresh coffee. Worth a read for the instructive value of the critique - whether you agree with either point of view, much is to be learned in the "space" between different viewpoints.
- 0des 5y agoI love succinct analogies like this. Anybody could understand that.
- ajuc 5y agoMy mine problem with Clean Code is Uncle Bob technique for refactoring big functions into classes. When you have a long pure function that has several local variables and changes them in several places - you can't trivially split it into smaller pure functions (because you would need to return several values from each of them). You could return Pair<X,Y> or similar, but that's clumsy in Java. Sometimes these values form a single consistent type - then it's simple - make a class out of them and return that. But often they don't, they are just conceptually independent parts of the algorithm. For me that just means the function is cohesive, either change the algorithm or keep away. Uncle Bob's advise is to make a new class out of that function, change the local variables into private fields and split the code into methods of that class with side effects modifying these variables all over the place. This results in exactly the kind of code this article complains about, and I agree it's awful. We managed to change code that was explicit about what it does, with no side-effects and no easy way to break it accidentally - into a mess of small interlocking surprises. Whole classes of programming errors that were basically impossible previously are now easy to make. Can this state even happen when I'm in this function? Should I check for it? Can I call this function after I called that other function? Can I change this variable in this function after requirements changed? The answer after the refactoring is "Dunno - solve this intricate puzzle to find out."
- kafkaIncarnate 5y agoThis is why I never understood or liked NPM. Apparently it's the DRY methodology that I don't like, one thing per function. This is one step closer to understanding a Bash coder. Just get things done, because you don't have the time to worry about how it was done. Maybe a bit of optimization but really optimizing some string or numeric loops that are split second over optimizing functions or operations that take longer periods of time are much more important. Readability and the ability to debug is also important. Stop worrying about the Purity Of Essence of your code, you'll end up turning on your own kind while muttering something about the fluoridation of the code supply.
- tpoacher 5y agoThe only real metric worth using here when discussing such issues is wtfsploc