Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Challenge Yourself


Challenge Yourself

Author
Message
Jasmine D. Adamson
Jasmine D. Adamson
SSC Veteran
SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)

Group: General Forum Members
Points: 284 Visits: 140
Naw, I think in SQL just fine. Steve mentioned business rules and that is another good thing to comment, but that's part of documentation, not explanation of the code. It's pretty important to document why you did something especially if you did it in an unorthodox way.
Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: Administrators
Points: 35976 Visits: 18726
But only if it's not obvious. Don't want to read comments about "used a left join because we have missing rows"

Use something like "some orders don't have a shipper, so left joined with Shippers table"

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Mal D
Mal D
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 1

I suppose in comment on the reason for this post is to 'Challenge Yourself'.  Not only in those things we thought we knew, as software changes and evolves, maybe some idioms are no longer valid.  I've been using SQL Server since Sybase was sucked up into the MS stable and there are still more things to learn (Thankfully !).   I thought that I knew dates but Itzik Ben-Gan's articles on Datetime calculation were a cool breeze throught the dusty portions of my briefcase.   So I suppose the challange is being open and prepared to be challanged.   and for those wondering ....

Last Monday (inclusive)
SELECT DATEADD(day, DATEDIFF
(day, 0, -- Base Monday date
GETDATE()) /7*7, 0); -- Base Monday date.

Pure genius....

CodeOn


Ian Brown-213389
Ian Brown-213389
Valued Member
Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)

Group: General Forum Members
Points: 71 Visits: 715
I've always thought that comments were a description of what you intended the code to do. You don't get this info by reading the code - you just get what the code actually does.

There is no problem so great that it can not be solved by caffeine and chocolate.
Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: Administrators
Points: 35976 Visits: 18726
Hopefully they're the same thing

I think that most comments are what you intend the code to do, but not explaining what a knowledgable person should be able to decipher. There should only be comments on something that's not obvious.

Or I sometimes make comments on a change in behavior as a reminder to myself or someone that comes along later.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Ian Brown-213389
Ian Brown-213389
Valued Member
Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)

Group: General Forum Members
Points: 71 Visits: 715
Yep, the comments should be fairly a high-level description of the coder's intent.

If the two don't match then the reviewer has to ask questions...

There is no problem so great that it can not be solved by caffeine and chocolate.
Glenn Dorling
Glenn Dorling
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2835 Visits: 918
In longer procs/scripts I'll add "section breaks", sort of very high-level pseudo-code, to help me quickly identify what a section of code does (or is meant to do). I find that really helpful if/when I have to revisit something months after I last looked at it.
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