My very good friend anon commented on my last post, asking:
What about interface documentation (summary, param, etc.)?
I agree that implementation how-to comments are usually redundant (if appropriate, a single comment that names the algorithm being used is good), but I like interface assumptions documented.
*Unless* I am building a closed source library/framework, product that someone else is going to program against, and I correspondingly need good documentation for the developers, I typically want to go one of two places to understand interface assumptions: either the regression test suite (you have one, right?), or the code itself.
For example, consider the following psuedo-code (psuedo so I don't have to worry about it compiling):
///
/// Assumes the provided DateTime since is within the previous linear year
///
IList GetWhozitsSince(DateTime since)
{
if(new TimeSpan(since, DateTime.Now).TotalDays > 365)
throw new InvalidDateRangeException("expected something else);
return Persistence.FindWhere(typeof(Whozit), "CreateDate > {0}", since);
}
If you have the source, is the really a need for the comment? If it is really unclear, maybe you could try:
IList GetWhozitsSince(DateTime since)
{
EnsureWithinLastLinearYear(since);
// warning: heretical, hypothetical, metadata-based, O/R mapping ahead
return Persistence.FindWhere(typeof(Whozit), "CreateDate > {0}", since);
}
void EnsureWithinLastLinearYear(DateTime since)
{
int DaysPerYear = 365;
if(new TimeSpan(since, DateTime.Now).TotalDays > DaysPerYear)
throw new InvalidDateRangeException("expected something else);
}
Of course that extra method call might really kill your performance, so maybe the comment makes sense.
(
If you watch Saturday Night Live and have ever seen Fred Armisen on the weekend update trying to teach Jimmy Fallon how to deliver a joke, latin-style, imagine his voice on this next part:
"I'm just kidding."
)
I do think it is worth making the point at this point that I am talking about my personal preference and coding style. If my team agrees to a particular granularity for commenting, I am going to stick to it, if only for the esprit de corps. If I am on a distributed development team, and the disconnectedness forces higher ceremony and more verbose documentation (apart from the source code), then I am all Visio and Word. I just prefer face to face communication, tests, and code as the ultimate arbiter of truth. And I still long for the "Hide the comments" option.
Recent Comments