Monday, April 03, 2006
« Change template for "New Stored Procedur... | Main | RSS URL update »

I like studying other people’s code… when they know what they’re doing!  I’ve noticed that this is particularly helpful when I’m new to a technology.  The problem is that the code you’re studying may not be as good as you think it is.

Case in point: I was recently reading over anther programmer’s stored procedure.  At the end, I saw the line “select SCOPE_IDENTITY()”  Eh?  SCOPE_IDENTITY?  What is this?  Every example I’ve seen would have said “select @@identity”… come to find out, 99% of the time, this is the wrong way to do it.

Jeff Attwood recently posted on studying other people’s code:

You won't become a better programmer by passively studying other people's code. Similarly, you don't magically become a better writer by reading a lot of books. You become a better writer by.. wait for it.. writing.

I agree: unless you go through the motions of leveraging a technology yourself, you won’t completely understand it.  Until you actually do it, you don’t yet know what you don’t understand.  I also agree with Jeff’s next statement: “Studying code is reasonable advice. It's helpful.”

Absolutely!  After having done it yourself, it’s much easier to pick out the things that the other author did differently.  Finding these differences makes you find out ask which way is better.  This process enhances your ability to make choices in a given scenario.  It also makes you aware of in future code you write or review.

A quick search on Google ("http://www.google.com/search?ie=UTF-8&oe=UTF-8&sourceid=deskbar&q=@@identity+vs+SCOPE_IDENTITY")  revealed that this issue is not a new topic – but I wouldn’t known anything about it if I hadn’t taken some time to read through someone else’s code.

Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u)  

Enter the code shown (prevents robots):