1. Computing

Discuss in my forum

Michael Morin

How Do You Use Comments in Your Code?

By , About.com GuideJuly 20, 2009

Follow me on:

Commenting your code is usually a way to provide some background to or explanation of complicated code, most often for another programmer who's looking it over. Ruby uses the sharp (#) as a way to identify the beginning of a a single-line comment and even though the interpreter for all practical purposes ignores the information on the line, anyone reading over the code should not.

Sometimes even if the code is comprehensible, it's worth taking a look at the comments merely for the amusement factor, because not everybody uses comments the same way. In fact, I've seen some pretty unusual things added to code as "comments" now and again. Do you use the comment line in the standard manner? Have you seen some odd comment lines in other people's code? We're collecting the answers, so share with us:

How Do You Comment Your Ruby Code?

Comments
July 20, 2009 at 2:04 pm
(1) Vlad Semenov says:

> Ruby uses the shebang (#!) as a way to identify the beginning of a a single-line comment

That’s false. Only sharp (#) is required to identify a single-line comment.

July 20, 2009 at 2:46 pm
(2) ruby says:

You’re absolutely right, of course. Thanks for pointing out the error. I’ve no idea what I was thinking when I wrote that and clearly wasn’t paying attention. Again, thanks.

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

©2013 About.com. All rights reserved.