On formatting SQL code

  • I forgot to check: It works well enough from my mobile phone.

    Good work!!!

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

  • I vote for "allowing written SQL to reflect the person who originally wrote the code". That way, if the formatting looks like it was taken directly from the interior of one of the pyramids, you have a good visual clue that what the SQL is doing is most likely equally obtuse.

  • There's some pretty basic rules for formatting that I use that I guess I'm just so used to they don't add any overhead what I'm doing. But simple things like horizontal indenting as control flow structures get nested and always adding the close parenthesis/bracket/END statement as soon as the corresponding open is done shouldn't take any extra time and make everything easier.

  • If management measures developer productivity by the daily average number of lines coded and unit tested, then that obviously influences how aggressively you would use line breaks. 😎

    "Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho

  • Eric M Russell (3/29/2016)


    If management measures developer productivity by the daily average number of lines coded and unit tested, then that obviously influences how aggressively you would use line breaks market one's CV. 😎

    HTH

    I'm a DBA.
    I'm not paid to solve problems. I'm paid to prevent them.

  • andrew gothard (3/29/2016)


    Eric M Russell (3/29/2016)


    If management measures developer productivity by the daily average number of lines coded and unit tested, then that obviously influences how aggressively you would use line breaks market one's CV. 😎

    HTH

    If you're really cheeky, you can submit a purchase order for a SQL Auto Formatting plugin. When your boss asks why, tell him it's a productivity tool. 😛

    "Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho

  • Average number of years per opinion is interesting - link

  • Thanks for putting that together - I thought I saw the same thing just scanning the data, but it nice seeing the graphic.:-)

  • diamondgm (3/29/2016)


    Some of the dashboard items up on Power BI (no moving avg, sorry) - https://onedrive.live.com/redir?resid=4D0361FD49E9910!17469&authkey=!ADivg4tDQOAKccM&v=3&ithint=photo%2cPNG

    Thanks, that's great

    Tom

  • I always format my code.... I'm not a stickler about it, but to me it's just way easier to read that way.

    I tend to stick with mostly lowercase, with camel case for column names - what way SSRS automatically parses the names for reports. I use indents to identify sub-queries. I like to use new lines for each part of a statement; I like to line up my parenthesis, etc. Yeah, it takes a small amount longer to write code that way but I find it easier to work with later if I need to add or change something.

  • Formatting should be such that somebody with at least a minimal level of experience should be able to pick up and understand the pattern quickly. That could be highly structured (dictated by local rules) or a programmer's individual style - doesn't matter, as long as it is readable.

    I was a teaching assistant in college a {cough} few {cough} years ago for a PASCAL/Sociology class, and one semester it was taught by a Sociology professor (highly qualified to teach the programming part as his girlfriend was an Electrical Engineering professor). He explained the importance of indenting, but kind of awkwardly. One student turned in his program looking like a perfect sideways pyramid - he had indented two spaces per line of code until halfway down the program, then brought the following lines back in. Poor guy said it took him a half hour to make it symmetrical. The TAs ultimately took up the slack in the programming end. The sociological issues raised were kind of interesting, though.

  • Notepad ++ and the Poor Man's T-SQL Formatter. Change to use spaces instead of tabs. No one here has an excuse for trying to push ugly T-SQL.

Viewing 12 posts - 46 through 56 (of 56 total)

You must be logged in to reply to this topic. Login to reply