
Ask HN: What are your best resources for writing clean code? - panosfilianos
Hey,
I&#x27;m in the process (after 4 years of BSc and 2 years of MSc in SE) to get serious about writing good, proper, clean code.<p>Colleagues have recommended Clean Code: A Handbook of Agile Software Craftsmanship and I&#x27;m very tempted to try James Koppel&#x27;s coaching.<p>What books&#x2F;resources&#x2F;courses have really helped you to step up your code game?
======
muzani
After doing it for years, I've realized that clean code isn't really a good
end goal, so I'm not sure if it "steps up your game"

That said, The Pragmatic Programmer is my favorite resource for it.
[https://refactoring.guru/](https://refactoring.guru/) is also a nice
reference point, in an easy problem-solution format.

~~~
panosfilianos
So what would you say is an appropriate end goal to max out productivity,
collaboration and reusability of/on code?

~~~
muzani
Deliberate practice. Find what you're weak at and work on that.

Clean code is great, and it's definitely someone's weakness, but it doesn't
sound like yours. Find out what's making you procrastinate or hesitate, and
focus on that instead.

If you're procrastinating because your code is a mess, then you probably want
to learn clean coding. But at some point it will have diminishing gains, like
learning to type fast.

The little things that have greatly improved my productivity recently: ES6
literacy, zsh aliasing, knowing array methods by heart, IDE shortcuts, CSS
animation.

Ideal productivity is not at 100% clean code & architecture, but somewhere
between 40%-80%, I'd say. The more confident you are of a feature and the more
confident you are in the architecture, the more you can invest in it.

There's an anti-pattern on refactoring as well. Many times you want to put a
constant or config in the code itself. Sometimes you even want to ignore DRY
and copy code. I also use god objects as a dumping ground for methods and then
refactor parts of them into a class much later, when a pattern emerges.

------
UglyToad
You can buy Clean Code and it's not going to hurt, but I increasingly believe
the only way to "step up" is to write code, lots of it.

Things like Clean Code are a bit too dogmatic for my tastes now, there are
some reasonable ideas there but it's tempting to apply them where they don't
fit.

What helped me was starting my own large project [0] based off porting another
codebase. I started with wanting to follow Clean Code practices to the letter
but now, 2/3 years later and with the benefit of hindsight I'm increasingly
moving away from a lot of the Clean Code 'rules' (short methods, etc).

But I also write other short lived projects which allow me to try different
things out and learn from my mistakes. When you think how we learn as children
a lot is based on making mistakes and I think that is what's missing from a
lot of how programming is taught.

[0]: [https://github.com/UglyToad/PdfPig](https://github.com/UglyToad/PdfPig)

~~~
tcbasche
I find Clean Code hasn't aged well either; a lot of the java-esque design
patterns have been superseded with either language features (speaking as a
Python/Go developer) or a better overall code architecture / structure.

Having said that though, it's a good primer in what's possible in writing
clean and testable code.

------
JaumeGreen
Learning different paradigms has helped me write cleaner code.

Functional programming, with its functions without side effects, has taught me
how to better isolate the functionality in OOP code.

Lisp with its "code is data, data is code" has taught me how to create data
that can be used to generate the correct code that had lots of duplication.

Years of working on legacy code has taught me the difference between useful
and confusing abstraction, and what kind of code is more maintenable.

As @UglyToad has exposed "write code, lots of it".

------
tcbasche
For good clean code, check out the Thorsten Ball books - Writing an
Interpreter[0] / Compiler[1] in Go

[0] [https://interpreterbook.com](https://interpreterbook.com) [1]
[https://compilerbook.com](https://compilerbook.com)

While the books are not strictly about clean code, there's definitely a focus
on it within the books.

------
jerome-jh
It is often easy to make code cleaner even in a corporate setting:
improve/update comments, reformat, add keywords that clarify the intent
(const, private, ...), add explicit checks at the beginning of functions
instead of letting them fail later in their body, remove duplicate code, split
functions.

If you do it in a separate change/commit, it should be welcome.

I am not talking of refactoring: that is a completely different story, and
requires extensive testing, long reviews...

------
aditeek
To make your code clean you have to maintain the readability of your code. You
have to make sure there is no duplication, code smells and vulnerabilities in
your code. To maintain your code quality you have to do code review. I use
Codegrip [https://www.codegrip.tech/](https://www.codegrip.tech/) which makes
code review easier and maintain the quality of your code. Codegrip is the one-
stop tool for all code quality measures. Codegrip helps you to build a
powerful code. It is an automated code review tool where code undergoes
various tests for bugs, code smells, vulnerabilities and scans it for any
security issues. It is a code analysis tool that finds critical metrics like
duplication percentage, suggestive error, error resolution time, and many more
displayed for all types of code. CodeGrip makes sure that every software has
excellent code quality.

~~~
panosfilianos
Have you found that CodeGrip helps you not repeat these kind of errors again?
Is it valuable as a learning resource?

~~~
aditeek
Yes, Codegrip also provides suggested solutions for each bug which explains
why that bug is harmful and which is the best approach to solve it.

------
pow999iper
Clean code won't hurt, approved

