SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Formatting and Readability


Formatting and Readability

Author
Message
UncleOllie
UncleOllie
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 38
Comments posted to this topic are about the item Formatting and Readability
James Stover
James Stover
Mr or Mrs. 500
Mr or Mrs. 500 (509 reputation)Mr or Mrs. 500 (509 reputation)Mr or Mrs. 500 (509 reputation)Mr or Mrs. 500 (509 reputation)Mr or Mrs. 500 (509 reputation)Mr or Mrs. 500 (509 reputation)Mr or Mrs. 500 (509 reputation)Mr or Mrs. 500 (509 reputation)

Group: General Forum Members
Points: 509 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

niall.baird
niall.baird
SSC-Addicted
SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)

Group: General Forum Members
Points: 428 Visits: 484
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!
Henrico Bekker
Henrico Bekker
SSCarpal Tunnel
SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)

Group: General Forum Members
Points: 4528 Visits: 4661
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.
P Jones
P Jones
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1635 Visits: 1517
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??
Koen Verbeeck
Koen Verbeeck
SSC-Dedicated
SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)

Group: General Forum Members
Points: 34237 Visits: 13270
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?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
antiflu
antiflu
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 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.
Alex Gay
Alex Gay
SSChasing Mays
SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)

Group: General Forum Members
Points: 641 Visits: 474
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?
IceDread
IceDread
SSChasing Mays
SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)SSChasing Mays (627 reputation)

Group: General Forum Members
Points: 627 Visits: 1145
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.
antiflu
antiflu
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 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.
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