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 12345»»»

Formatting and Readability Expand / Collapse
Author
Message
Posted Thursday, June 17, 2010 9:47 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, May 4, 2013 4:28 PM
Points: 1, Visits: 8
Comments posted to this topic are about the item Formatting and Readability
Post #939334
Posted Thursday, June 17, 2010 10:00 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Sunday, September 8, 2013 5:39 PM
Points: 263, Visits: 862
I think you can extend this ever further by saying you should take pride in your work. Good formatting and readability is just part of that. Besides, everyone is replaceable. Crafting pristine or sloppy code won't change that fact.


James Stover, McDBA
Post #939336
Posted Thursday, June 17, 2010 11:18 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, July 29, 2014 4:04 PM
Points: 204, Visits: 469
Its such an easy thing to do, but until you go start trying to maintain code that is poorly written, you'll never really understand WHY you should lay everything out nicely.

There are a number of tools on the market (or alternatively you could learn how to set Management Studio up properly) which will refactor your code, so basically I believe there's no excuse for poorly indented/laid out code.

I think every programmer should spend at least a year on maintenance prior to being allowed near a greenfields development!
Post #939357
Posted Thursday, June 17, 2010 11:48 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 1:05 AM
Points: 1,904, Visits: 2,842
Fully agree.
Bad formatting is almost as ugly as bad coding. When handing over your code/work you should
feel confident that any developer can look at it and be able to read/understand it.

I'm not saying it must be pretty, and spend more time on the looks rather than the functionality, but be proud of your work, not ashamed, and fear that it will come back to you because no one can read it.



----------------------------------------------
Msg 8134, Level 16, State 1, Line 1
Divide by zero error encountered.
Post #939371
Posted Friday, June 18, 2010 1:48 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: Yesterday @ 4:21 AM
Points: 561, Visits: 1,168
It's easy to do and only those with no drive or ambition make themselves indispensable - who wants to be slogging away with the same old code in 5 or 10 years time??
Post #939399
Posted Friday, June 18, 2010 1:49 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 5:42 AM
Points: 13,563, Visits: 10,440
I couldn't agree more.
Sometimes the analyst gives me some unformatted SQL code generated by a Build Query editor in SSIS.
The first thing I do is format the whole thing. While I do this, I read the code which helps to understand it better.

All my code is neatly formatted. This is extremely useful for debugging and maintenance, but also when you are explaining your code to someone else.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #939400
Posted Friday, June 18, 2010 2:01 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, October 2, 2012 6:14 AM
Points: 4, Visits: 53
One of my colleagues just tested SQL Prompt, it adds a button "Format code". So the formatting is done automatically according to default or custom rules. I used to do formatting by hand, but I'm considering moving to this tool, because it will save a lot of time.
Post #939409
Posted Friday, June 18, 2010 2:04 AM
SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Today @ 4:02 AM
Points: 108, Visits: 220
I have had to spend hours re-formatting badly set out code to make it readable before I even stand a chance of understanding what it does. Some of it I had written when I was less experienced.

So, please, set you code out neatly and comment it thoroughly. You will save yourself and others a lot of work in the future. Or do you want to get phone calls on holiday from junior programmers who are pulling their hair out trying to understand your code?
Post #939410
Posted Friday, June 18, 2010 2:12 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, June 3, 2014 8:16 AM
Points: 295, Visits: 1,011
Interesting that you'd bring this up. Often when I see bad sql code it's done by someone who never took the time to learn sql but focuses on vb/ java/ c or c#. There it's more common with bad coding standards I'd say from my experience. What do you think?
I also think it's more common with this type of code from people who wants to have fun more then having fun while taking pride in doing it proper. Often the later also makes faster code as a side bonus.

I changed a sql script from taking 3 hours down to 40 seconds. That was such a person. And guess what, cursor was involved, but the time consuming part was not the cursor but how the select statements were made.
Post #939416
Posted Friday, June 18, 2010 2:12 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, October 2, 2012 6:14 AM
Points: 4, Visits: 53
Oh, I just discovered there is more than one.
See this Stack Overflow question for a comprehensive list of SQL formatting helper tools.
Post #939417
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse