Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Begin and End in If statements

Status
Not open for further replies.

SQLSister

Programmer
Joined
Jun 18, 2002
Messages
7,292
Location
US
After a miserable afternoon spent debugging the code another developer wrote, but didn't have a chance to test at all before he left the company, I am forcibly reminded of the need to always put a begin and end in every if statement even if there is only one line after the if. This silly thing has 42 if statements spread out over stored procedure that is over 12 printed pages long. (It also has 27 input variables, Ugh, Ugh, Ugh! Testing hell!)

Some of these statements have begin and end and some do not, but the spacing doesn't indicate to me whether they next two lines or so should also be in the if or not (given what the statemetns are trying to do, it could go either way, although including them makes more sense to me). I haven't gotten past the pure typing errors and mismatches between the variable data types and the data that actually will be supplied to really see the effect of leaving the block off would have since it never gets to the point of actually building the dynamic sql statement and running it.

At least if he had consistently put in the begin and end statements, I would know which path he intended to follow. It's also easier to maintain the code if later on you need to go from one to more lines (really easy to forget to do this when changing an if statement becasue you expect them to be there.

Sorry for the rant, just needed to vent and wanted to remind everyone to think about their coding practices since they may not be the person who ultimately has to deal with their code.
 
Amen Sister.
 
As a follow up, are there SQL formatters commercially available to help deal with these messes? What about an industry standard style guide?
 
It also helps to put comments in your scripts to document what each portion is supposed to do.

-SQLBill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top