Line length … really follow the rule of 6. If you have more than 6 things for a programmer to remember, their brain is going to blow up.
As Java developers, we all have an innate, burning desire to write the cleanest code possible. If given the opportunity, each and every one else would write code so clean you could read it to your kids as a bed time story. That’s just the thing, “If given the opportunity”. Developers don’t write bad code; bad situations write bad code. At some point in our coding careers we’ve all had the sneaky feeling that we’ve compromised our clean code instinct. Perhaps the code you were working on was poor condition. Perhaps there was a deadline and it just needed to get done. Whatever the case, at some point we’ve probably set our convictions aside because there looked like there was just no hope. Men like Martin Fowler, Robert “Uncle Bob” Martin, Ward Cunningham, and Kent Beck have been in those situations and they have found the answers. They have solved the problems that cursed programmers as recently as 8 – 10 years ago. They have given us a tremendous gift. And with that let’s look at some code.. That feeling is really what started me on a quest to discover what it means to write clean code. It was a desire to know and have the confidence that my code was the absolute cleanest it could possibly be.
Let’s talk about how not to get there…“Uncle Bob” talks about the grand redesign in the sky.Someday, your code base is going to get the golden seal of being rewritten. What a glorious that will be! We shall pool the most talented programmers “Tiger Team” into one project and dream of the ultimate design.ANNNNNNNNNNNNNNNNNNNThis point is talked about in Refactoring as well. Creating clean code is like eating an elephant, one bit at a time. Taking the big rewrite jump could land you with some of the same predicaments as beforeThe most important tool in creating clean code is having worthwhile unit tests backing your base.
The best tool get your code cleanIt’s so much fun thinking of the perfect design for code and making UML documents etc.Test driven development drives the perfect design out of your codebase. It makes writing dirty code painful!The cleanliness of your tests is has a direct correlation with your design. One assert per test!!
“”I could list all of the qualities that I notice in clean code, but there is one overarching quality that leads to all of them. Clean code always looks like it was written by someone who cares.””<br />-Michael Feathers<br />author of “Working Effectively with Legacy Code”<br />