Juri Strumpflohner
Juri Strumpflohner Juri is a full stack developer and tech lead with a special passion for the web and frontend development. He creates online videos for Egghead.io, writes articles on his blog and for tech magazines, speaks at conferences and holds training workshops. Juri is also a recognized Google Developer Expert in Web Technologies

Comments smell! Replace them with more expressive code.

1 min read

As already pointed out in that post, here's another code example:
...
//300 = Italy
if(aCompany.NationId == 300)
{
...
}
...
The comment above the if clause is definitely a code smell. If you wouldn't have that and you come back three months after releasing the software in search for a bug, you probably don't remember what's the meaning of 300, right? Therefore, refactor it by writing more expressive code:
...
if(aCompany.NationId == Nation.TypeOf.Italy)
{
...
}
...
The comment is completely useless now. Every developer in the team will now understand the meaning of this code without any effort. Note, such code can lower the mean-time-to-repair (MTTR) significantly.
Questions? Thoughts? Hit me up on Twitter
comments powered by Disqus