Wednesday 16 November 2016

Clean Code - What is it anyway?

It's become a meme that the tech industry is in the middle of a tsunami of change and a lot of software houses are running scared that they are going to be the next Kodak or Blockbuster - the octopus that sees the hungry dophin coming, but doesn't change colour fast enough to avoid being eaten.

After a decade or so of stagnating in a marsh of mediocre talent, idiotic management and poor standards, denigrated and career repressed , it has suddenly become cool to code again. Companies are suddenly seeing the value in those socially inept code monkey losers as they realize just how hard to find and hire their special skills are. 

Amid all this there has arisen a movement calling itself software craftmanship, which even has its own manifesto: http://manifesto.softwarecraftsmanship.org/ 
Among all this there is much talk of "Clean Code". So it’s worth spending some time asking the question: Just what is “clean” code?

While being a familiar concept among software professionals, it’s fair to say that the concept Clean Code was first comprehensively defined in a book by “uncle” Bob Martin called “Clean Code – A Handbook of Agile Software Craftsmanship” first published in 2008. Martin begins the book by asking “What is Clean Code?” of several of the most respected leading lights in the field (Bjarne Stroustrup, Grady Booch, “Big” Dave Thomas, Michael Feathers, Ron Jeffries and himself). Their responses are remarkably consistent. 

For them, clean code:
  • Is readable
    • By human beings, not by compilers
  • Is easy to understand by someone other than the person who wrote it
    • It uses meaningful names
    • It isn’t too long and meandering
    • The design is easily understood
  • Is adequately commented
    • All intention cannot be conveyed simply by the code logic itself
  • Is concise and to the point
    • It does one thing well
    • It does not contain duplication
    • It minimizes the number of entities (classes, methods, functions etc) required to implement the design
  • Has automated unit tests
  • Has minimal, explicitly defined dependencies
  • Provides a clear and minimal API
  • Is cared for and maintained
Each of these deserves its own post in itself, but the overriding message is that, above all, “clean” code is really an attitude. It’s about taking a professional approach to writing software and continuously improving the code you work with.



No comments:

Post a Comment