Live data from Hacker News

There’s No Such Thing as Clean Code

steveonstuff.com

301–310 of 395 posts

Re: There’s No Such Thing as Clean Code

#301

So True ! After 25+ years of coding, I know one thing. I STILL don't know how to "code correctly". And apart from a few gifted individuals (Rob Pike, Fabrice Bellard Bobby Bingham [ffMpeg team] etc) I'm HIGHLY suspicious of ppl and programmers who claim "they can program correctly" and that "this xyz is the correct way/stack/method/arch". Background:CS grad, start coding at around 13 (thank you dad !) I am well verse…

I've got about a decade more of coding over you and I can confirm the same. The only time you see "clean code" is trivial examples. Get a project that needs to do something complex, and suddenly it becomes not so clean. That's because the real world is messy and complex and solutions are almost always the same. I love your priority list, although I'm scratching my head over the order - not that it is wrong, but I don…

>The only time you see "clean code" is trivial examples. Get a project that needs to do something complex, and suddenly it becomes not so clean. That's because the real world is messy and complex and solutions are almost always the same.

Absolutely ! :)

>Go listen to Carmack or watch Jonathan Blow's code stuff. Far more interesting things there.

Oh ja ! I definitely should have added Carmack to that list !!

Re: There’s No Such Thing as Clean Code

#302
post #96
post #59

The Uncle Bob Martin definition of "clean code" from his book "Clean Code: A Handbook of Agile Software Craftsmanship" is a set of rules that absolutely are not at odds with one another. If you follow them you will end up with code that's really nice to read and easier to maintain, and, most importantly, that you can confidently change. There's a decent summary here - https://gist.github.com/wojteklu/73c6914cc446146b…

> If you follow them you will end up with code that's really nice to read and easier to maintain, and, most importantly, that you can confidently change. I found that a lot of those guidelines lead to the exact opposite. Examples: - Prefer polymorphism to if/else or switch/case (oh, the joy of tracing a simple task through 50 files) - Use dependency injection (same as above) - Hide internal structure (that "private"…

IMO it's generally good advice to be wary of rolling too many disjoint use cases into one abstraction, and I think that's the rationale behind recommending polymorphism, but the ergonomics of actually writing OO code make it impractical advice to try to follow as a rule. Inversion-of-control is often a more practical way to solve the same problem, in my experience

Re: There’s No Such Thing as Clean Code

#303
post #154
post #146

Earlier quoted context omitted.

> PS2. Oh and on 'code reviews': It would be cool if code-reviews were done "anonymously" i.e I should not know until the very end WHO wrote the code. Helps to keep any personal biases at bay - my 2cents. This is a generally good idea, but in small teams it can't really work. Code is in that sense a bit like handwriting, everyone has their own style, and after a long enough time in a small team you learn to recognize…

My biggest problem with code reviews is that they are so often without value. Code review should be a chance for teams to learn from each other, catch issues, and align on coding practices and strategies. In my experience, a lot of the time code reviews are either just a task - where people try to find superficial "mistakes" just to tick a box, or worse a chance for certain colleagues to power trip and try to get oth…

> where people try to find superficial "mistakes" just to tick a box

I've found this to be true in change control as well as any meeting involving people who feel they are compelled to "contribute" even if they don't have anything of value. You don't want to seem like the person who's just attending the meeting and slacking off, so if you're expected to contribute and you can't find any useful critiques, you just pick nits.

Re: There’s No Such Thing as Clean Code

#304

So True ! After 25+ years of coding, I know one thing. I STILL don't know how to "code correctly". And apart from a few gifted individuals (Rob Pike, Fabrice Bellard Bobby Bingham [ffMpeg team] etc) I'm HIGHLY suspicious of ppl and programmers who claim "they can program correctly" and that "this xyz is the correct way/stack/method/arch". Background:CS grad, start coding at around 13 (thank you dad !) I am well verse…

I've got about a decade more of coding over you and I can confirm the same. The only time you see "clean code" is trivial examples. Get a project that needs to do something complex, and suddenly it becomes not so clean. That's because the real world is messy and complex and solutions are almost always the same. I love your priority list, although I'm scratching my head over the order - not that it is wrong, but I don…

>Go listen to Carmack or watch Jonathan Blow's code stuff. Far more interesting things there.

Could you please give the links?

Re: There’s No Such Thing as Clean Code

#305
post #292

Earlier quoted context omitted.

Are you the only working on the codebase? It may be easy to rewrite your own codebase, but it's certainly not easy to rewrite someone else's. Especially if they haven't been caring about code quality and/or test coverage. My definition of "good-quality" code is pretty much exactly "how difficult would this codebase be for a new engineer to understand and modify safely."

