5 ms·
I disagree. Code without comments will never be as understandable as code with comments. This is true because code is designed partly for computers while comme
by newt0311 18y ago
I disagree. Code without comments will never be as understandable as code with comments.
This is true because code is designed partly for computers while comments can be written entirely for humans.
This is important because comments only have to be written once and maintained occasionally while code without comments has to be reinterpreted every time it is read.
- procyon 18y agoNot quite! I think code can be written to make it self explanatory. With appropriate variable, function names along with proper abstraction and refactoring code can be read almost like a prose which eliminates need for comments. At times comments are too annoying because they state the obvious or they are not updated along with the code. eg: code like this in ruby can explain itself very well! display_error if not valid_input Now I do understand that comments cannot be replaced entirely and sometimes it is necessary to add notes to understand the code thus I prefer using comments sparingly and avoid long headers on top of each file. Those headers with author name, dates and other information is unnecessary if right tools are used to maintain your project.
- bkudria 18y agoYou mean: display_error unless valid_input right?
- eru 18y agoWhy use more different language constructs in a post than necessary?
- xlnt 18y agoI don't like "unless". Why do you? Every time I have to actually think about what's happening, I change it to "if" so all the logic is actually written visibly.
- raganwald 18y agoI use "unless" in ordinary speech. Unless I'm talking with someone who dislikes the word.
- xlnt 18y agoI don't parse/think-about boolean logic like English.
- raganwald 18y agoThen you probably won't be happy with languages like Perl and Ruby, DSLs, or the "There is more than one way to do it" line of thinking some people have. It's a big world out here, there's room for Spock and for Kirk.
- xlnt 18y agoI love ruby, and use ruby at my job. I just don't write unless. Certainly there is no cause for someone to say a statement is mistaken just because it used if+not. Nor to guess that someone won't like ruby just because he doesn't like unless.
- raganwald 18y agoSaying someone is mistaken because they used "if not" instead of "unless" doesn't align with my understanding either, as I tried to point out by listing yet another way to write the same thing. OTOH, you made a much more interesting statement than simply saying you didn't like "unless," you took things into a discussion about programming languages resembling vs. not resembling English. Ruby has a bunch of lispy things that have nothing to do with English, but it also has a bunch of Perl-inspired things that have a lot to do with expressing logical ideas in English-y "prose." If you can reconcile those two things, then yeah, you'll like all of Ruby. If not, you'll probably find a subset that pleases you. So sure, I can see that you might like the Ruby you use.
- raganwald 18y agoRight. Unless he means: display_error if invalid_input
- comatose_kid 18y agoCode without comments is better than code with outdated comments - this happens quite frequently.
- ajross 18y agoAmen. Comments lie. This happens all the time. Programmers who try to maintain code by reference to the comments will get it wrong. You have to debug the code. Comments, at most, should be a guide to what happens where.
- axod 18y agoIt depends on how well you write your code. Also I think in general hackers should learn to read code. To reverse engineer. To understand what is going on without comments. Then when you do have some comments, it's a bonus (Or just even more confusing and contradictory).
- rw 18y agoYou can write a provable theorem as a stream of symbols from mathematical logic, instead of prose. But, do you really want to read the result? Code can be made clearer through abstraction, certainly, but comments are a domain specific language for helping humans understand computer programs.
- stcredzero 18y ago"This is true because code is designed partly for computers while comments can be written entirely for humans." There are differing degrees to which this is true. Different languages had different design motivations. Smalltalk was specifically designed to be readable by humans. By grade school aged humans, actually! In the Smalltalk community, most regard comments as a "Code Smell."