SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Complicated Comments


Complicated Comments

Author
Message
KevinC.
KevinC.
SSC Eights!
SSC Eights! (881 reputation)SSC Eights! (881 reputation)SSC Eights! (881 reputation)SSC Eights! (881 reputation)SSC Eights! (881 reputation)SSC Eights! (881 reputation)SSC Eights! (881 reputation)SSC Eights! (881 reputation)

Group: General Forum Members
Points: 881 Visits: 504
Wow. I didn't see that coming. AND I learned something new! And that's always a good thing. BigGrin
Tom Garth
Tom Garth
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1993 Visits: 1499
Irish Flyer (2/11/2009)
Given the inconsistancies noted, I guess it brings home the point that one should be consistant in coding. Either use the -- convention to comment a line, or use /* */ pairs for comments, but don't mix them. Consistancy is just good coding practice anyway.


I'm pretty consistent about commenting out comment blocks (--/* and --*/). It's the best way to remember which code was in the original block.

Tom Garth
Vertical Solutions

"There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers

Myles Sigal
Myles Sigal
Old Hand
Old Hand (329 reputation)Old Hand (329 reputation)Old Hand (329 reputation)Old Hand (329 reputation)Old Hand (329 reputation)Old Hand (329 reputation)Old Hand (329 reputation)Old Hand (329 reputation)

Group: General Forum Members
Points: 329 Visits: 118
It's the best way to remember which code was in the original block.


I thought that is what version control is for?
Jesse McLain
Jesse McLain
Mr or Mrs. 500
Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)

Group: General Forum Members
Points: 565 Visits: 567
Here are a couple of articles related to this thread:

"Worst Practice - Bad Comments", By Andy Warren, 2003/01/23:
http://www.sqlservercentral.com/articles/Miscellaneous/worstpracticebadcomments/893/

"The case against using single-line comments", By Cade Bryant, 2003/01/22:
http://www.sqlservercentral.com/scripts/30672/

Jesse McLain
jesse@jessemclain.com
www.jessemclain.com
www.jessesql.blogspot.com
Tom Garth
Tom Garth
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1993 Visits: 1499
Myles Sigal (2/11/2009)
It's the best way to remember which code was in the original block.


I thought that is what version control is for?


Version control isn't needed when making temporary edits for effect.

Also - version control applications are not a good fit for every shop or project. Sometimes version control is whatever you are savvy enough to remember to update.

Tom Garth
Vertical Solutions

"There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers

Olga B
Olga B
SSC Eights!
SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)SSC Eights! (820 reputation)

Group: General Forum Members
Points: 820 Visits: 455
I got it right, but now I realize it was almost by accident.

Irish Flyer (2/11/2009)
Given the inconsistancies noted, I guess it brings home the point that one should be consistant in coding. Either use the -- convention to comment a line, or use /* */ pairs for comments, but don't mix them. Consistancy is just good coding practice anyway.


Good point. I tend to use the comments differently: -- to explain what (I think) the code is doing, /* */ to take out copies of code while I'm messing with it in development or to separate queries I use for testing. Most of the code in /* */ will get taken out in production.

As far as inline comments - I avoid them precisely for the reasons stated above. I do add them to large queries sometimes if I feel that parts of it need to be explained separately. Maybe I ought to exercise more caution in the future.
raymond lew
raymond lew
SSC Veteran
SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)

Group: General Forum Members
Points: 222 Visits: 123
I love using inline comments. Especially when hacking complex sql.

For example:
with something like this, I can switch things up using simple inline comments
select a
,b
-- ,c
,d
from taba
,tabb
-- ,tabc
,tabd
where 1=1
and blah-a
--and a = 9
and a = 18
--and a in(1,2,3,4,5)
and blan-b
--and blah-c
and blah-d
Irish Flyer
Irish Flyer
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1399 Visits: 240
The comments Jesse refers to above are right on point. The problem with Grasshopper's in-line comments example is that too often they get left in the code when it is placed in production. When I do code reviews (and yes, we actually do them), code with those types of comments would be rejected.
Charles Kincaid
Charles Kincaid
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3283 Visits: 2384
Let me see if I can show what is going on here and why. Lets number the lines

(00) PRINT '1' -- /* ;PRINT '2' */ ;PRINT '3' /*
(01) PRINT '4' --*/
(02) --/*
(03) PRINT '5'
(04) --*/
(05) /*
(06) PRINT '6'
(07) --/*
(08) */
(09) PRINT '7'
(10) --*/
(11) PRINT '8'


Line (00) has an inline comment starting with the double dash so 2 an 3 are in the comment
Same for (01) so 4 does print just like 1.
Line (02) has an inline comment so the block comment starter is par of the comment and is ignored. Same for (04) and (10).
Line (03) is not in any comment and gets executed. Same goes for line (11).
Line (05) starts a block comment. Lines (06) and (07) are part of the block comment.
Line (08) stops the block comment.

ATBCharles Kincaid
Tom Garth
Tom Garth
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1993 Visits: 1499
Charles,

Regarding line (10). That is the same incorrect assumption that most of us made. Line 10 is not ignored. The comment begin marker causes the parser to search from the bottom up for a comment end marker, and finds it on line (10).

Try this:


/*
Good comment.
--*/


Now my question is why isn't the following just as good.

/*
Good comment not.
--/**/


heh

Tom Garth
Vertical Solutions

"There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search