You can go really really fast when you don’t give a shit about consequences. Often the worst code comes from prolific people. There’s just so much if it. And if you touch it you will break it at least 1% of the time, so you have to pick your battles when you are trying to keep the ratio under control.

If you write loosely-coupled code, it shouldn't be that easy to break things unless you're careless.

Re: There’s No Such Thing as Clean Code

#306

Earlier quoted context omitted.

Back in university I had an experience that was really instructive. For a project we had to write a program that differentiates mathematical equations. I dove in and just started writing code. Eventually, I realized that I had made a design error and that my code was much more complicated and cumbersome than it needed to be and I was getting stuck due to the complexity of the monstrosity I created. Unfortunately I fi…

> As they say "measure twice, cut once". and also the reuse of the term architecture.. don't put beams at random and see if it works, plan in advance and calculate. They probably had these realizations thousands of years ago, it's a generic economy principle. I forgot what the saying is but solution unfold themselves when you thought about the problem long enough. Oh and lastly, Grothendieck said he wasn't in the bus…

If architects could freely reposition beams in a building, they might take advantage of that fast iteration rather than spending a lot of time calculating up-front.

Re: There’s No Such Thing as Clean Code

#307
post #178

Earlier quoted context omitted.

> One assert per test Was meant to make a failed test instantly communicate what's wrong with the unit under test. As frameworks evolve and our practices around them change, it's absolutely fine to come up with new rules. All of uncle Bobs rules come with pages of explanations of what problems they solve. If you don't have those problems, you may not need those solutions. The book is more about the spirit of the law…

This makes no sense whatsoever. I've read thousands of tests with multiple asserts that were perfectly plain about what was being tested and in many cases the logical sequence made it easier to understand. Breaking them into separate tests with one assert would simply have meant a shit ton more code to read. Uncle Bob's "rules" often come with mile long caveats that he seems to be blissfully unaware of. I think I get…

[deleted]

Re: There’s No Such Thing as Clean Code

#308
post #306

Earlier quoted context omitted.

> As they say "measure twice, cut once". and also the reuse of the term architecture.. don't put beams at random and see if it works, plan in advance and calculate. They probably had these realizations thousands of years ago, it's a generic economy principle. I forgot what the saying is but solution unfold themselves when you thought about the problem long enough. Oh and lastly, Grothendieck said he wasn't in the bus…

If architects could freely reposition beams in a building, they might take advantage of that fast iteration rather than spending a lot of time calculating up-front.

I think it's antithetical, their profession exist only to avoid moving complicated stuff when it's too late. Of course architect can design wrong and then it's costly too.

Re: There’s No Such Thing as Clean Code

#309

Earlier quoted context omitted.

I've got about a decade more of coding over you and I can confirm the same. The only time you see "clean code" is trivial examples. Get a project that needs to do something complex, and suddenly it becomes not so clean. That's because the real world is messy and complex and solutions are almost always the same. I love your priority list, although I'm scratching my head over the order - not that it is wrong, but I don…

>Go listen to Carmack or watch Jonathan Blow's code stuff. Far more interesting things there. Could you please give the links?

Sure, Jonathan Blow is a game developer and he has a couple of great playlists on youtube: https://www.youtube.com/user/jblow888/playlists

I recommend the Game Engine one and the Compiler one. Note, these are not high level fluff talks like Uncle Bob gives, but in-depth, really deep thoughts and watching him make complex decisions while he is actually coding.

Carmack has a bunch of talks, here's a starter: https://www.youtube.com/watch?v=dSCBCk4xVa0

Again, he has produced immense amount of software, from Doom to Quake to rocket control tech to Oculus Rift VR devices.

Re: There’s No Such Thing as Clean Code

#310
post #249

Earlier quoted context omitted.

No, it is not cheap, generally. Example: Dendrite[0] was going to be a Rewrite of Synapse (which was a prototype which ended up going into production). The rewrite started more than 5 years ago, had lots of development breaks and it still is nowhere complete or close to replace a existing Synapse instance (which even today is ... Well ... suboptimal software). The current plans are to support and use both servers lon…

Well starting from scratch for a rewrite is generally a bad idea. I'm more a fan of incremental re-wrties. But I have code bases I have been working on for years with tens of thousands of lines where basically the entire thing gets rewritten ever 18 months or so, a bit at a time. Isn't your example proof of the benefit of pragmatic coding? Synapse is actually serving users right now. Dendrite sounds like a "better de…

They tried an incremental rewrite before. They failed, and started Dendrite.

https://matrix.org/blog/2020/10/08/dendrite-is-entering-beta

Post reply on HN