In this document, I present my favorite best practices & resources on improving one’s coding skills. Warning: This document is not concerned with learning a programming language. It is directed at people who already know how to code, and who want to improve their craft.
In the first part, I will pick & explain some concrete coding best practices & principles that are easy to follow and will already improve your code significantly. Then, I will talk about general resources related to improving one’s code. I will end with a link-list of further blog posts that influenced the way I code.
Concrete & Easy to apply Coding Best Practices
Early Returns: Getting rid of if/else spaghetti code
One thing that I see very often in code are nested
Nested ifs are evil! They make it very hard to get the program flow into your head. Actually, I would even go that far and say that else blocks should be avoided as much as possible. else-blocks often become the place where you do your error handling logic - but this means that the error handling gets pushed down to the bottom of your method and you it becomes hard to keep in mind under which conditions which error handling occurs. Instead, you should do the error handling as soon as possible and focus your mental energy on the happy path!
One feature to the rescue: Early returns! I don’t know how, but programmers often get caught up in the idea that a method should only return at one well-defined point at the bottom of he method’s code. Until then, allnecessary information for returning gets passed through all of the method’s code. But this is a mistake! Often, you can easily rewrite code like the one in the example like this:
- https://blog.codinghorror.com/flattening-arrow-code/ (also: Try to refactor your
if-conditions so that they are positive ⇒ easier to read)
Comments: Code should explain the what, comments the why
- Code should explain the what, comments the why. The best comments are the ones you don’t need. https://blog.codinghorror.com/code-tells-you-how-comments-tell-you-why/
- Make everything as
constantas possible. https://stackoverflow.com/a/8353371 , https://stackoverflow.com/a/3182664/3327577
- Think twice before using class inheritance. People tend to overuse inheritance. Inheritance can easily lead to confusing code. You almost always can do without inheritance. Use composition over inheritance. https://news.ycombinator.com/item?id=19863871 , https://stackoverflow.com/a/37624298/3327577 , https://softwareengineering.stackexchange.com/a/371715
- Baseline when coding: Think about your future collegues & your future self. Make your code easy to read (vs. easy to write). It will be read much more often than modified ⇒ take time for naming and structuring, refactor often,…
- Variable names: https://wiki.c2.com/?GoodVariableNames
- Use variable names that describe what the variable is doing. Don’t just use random letter. If in doubt, prefer longer variable names over highly-abbreviated ones.
- Do not use Magic Numbers directly - extract them into constants with good names & use the constant instead
The best resource: Discussing with coders around you
First things first: The best way to improve one’s skill is to talk & discuss & pair up with coders around you and learn from them. Be it your co-workers, your fellow students, or some friends on the internet. By actually talking to people, you will get a lot more context than by simply reading articles on the internet. Also, by discussing with them, it helps you structure & formulate your own thoughts, instead of simply consuming knowledge. So, even if the people around you are not the best coders, the discussion helps you improve. That said, best case is of course when you get to talk to people you have better coding skills than you and to learn from them. A big “Thank you!” to Johannes, Johnny, Joel, and Jochen, who I all admire & who significantly influenced my way of coding!
A general advice: Challenge everything you hear and read and make up you own thoughts. Don´t blindly follow the advice of someone without agreeing on the reasons behind. This counts both for personal discussions, as well as for blog posts. Even the most well-regarded programming books might have advice that you should not follow, e.g. because your situation does not fully apply to the one assumed in the books.
To challenge everything (to an extent) is a good advice for (not just professional) life in general… 😉
The one book: Clean Code
If there is one book that is regarded as “the” book on coding craftsmanship, it is Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin (also called “Uncle Bob”). This is the bible of coding, and has a lot of inspiration to offer. In fact, a lot of the coding advice you’ll find on the internet is probably just a rehashed version of some of Clean Code’s concepts.
The book was published in 2008, which is a long time in IT, but has aged well. That said, I like the book especially for his general inspiration and ideas, e.g. on the purpose of clean code, how to distinguish good code from bad code, code smells. I don’t especially like the refactoring code examples and would recommend to not follow them religously - I find them too verbose and to actionable enough to apply on one’s own code.
Clean Code collections for specific programming languages
WIP: Coding Posts that influenced me
- In general: Blog posts by Jeff Atwood on codinghorror.com. Also: Posts by Joel Spolsky
- Get Total Directory Size via Command Line
- Changing DNS server for Huawei LTE router
- Notes on Job & Career Development
- Adding full-text search to a static site (= no backend needed)
- Generating a random string on Linux & macOS
- Caddy web server: Why use it? How to use it?
- Tailwind CSS: A Primer
- Versicherungen: Learnings
- Screen Recording on macOS (without any extra tools)
- WSL2 Cheat Sheet