I was writing some comments in my code the other day. Yes, I know first mistake – letting a manager write code. But you have to get past that.
I was actually writing a comment. It said something like…
/// This class rolls over old log files into a folder and writes a summary file.
All good you might think. The original product had implemented the file rollover feature in this class and now I was just adding a bit more code to write an XML file and accompanying XSLT from a resource to show a summary of logs when loaded in IE. Each time the class rolled over the log file it updated the summary too.
The problem here is “and” what this should tell you is that you now have a class that does two different things, thus adding coupling and breaking orthogonality. This is generally bad (understatement).
The lesson I learnt here is that code comments can smell too and sometimes it’s easier to spot than when you’re deep in the code. I ended up refactoring the summary story into a separate file.
I’m actually thinking that there may be some other language constructs that map directly to smells if anyone can think of some good examples I’d like to hear them.