If you want to learn a code base, start renaming things

They say the 2 most difficult things in computer science are cache invalidation, naming things, and off by one errors.  That explains why so many things are misnamed in code bases.  This is a pet peeve of mine and I always try to fix it whenever I can.  It’s the easiest way to to practice the boy scout rule.

I go around renaming poorly named variables and classes.  It’s a win-win situation: The code base is easier to understand for the next guy and it’s easier to understand for me.  When you rename something, you have to understand the code at a certain level of depth that is unnecessary if you merely look at it.  The best way to understand code is to actively participate in it.

Sometimes you may think you know how a variable should be named, but then you realize that it’s used in another place you didn’t notice and you made a mistake.  That little detail will stick in your head better than just looking at the method.


This is probably different enough to warrant its own post, but I also want to say you should name your servers appropriately.  If in casual conversation you call the server the “HP Demo Server”, it shouldn’t be named “xfdke03.mycorp.com”.  Stop making a humans build an associative map in their head.  That server should be named “hpdemo.mycorp.com”.

Usually these servers’ domains can’t be changed over night and it may be risky to do so, so it never happens.  In that case, I edit my hosts file so that “hpdemo” resolves to the IP Address of “xfdke03.mycorp.com”.  Not the best solution in the world (the IP address can change), but it’s better than nothing.

Companies should take these complaints a little more seriously though.  If “HP Demo Server is “xfdke03.mycorp.com” and “HP Prod Server” is “xfkde03.mycorp.com”, a person could accidentally do some serious damage if they had access to both.