Tuesday, December 1, 2009

Consistency in naming matters

If you have a naming convention for your code, stick with it.

If you don't have a naming convention for your code, establish one, and then stick with it.

You may not like the naming convention, but it doesn't matter. Even if you don't like it, stick with it. If you really don't like it, you can try to change the convention (which implies changing all the code to match it, of course), but don't just casually violate the naming convention.

It's just unbelievable how many hours of my life I've wasted dealing with situations where one programmer wrote:

String result = obj.getKeyByID(my_id);

while elsewhere, nearby in the code, a different programmer wrote:

Object obj = store.readById(my_id);

and thus, while working in that code, I casually wrote:

Object anotherObj = store.readByID(different_id);


Yes, I know, modern IDEs help you notice such simple problems rapidly.

But the whole world would be so much better if we just avoided such inconsistencies in the first place.

Grumble grumble grumble

No comments:

Post a Comment