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 «««1234

Writing Maintainable Code Expand / Collapse
Author
Message
Posted Tuesday, August 7, 2007 1:39 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, June 20, 2013 3:00 AM
Points: 1, Visits: 9

I also agree, that you must write SQL code maintainable. But NOT on the way they describe in this article. If you check VB.NET or C# developers, they all write in good maintainable code. If they use SQL, then it is an disaster. I have some good samples:

When you use columns in a select statement, place the comma at firtst. Now you can easely comment a column:

SELECT        ColumnA

           ,      ColumnB

 --        ,      ColumnC

FROM           TABLE1                               WITH (NOLOCK)

WHERE          STATEMENT1              =      @p_PARAMETER

AND              STATEMENT2              =      @l_PARAMETER     

I also places all columnnames on the same place and all signs and parameters. Now you can easily read the code.

Post #388405
Posted Tuesday, August 7, 2007 5:06 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 10:47 AM
Points: 35,347, Visits: 31,882
Curious... if you like the way it's done in .Net or C#, why didn't you do it that way?

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #388458
Posted Tuesday, August 7, 2007 6:17 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, November 12, 2007 6:32 AM
Points: 62, Visits: 3

>>If you check VB.NET or C# developers, they all write in good maintainable code

Being a .NET developer I can safely say that they do not all write in good maintainable code.

Post #388482
Posted Tuesday, August 7, 2007 7:37 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, October 17, 2014 1:59 PM
Points: 262, Visits: 918
WHERE SvcTypeID IN (1, --Standalone Long Distance
2, --800 Service
3, --800 Pin
5, --Calling Card
1801 --Bundled Services
)

whether this is commented "properly" or not, I ask why these values are not in a table. I know the knee-jerk response is that it's easier/faster to use this construct, but how often has easier/faster for the developer been the long term growth solution? If these values do not exist in a control table, why not? If they ARE, then why is the developer hard-coding this list of services into the procedure? In an article on maintainable SQL, I would have expected hard-coding to be absolutely forbidden.
Post #388530
Posted Tuesday, August 7, 2007 7:50 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, November 15, 2010 9:15 AM
Points: 158, Visits: 15

Just weighing in...  good points in the article...  I think some comments have their place, for example when you do something strange in the code for a good reason.  An example I used recently is I had to create an in-line query that was nested twice.  It was very unpleasant but it did the job.  I commented it carefully so that developers who had to maintain the code could understand the thought process and why it was done like that. 

My only pet-peeve regarding comments is when developers comment out reams of code and LEAVE IT IN THE PROGRAM.  Trying to read and decipher that is a difficult task.  It is even more pointless if you are using a version maintenance tool, such as SourceSafe.  Just remove it, add a comment if you must indicating that code was removed and refer to SourceSafe.  When I have to maintain a new program, I do 2 things, one is add whitespace, as article author indicated, and two is delete commented out code. 

MikeZane

 




Post #388536
Posted Tuesday, August 7, 2007 5:50 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 10:47 AM
Points: 35,347, Visits: 31,882

Heh... I asked the same thing... and the answer is... crappola 3rd party software. 

So, Mike, you never hardcode anything?



--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #388770
Posted Wednesday, August 8, 2007 11:59 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, October 17, 2014 1:59 PM
Points: 262, Visits: 918
nearly never. Absolutely never in a public example of maintainable code.

I forced myself to develop a habit of taking the minor pain up front to set up and use the DB for data rather than the major pain returning to the project months later and having to figure things out.
Post #389018
Posted Wednesday, August 8, 2007 6:12 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 10:47 AM
Points: 35,347, Visits: 31,882
That's actually a pretty good plan and I agree with that... nice to see someone to spend a little time up front to save wads later on.

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #389093
« Prev Topic | Next Topic »

Add to briefcase «««1234

Permissions Expand / Collapse