6 ms·
I'll happily be "so brave" and reiterate a simple truism of software development -- comments are the battle cry of terrible developers. They are the crutch of
by huggyface 14y ago
I'll happily be "so brave" and reiterate a simple truism of software development -- comments are the battle cry of terrible developers.
They are the crutch of people who can't read code: "Add more comments because otherwise I can't make sense of what the statements are doing." It is the English speaker demanding that every French passage have an English translation, rather than simply learning French.
They are the crutch of people who can't write code. "My code is a gigantic, illiterate mess, so instead read the comment at the top that has no guarantee of being robust or accurate."
Bringing up mathematicians and Knuth are both irrelevant distractions. Software development in the modern world is a very structure, self-describing affair, or at least it should be. Comments are the short-circuit from having to figure out how to do that.
- ballooney 14y agoYour hubris is certainly self-documenting, if it gives you any comfort.
- eru 14y agoMaking the machine check as much as possible about your code is a worthy and practical goal. I often try long and hard to capture as many invariants as possible in the type system. And even though the language that we are using, Haskell, has one of the strongest typesystems you can find, that's still not very much logic guaranteed by the compiler. Of course, run time checks can catch a few more errors, but I'd rather catch mistakes as early as possible. You seem to have lots of experience with expressing intent in code, and making that intent 'canonical'. How do you make the machine check the accuracy of your code? What language are you using for that?
- FuzzyDunlop 14y agoI'd like you to offer some examples of code that successfully documents its own raison d'être - in a way that a comment couldn't do better - instead of repeating this 'crutch of poor developers' rhetoric. I mean, I can write self documenting code without any comments, and it's perfectly understandable. before_create :auto_increment def auto_increment self.count + 1 end That code fails to tell the programmer why it's in the application logic and not defined in the database schema. What should I do instead, so I can code without crutches? def auto_increment_natural_key self.count + 1 end That's not a great deal better, it's still just saying what it does, not why it's there in the first place. def auto_increment_natural_key_because_another_app_relies_on_it self.count + 1 end Is that it?
- eru 14y agoThanks for trying! Now we just put the comment in the variable name. The compiler just checks the variable names all match up, but doesn't check whether their names make sense. Perhaps the example chosen was too much of a toy to yield valuable insight?
- run4yourlives 14y agodef auto_increment_natural_key_here_because_if_a_product_doesnt_have_a_key_assigned_because_it_came_back_from_return_and_wasnt_assigned_on_during_the_recieve_shipment_process_the_key_doesnt_exist_and_another_app_relies_on_it Pretty sure that's it.
- rhizome 14y agoYour sarcasm is screwing with HN's page formatting.
- dredmorbius 14y agoThis is what element inspectors/editors are for. Snip, snip.
- 14y ago
- vadman 14y agoDo you have github/sourceforge? I'd love to read some of your non-trivial code. I'm not trying to be an a$$hole btw. I am not a coding guru, I genuinely want to minimize the need for comments in my code and am willing to learn from examples.
- huggyface 14y agoDo you have github/sourceforge? I'd love to read some of your non-trivial code. Read almost any non-trivial successful project for good examples. The Linux kernel. Firefox. etc. The frequency and verbosity of comments tends to have a direct correlation with the simplicity of the code (which is the exact opposite of normal expectations).
- flatline3 14y agoLinux and Firefox code basis are messes. Have you written any large projects that you've had to maintain over years, or worked with large teams, or handed off maintenance of a large project to others?
- huggyface 14y agoTwo projects that are enormous successes, both with more contributors than any code that you've ever touched, I would wager. "Messes". Indeed. To your questions, while you're rhetorically asking, trying to wink to the crowd in the implication that the answers are telling, yes, actually I have. To very good effect. I'm speaking from actual experience here, not just the hilarious patter of the bottomfeeder that is far too typical on HN.
- flatline3 14y ago> Two projects that are enormous successes, both with more contributors than any code that you've ever touched, I would wager. No. > "Messes". Indeed. Yes, messes. Why do you think Chrome is eating Firefox's lunch ? Google has both a better-implemented product and sufficient marketing clout to push it. Have you worked on Linux kernel code? > I'm speaking from actual experience here, not just the hilarious patter of the bottomfeeder that is far too typical on HN. What have you worked on? I've worked on FreeBSD, Mac OS X, and an assortment of smaller widely used software projects, including user-facing applications.
- run4yourlives 14y agoI'm not meaning to insult you, but you sounds like a programmer who's experience consists solely of personal projects and academic assignments. As has been said, comments explain why you are doing something in a certain way. That why is often related to a business process, several business process, and/or 25 different outside cases. The code can be amazingly clean and organized, but you comment to indicate why you did something one way and not another.
- huggyface 14y agoI'm not meaning to insult you Sure you are. And that's okay.