January 26, 2018
Good Code Speaks The Customer's LanguageSomething we devote time to on the Codemanship TDD training course is the importance of choosing good names for the stuff in our code.
Names are the best way to convey the meaning - the intent - of our code. A good method name clearly and concisely describes what that method does. A good class name clearly describes what that class represents. A good interface name clearly describes what role an object's playing when it implements that interface. And so on.
I strongly encourage developers to write code using the language of the customer. Not only should other developers be able to understand your code, your customers should be able to follow the gist of it, too.
Take this piece of mystery code:
What is this for? What the heck is a "Place Repository" when it's at home? For whom or for what are we "allocating" places?
Perhaps a look at the original user story will shed some light.
The passenger selects the flight they want to reserve a seat on.
They choose the seat by row and seat number (e.g., row A, seat 1) and reserve it.
We create a reservation for that passenger in that seat.
Now the mist clears. Let's refactor the code so that it speaks the customers language.
This code does exactly what it did before, but makes a lot more sense now. The impact of choosing better names can be profound, in terms of making the code easier to understand and therefore easier to change. And it's something we all need to work much harder at.
Posted 6 months, 3 days ago on January 26, 2018