Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««23456»»»

Complicated Comments Expand / Collapse
Author
Message
Posted Wednesday, February 11, 2009 10:37 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Tuesday, December 7, 2010 12:55 AM
Points: 771, Visits: 504
Wow. I didn't see that coming. AND I learned something new! And that's always a good thing. :D
Post #655080
Posted Wednesday, February 11, 2009 10:46 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, February 4, 2011 7:20 AM
Points: 977, Visits: 1,499
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
Post #655092
Posted Wednesday, February 11, 2009 11:08 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, June 20, 2013 12:45 PM
Points: 262, Visits: 94
It's the best way to remember which code was in the original block.


I thought that is what version control is for?
Post #655115
Posted Wednesday, February 11, 2009 11:14 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, September 22, 2014 11:18 AM
Points: 305, 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
Post #655122
Posted Wednesday, February 11, 2009 11:27 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, February 4, 2011 7:20 AM
Points: 977, Visits: 1,499
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
Post #655129
Posted Wednesday, February 11, 2009 11:34 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Friday, September 12, 2014 4:57 PM
Points: 582, Visits: 453
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.
Post #655132
Posted Wednesday, February 11, 2009 11:45 AM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, March 27, 2009 10:01 AM
Points: 48, 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


Post #655142
Posted Wednesday, February 11, 2009 11:58 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, October 18, 2013 8:39 AM
Points: 1,219, Visits: 226
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.
Post #655151
Posted Wednesday, February 11, 2009 12:45 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 10:41 AM
Points: 809, Visits: 1,996
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.


ATB

Charles Kincaid

Post #655173
Posted Wednesday, February 11, 2009 1:09 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, February 4, 2011 7:20 AM
Points: 977, Visits: 1,499
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
Post #655187
« Prev Topic | Next Topic »

Add to briefcase «««23456»»»

Permissions Expand / Collapse