Hacker News new | past | comments | ask | show | jobs | submit login

I think the bar of usefulness for comments should be pretty low. Most modern IDEs will dim them for you anyway, so it's minimal how visually annoying it is.

The problem is more that you might not have a comment when you need one. There's a lot of times when the author has thought a lot about something and thus understands it, but someone glancing over the code might not.

Example:

    def caterpillarMethod(A, s): 
      n = len(A)
      front, total = 0, 0
      for back in xrange(n):
        while (front < n and total + A[front] <= s):
          total += A[front]
          front += 1
        if total == s:
          return True
        total -= A[back]
Someone reading this might think it's O(n*2), because there's a loop in a loop and that often makes it so. But if you look closely it isn't. So maybe comment that.



Yep, and while I can understand what this is doing by going through it line-by-line, at a glance I haven't a clue. What is the high-level purpose of this function? This could be remedied with a few good comments.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: