Bookreview: Clean Code on the rescue
You´ve learned yourself to code, followed several video tutorials and courses or even attended a bootcamp or two and now you are ready to start for your first jobs in Tech. But this is where it gets hard. Bootcamps make it sounds easy to get a real job after a few months of non-stop coding. Yet, after applying for several months doing coding challenges, you get tired of hearing a “No, you lack real-world experience”.
How can you end up getting a job in Tech, if the entry-level jobs are lacking and you hardly get feedback on your job application attempts? So, how do you get the job? Our answer at Code Sherpas is simple: start improving your code quality! How? Let’s get started!
Clean Code on the Rescue
At Code Sherpas we suggest you start reading “Clean Code: A Handbook of Agile Software Craftsmanship-Robert. C Martin(2008)”. This book is seen as the bible of software engineering. And with daily practice you will be able to get a job on Mid or even Senior level. So, don´t give up, grab yourself a copy and keep on coding.
Good Code, Bad Code
Code is code, you might think. But that is not entirely true. Code can be divided into good code and bad quality code. But what makes code good or bad? And why bother to write good code if even bad code can function?
Writing clean, understandable, and maintainable code is a crucial skill for every developer to master their craft. Yet, more than a skill that can be acquired overnight, clean coding is a habit that needs to be developed by keeping these principles in mind and applying them whenever you write code. Or as Martin Fowler explains it so well:
“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” — Martin Fowler(2008)
Every year, countless hours and significant resources are lost because of poorly written code. This is what Robert Martin- better known as “Uncle Bob” made to decide to write a book about Clean Coding. He teamed up with his colleagues to write a book with the best agile practice of clean coding to help the reader become aware of the values of a software crafts(wo)man and make them better programmers.
Excellent software crafts(wo)men
As an aspiring software engineer, a great practice is to regularly read and write a lot of code. But that in itself is not enough to become an excellent developer, software engineer, project manager, team lead or systems analyst. In order to thrive in a fast-paced Tech industry, you need to take your skills to the next level. Instead, you need to challenge yourself to think about what is right and what is wrong about the code. You also need to be clear about your personal commitment to your craft and reassess your professional work values. Take nothing for granted and constantly improve yourself by trying to understand anytime you write, read and clean up code. That is what distinguishes excellent software crafts(wo)men from the average developer.
To obtain this level of excellence, interest in writing better code is at the core of personal improvement. Therefore the autor divided the book “Clean Code” into three parts:
- PART 1: Principles, Patterns and Practices of writing clean code.
- PART 2: Case studies & exercises of increasing complexity. Each case study is an exercise in cleaning up code and transforming a problematic code base into a clean and efficient one.
- PART 3: Bad Code Examples. The last chapter consists of a list of “code smells”, gathered while creating the case studies.
The result is an entire knowledge base that describes and helps to understand:
- GOOD vs BAD code: How to distinguish between good and bad code
- GOOD CODE: How to write good code
- REFACTOR CODE: How to transform bad code into good code.
- NAMING: How to create good coding names, functions, objects and classes
- FORMATTING: How to format code for maximum readability
- ERROR HANDLING: How to implement complete error handling with correct code logic
- UNIT TESTING: How to unit test your code
- TEST-DRIVEN DEVELOPMENT: How to practice test-driven development
The 7 rules of Clean Code
The book distinguishes seven most important best practices for clean code:
RULE 1: Names matter
Independently of what type of data naming is used- be it a variable, function, parameter, class or method- names matter for clear code:
“A name should tell you why it exists, what it does, and how it is used. If a name requires a comment, then the name does not reveal its intent.” — Clean Code
RULE 2: Boy Scout principle
Based on the camping principle of Boy Scouts, in programming:
“You should leaving the code cleaner, than it was before editing”- Clean Code
RULE 3: Tell a story
Programming is like telling a story. As the programmer is the author of this coding story, (s)he needs to take care of how the story of code is presented:
“You should structure clean code with simple, small and clear functions, that just solve one thing”- Clean Code
RULE 4: DRY principle (Don’t Repeat Yourself)
In Coding, less is more:
“In databases, documentation and tests, the most important thing is to Do Not Repeat (DRY) yourself.”- Clean Code
RULE 5: Comment only if needed
In a Code Base, code is modified, but comments are not:
“Comments are like lies. They are often forgotten and do therefore not portray the actual functionality of the code base. Only use comment if needed”- Clean Code
RULE 6: Error handling
Handling Errors and exceptions correctly is an important skill to have as a programmers developing software:
“Things can go wrong, but when this happens, programmers are responsible for ensuring that the code continues to do what it needs to do”. — Michael Feathers
RULE 7: First test, then Code
Although often forgotten, when learning to code, carrying out unit tests in the programming area is a very important stage. A code is only considered clean, after being valid through tests, which must also be clean. The best way to write a test, is to write the test, before writing any code. This is what is called a Test-Driven Development (TDD):
“In order to consider a test as clean, the test must be: fast, independent, repeatable, self-validated and timely.”- Clean Code
In software engineering, constant reading is a must to build foundational knowledge and improve branch knowledge. And Clean Code is an absolute “must-read” item. So, next time you prepare yourself for a coding assignment, keep the book Clean Code at hand and follow up these 7 principles of clean code as stated above. These practices really help you to improve the main problem, many code bases and systems projects face: better code maintenance.