IsUserIsAnonymouse
I ran across some ‘interesting’ code today. As I do many days while debugging this outsourced website I’m working on, I found some tidbits that should go in the coding blunders hall of fame.
The quick version is this:
The site failed on something called IsDefaultProfileExists. Looking into the code, I find that it takes two variables (IsDefaultProfileExistsParamProfileOwnerNick, ownerNickName).
um…. need I say more…
UPDATE: After getting an email from a non-developer, it appears I do need to say more.
To explain:
Code should be written so people can understand what is happening. The most important thing to know about a function is what it eats and what it excretes.
In the case of this function, which has a silly name “is default profile exists” (understandable but excessively worded in bad grammar), it’s not apparent what it eats. It’s plainly obvious that “ownerNickName” is the ‘username’ or ‘nickname’ of the profile ‘owner’ (although, it would suffice to call this variable “NickName”, which would be lighter code and make just as much sense in the context of the function.
The first variable though is
1. Ridiculously long
2. Confusing
3. Possibly the same value as the second variable?
You shouldn’t have to be a programmer to look at a function and be able to tell what it’s eating. Programmers should never need 45 characters to make a variable understandable–it makes the codebase horribly large and it generally causes more confusion than clarity. Variables definitely need to be clear but there is a limit.