aspose file tools*
The moose likes Cattle Drive and the fly likes Does a reader carry an Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Does a reader carry an "if" into a comment?" Watch "Does a reader carry an "if" into a comment?" New topic
Author

Does a reader carry an "if" into a comment?

Jamie Cole
Ranch Hand

Joined: Feb 03, 2000
Posts: 36
Here's an example of a line of code with comment:
if ( number <= 19 ) // print the entry . . .
Would this normally be read as "if the number is less than or equal to 19, print the entry . . ."? In other words, would the reader understand that the action expressed in the comment is something that will be done if the "if" is satisfied?
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
I'd say YES. Although remember that the comments are as good as the programmer writes them and are not checked by the compiler for accuracy
[This message has been edited by Tony Alicea (edited February 04, 2000).]


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20692
    ∞

How about


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
or even:

In my opinion the aim of every programmer should be to make the actual code as close to a direct expression of intent as possible. Given that the code actually works, all other issues are secondary. In this case I'd also use a better variable name than "number" which is almost meaningless, and give some sort of name to the "19". I can't tell from your example what your intent is, so I can't help you to find better names.
By all means use comments where you really need them (to explain non-obvious algorithm or performance issues, to indicate why you chose to do somthing a particular way, and so on) but only after you have tried your very best with the actual code.
Remember, comments can lie, so you should be vary wary of them.
If you really want to have the example code as listed, I'd probably try to capture intent with a comment before the block


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
 
subject: Does a reader carry an "if" into a comment?