There are lots of books and websites about software design. But often, the devil is in the details. Look after the pennies and the pounds look after themselves. There are a whole lot of little thing that if you pay attention to them, it just makes life a little easier.
This is about the little things.
Friday, April 1, 2011
Names ending in 2
It's almost always a wrong thing to have a variable, class or function whose name ends in 2.
class SensorReadingTransform sensorReadingTransform;
class SensorReadingTransform2 sensorReadingTransform2;
Anyone care to make a guess as to the difference between the 2 classes above.
Does this code "speak to you"
Are you going to have to go look in the class to have any idea what the difference is?
If I'd renamed the first one, and created the second one as follows
class SensorReadingLinearTransform sensorReadingLinearTransform;
class SensorReadingNonLinearTransform sensorReadingNonLinearTransform;
Now you have at least a starting point. Yes, that's what I need, look further, or no, that's ok, I need to look somewhere else.
And truly, if the best name you can come up with is "Foo2" then that says a lot about the need for some rethinking.