Reading and Learning 'Clean Code' by Uncle Bob #Day_8
Understand clean code with me and become the clean coder
Welcome back to the Clean Series, where we journey through the principles and attitudes that define the mindset of a professional coder. In Chapter 4 of "The Clean Coder," author Robert C. Martin shares his insights and principles, acknowledging that they might not resonate with everyone. The central theme of this chapter revolves around building confidence, staying error-sensitive, and nurturing a professional coding mindset.
Chapter 4: Coding
Software development is a marathon, not a sprint.
Preparedness: The Foundation of Clean Code
Mental preparation is the cornerstone of writing clean code. Before you dive into the depths of code, it's essential to comprehend the problem thoroughly. In the world of clean code, the importance of readability cannot be overstated. Remember the lessons we've learned from our previous Clean series blogs.
Your focus and concentration play pivotal roles in crafting quality code. Avoid distractions that hinder your ability to deliver code with precision. After all, your code should not only work but also communicate its intentions clearly.
In the realm of professionalism, solving your customer's problem is paramount. Sometimes, the customer's stated requirements may not effectively address the issue at hand. It's your responsibility to understand their needs and negotiate for their ultimate benefit.
Writing Bad Code: The Perils of Poor Circumstances
Writing Code When Fatigued: Coding late at night, when your brain is pleading for rest, is a recipe for poor code. Dedication is commendable, but it should not come at the cost of code quality.
Worry Code: A preoccupied mind, filled with worries unrelated to the task at hand, can sabotage your coding efforts. Your inability to concentrate can lead to time wastage both for your code and your personal concerns.
The Flow Zone: While getting into the 'zone' can feel productive, it's crucial not to overlook the bigger picture. Speedy coding can lead to frequent revisits, resulting in inefficiency.
Being in the zone isn't inherently negative; it can be productive during practice sessions. Sometimes, when interrupted in your flow zone, you can get rude to your colleagues as one doesn't like getting dragged out of the zone. However, it's essential to remain courteous when interrupted, as professionalism extends to respecting your colleagues' work and concentration.
Listening to Music: Music can be a double-edged sword. While it may aid some in coding, it can also serve as a distraction. It's a personal preference, but understanding its effects on your concentration is key.
Writer's Block: The phenomenon of facing a creative block is not unique to writers. Coders can experience a similar roadblock. Taking a step back can often spark new ideas and creative solutions.
Being Late: Delay can be an unexpected twist in the coding journey. In such instances, it's crucial to stay grounded and realistic rather than letting optimism cloud your judgment. Communicate your situation transparently to your team and stakeholders, emphasizing the reality of the circumstances. Resist the temptation to rush, as pushing harder won't magically accelerate the coding process; in fact, it might slow you down.
Woe to the poor developer who buckles under pressure and agrees to try to make it to the deadline.
While overtime can be a solution, it's not a universal fix. The author underscores the need for considering overtime only under specific conditions:
Personal Affordability: Ensure that you can personally handle the extra workload and time commitment.
Short-Term Commitment: Overtime should be a short-term solution, limited to two weeks or less.
Contingency Plan: Your boss should have a backup plan in case the overtime efforts don't yield the desired results.
Avoiding Bad Code: Strategies for Excellence
Pacing Yourself: Treat your work like a marathon, not a sprint. Conserve your energy and creativity carefully.
Knowing When to Walk Away: Creativity and intelligence are fleeting, especially when fatigue sets in. Recognize when it's time to step back and recharge.
Creative Hunt: When stuck in a writer's block, seek creative input from other sources. Escapism, whether through reading, art, or other interests, can rekindle your creativity. For the author, it was science fiction. It can be something else for you. For me, sometimes it’s engaging in sketching and drawing.
Find a Pair Partner: Pair programming isn't just about code; it can help break writer's block and prevent falling into the flow zone, promoting efficiency.
Define 'Done': Don't succumb to the pressure of rushing when time is running short. Instead, define 'done' using automated acceptance tests, ensuring professionalism and clear criteria for project completion.
The Professional Coder's Toolbox: Extra Insights
Debugging: Debugging is an integral part of coding, but some programmers don't consider debugging time as coding time. Reducing debugging time is vital. Test-driven development (TDD) is one approach that can minimize debugging efforts suggested by the author. A software professional will put effort into minimizing debugging time as much as possible.
Help: The author explains the concept of help in two ways:
Helping Others: Understand and recognize when your teammates are stuck. Offer help or engage if you can when asked for help. This shows good work ethics and builds good professional relationships.
Being Helped: If offered help, be grateful and take the assistance. If one doesn’t receive the help they need, they still should be polite and say thanks. It is also important to learn how to ask for help.
Mentoring is also a type of help. As senior developers, they should look out for their juniors and guide them, make them aware of possible scenarios and introduce the bigger picture to them. As junior developers too, they should search for such seniors who can provide them guidance and be their mentors.
This chapter from "The Clean Coder" emphasizes the importance of professionalism in coding. It underscores the significance of mindset, preparedness, and a commitment to deliver clean, high-quality code. This particular chapter was pretty insightful for me. I highly advise you to consider these practices and start including them one by one in your coding life and you'll surely see change. On Day 9, we will return with the 5th chapter from the book, 'Clean Code'. That'll be the last chapter I take from that book for this clean series. Till then Happy Clean Coding!