top | item 37248314

(no title)

katamaster818 | 2 years ago

This isn't exactly a repo to look at, but the book "Clean Code" is a fantastic read for learning how to write good code. It does have a lot of examples in it, and does a great job explaining everything. https://github.com/jnguyen095/clean-code/blob/master/Clean.C...

discuss

order

pc86|2 years ago

https://qntm.org/clean has a great discussion of all the things that are wrong with Clean Code.

ecshafer|2 years ago

I don't like clean code, and like the author I find the things presented in Clean Code to just make incredibly inscrutable code. The worst code bases I have seen have been the ones with no code plans at all, and the ones that use Clean Code and Gang of Four like a bible, both are equally mazes of spaghetti. Clean Code I really just don't agree with, and I think this author lays it out well. Special design patterns and tons of polymorphism usually end up creating multiples of complexity in the effort to reduce DRY at any cost (and often are abstractions that are only ever used one or two times anyways).

Ultimately I think the single most important rule for clean code is: skinny controller, fat model. If you are doing batch data, then this applies still I think. You should have all of the logic you can in the model, avoid data objects. And the code paths that alter things should be as thin as possible. I honestly think it is better to have a 5k line model if it avoids more.

The most unlcean code I have seen usually falls into the abstracted out processes in financial instutitons where they follow Clean Code advice and everything are a bunch of functions passing around some big fat objects full of getters and setters, and changing any functionality means adding changes somewhere in the process to check state and alter the state, which leads to loops and if statements everywhere to see which account type it is at each point etc.

But in OOP programming its supposed to be objects sending messages to each other. Every object should know everything about itself, which is what a fat model demands. Any more abstraction than that seems to get in the way.

y-curious|2 years ago

Interesting read. I read a companion book (or is it wholly unrelated?) called Clean Code for Python and I learned a whole lot! That book improved my Python more than anything else, honestly. That being said, I agree with the critique that obsessively committing to DRY is throwing the baby out with the bathwater.

butterNaN|2 years ago

The side effects example is exactly where I put down the book. I briefly questioned whether the book is supposed to be satire.

chimprich|2 years ago

Clean Code is dreadful, or at least the programming examples are.

It was a good book of its time in that it was influential and encouraged people to think more deeply about how to make code readable, but even when it was published I thought it had some terrible advice.

It's probably still just about worth reading, as long as you ignore all the code examples and appreciate that some of the thinking is out of date, and a lot of the rest is controversial at best.

I also find the style grates, as "Uncle Bob" is far too full of himself and e.g. "rips apart" someone's code to produce a worse refactor.

_gabe_|2 years ago

There’s so much conflicting advice in this book (like saying functions should be immutable then also saying the ideal function has 0 arguments, apparently mutating the class doesn’t actually make the function mutable to Bob Martin!), and the code examples themselves are horrible (the prime number generator for example).

I’ve heard people say it’s a good book if you just ignore all the bad stuff, but how are you supposed to know what the bad stuff is if you’re a beginner? I think it’s time to stop recommending this.

lijok|2 years ago

> like saying functions should be immutable then also saying the ideal function has 0 arguments, apparently mutating the class doesn’t actually make the function mutable to Bob Martin!

What does "functions should be immutable" have to do with mutating classes?