3 ms·
It has earned me the Stickler moniker, and I'm absolutely alright with this. They've never had the displeasure of refactoring code from 3 years prior where the
by noxToken 10y ago
It has earned me the Stickler moniker, and I'm absolutely alright with this. They've never had the displeasure of refactoring code from 3 years prior where the function's name is getIpAddress(), but it does 6 additional things within the method. The docs says, "Gets the IP address". The commit message says, "gets user's IP address". The function really gets the IP address, does some weird encoding (of which I'm still not sure why), does some other stuff with the request headers, then returns the IP.
Documentation saves lives, people.
- rkangel 10y ago"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live"
- retro64 10y agoYou may want to also consider refactoring this code. A function should do what it says, not have unexpected side effects. Not only can this be surprising to a client, but it also makes it difficult to leverage the code for reuse elsewhere ("I only wanted the IP address, not the rest, guess I'll write one called getIpAddressOnly", etc). Functions like this also tend to become muddled and difficult to maintain because as time marches forward, functionality may need to be added between these side effects, and again, unless it is refactored, it has to end up within the same function, making the whole problem even worse.