Coding Standards

  • Hi,

    I don't need assistance today, but I have a comment. Why doesn't Microsoft use T-SQL coding standards?

    Whenever I script a system stored proc the code looks like a dogs breakfast. Surely MS should be leading by example.

    ...

    from sys.partitions p join sys.allocation_units a on p.partition_id = a.container_id

    left join sys.internal_tables it on p.object_id = it.object_id

    ...

    Cheers

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

  • Artoo22 (3/19/2012)


    ...

    Why doesn't Microsoft use T-SQL coding standards?

    ...

    Microsoft wants to show by example, that not using coding standards, ends up with great "dog's breakfast" :hehe:

    I wonder what kind of coding standards do You refer to? Are any industry-wide recognised standards available? What is ISO number for them?

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Artoo22 (3/19/2012)


    Hi,

    I don't need assistance today, but I have a comment. Why doesn't Microsoft use T-SQL coding standards?

    Whenever I script a system stored proc the code looks like a dogs breakfast. Surely MS should be leading by example.

    ...

    from sys.partitions p join sys.allocation_units a on p.partition_id = a.container_id

    left join sys.internal_tables it on p.object_id = it.object_id

    ...

    Cheers

    :unsure:

    http://en.wikipedia.org/wiki/SQL

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle

  • Whose standards? Everyone has their own idea of how code should be formatted. In some ways, I agree, it would be nice if the code for the Microsoft procedures were formatted better, it would make it easier to figure out what they are doing.

  • Except for the formatting, that code looks decent. If you want bad examples of TSQL from Microsoft you need to dig through the Books Online a little. There are several places where you can find poor TSQL examples.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Eugene Elutin (3/19/2012)


    Artoo22 (3/19/2012)


    ...

    Why doesn't Microsoft use T-SQL coding standards?

    ...

    Microsoft wants to show by example, that not using coding standards, ends up with great "dog's breakfast" :hehe:

    I wonder what kind of coding standards do You refer to? Are any industry-wide recognised standards available? What is ISO number for them?

    I know there are not industry-wide ISO recognised standards for SQL formatting, but most companies I have worked for have some sort of standard, while MS seems to have none.

    Henrico Bekker (3/19/2012)


    Artoo22 (3/19/2012)


    Hi,

    I don't need assistance today, but I have a comment. Why doesn't Microsoft use T-SQL coding standards?

    Whenever I script a system stored proc the code looks like a dogs breakfast. Surely MS should be leading by example.

    ...

    from sys.partitions p join sys.allocation_units a on p.partition_id = a.container_id

    left join sys.internal_tables it on p.object_id = it.object_id

    ...

    Cheers

    :unsure:

    http://en.wikipedia.org/wiki/SQL

    Your point being?

    Lynn Pettis (3/19/2012)


    ....In some ways, I agree, it would be nice if the code for the Microsoft procedures were formatted better, it would make it easier to figure out what they are doing.

    This is what I am referring to.

    Grant Fritchey (3/19/2012)


    Except for the formatting, that code looks decent. If you want bad examples of TSQL from Microsoft you need to dig through the Books Online a little. There are several places where you can find poor TSQL examples.

    I know it's decent code, that's why I "borrow" some from time to time, I'm just referring to formatting.

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

  • Our point is that everyone has their own standard.

    I worked with three other people at one company and each of us formatted code differently. Three of us had no problem reading each others code, the other, that was a different story.

    Not only that, one of the people would reformat our code to their standard when working on it.

    If you don't like how Microsofts code is formatted, use a code formater on it to change it.

  • Frankly, if I want to see code formatted my way, I just hit the CTL-K followed by CTL-Y.

    It's magic.[/url]

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • CELKO (3/19/2012)


    I wonder what kind of coding standards do You refer to? Are any industry-wide recognised standards available? What is ISO number for them?

    The ISO-11179 is one. MS also fails to use industry standards constantly in their examples.

    The best place to look for help is SEI and the decades of research on coding. I spent part of my career doing DoD research on this topic and wrote a book.

    ISO-11179 has nothing to do with code standards.

    It's standard for metadata representation.

    In my opinion, different naming conventions (eg. Hungarian notation) have more to do with coding standards than the above ISO.

    What I would call coding standards is something to do with the way you write your code, for example:

    - all language keywords in upper (lower) case

    - maximum length of code line

    - use comma at beginning of code line

    - use appropriate indentation (eg. use spaces for Tab)

    etc.

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Eugene Elutin (3/19/2012)


    CELKO (3/19/2012)


    I wonder what kind of coding standards do You refer to? Are any industry-wide recognised standards available? What is ISO number for them?

    The ISO-11179 is one. MS also fails to use industry standards constantly in their examples.

    The best place to look for help is SEI and the decades of research on coding. I spent part of my career doing DoD research on this topic and wrote a book.

    ISO-11179 has nothing to do with code standards.

    It's standard for metadata representation.

    In my opinion, different naming conventions (eg. Hungarian notation) have more to do with coding standards than the above ISO.

    What I would call coding standards is something to do with the way you write your code, for example:

    - all language keywords in upper (lower) case

    - maximum length of code line

    - use comma at beginning of code line

    - use appropriate indentation (eg. use spaces for Tab)

    etc.

    I agree.

    But, to be fair, there could be two (potentially more) definitions for coding standards. In this case, however, I do believe we are talking more sytle than metadata.

  • I think it comes down to more of what it is doing. When I ask the engine to generate a script for me, I don't "expect" any sort of format. I suppose it is not even the database engine that is doing this, but SSMS. So, how does SSMS know how to format it? I think it would be a waste to store tons of format data with an sp definition. The database engine doesn't care about the format, so why should SSMS? I guess I just don't see the utility in adding a more detailed formatting mechanism when it varies so much.

    Jared
    CE - Microsoft

  • CELKO (3/19/2012)


    Part of the University of Maryland and DoD research was the effect of formatting on maintaining code. Desktop programmers do not know or think about maintaining code but that is 89-90% of the lifetime cost of a system. As the largest user of software on Earth, DoD has been concerned about this stuff.

    We had "cowboy coders" that loved vendor features (did you know you can add letters in Burroughs COBOL? That IBM 1620 has a neat three-way IF? etc?). The problem was costing us hundreds of billions of dollars until we got the FIPS-127 standards and the FIPS flagger to warn about the cowboys.

    Then we looked at how this standardized code was being written.

    Bad formatting adds 8 to 12% more to the lifetime cost of a system. People cannot find bugs in visually difficult code. The original experiments were simple; add (n) bugs to a program and see how long it takes to find them. And yes, they often find only (n-k) of the bugs.

    The typography studies by newspapers and the US Printing office hold true for code (all uppercase stinks, you read in boumas, etc). Later we got good tools for eye movements (camelCase stinks, PascalCase is only a bit better because your eye jumps to uppercase letters as a cue; commas at the front of a line or keywords at the end of a line also cause eye twitches; etc)

    Again, all that research went into my book; Ii am not going to post an entire book.

    I don't understand what this has to do with system stored procedures being scripted out and preserving some type of formatting...

    I thought about this more, and realized that in addition to this being a generated script we are assuming that someone sat down and created these stored procedures in SQL. I don't know how these are developed, but my guess is that they are compiled along with the rest of the code when the software is created, not a bunch of SQL developers sitting down after the base software is created an they all type out SQL procedures. Maybe I am wrong.

    Jared
    CE - Microsoft

  • Jared, do me a favour please. Find sp_spaceused and modify it. What do you think? Good code laid out badly.

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

  • CELKO (3/19/2012)


    Part of the University of Maryland and DoD research was the effect of formatting on maintaining code. Desktop programmers do not know or think about maintaining code but that is 89-90% of the lifetime cost of a system. As the largest user of software on Earth, DoD has been concerned about this stuff.

    We had "cowboy coders" that loved vendor features (did you know you can add letters in Burroughs COBOL? That IBM 1620 has a neat three-way IF? etc?). The problem was costing us hundreds of billions of dollars until we got the FIPS-127 standards and the FIPS flagger to warn about the cowboys.

    Then we looked at how this standardized code was being written.

    Bad formatting adds 8 to 12% more to the lifetime cost of a system. People cannot find bugs in visually difficult code. The original experiments were simple; add (n) bugs to a program and see how long it takes to find them. And yes, they often find only (n-k) of the bugs.

    The typography studies by newspapers and the US Printing office hold true for code (all uppercase stinks, you read in boumas, etc). Later we got good tools for eye movements (camelCase stinks, PascalCase is only a bit better because your eye jumps to uppercase letters as a cue; commas at the front of a line or keywords at the end of a line also cause eye twitches; etc)

    Again, all that research went into my book; Ii am not going to post an entire book.

    Thanks Joe. Which of your books are you referring to?

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

  • Artoo22 (3/19/2012)


    Jared, do me a favour please. Find sp_spaceused and modify it. What do you think? Good code laid out badly.

    I understand what you mean by laid out badly. However, we are assuming it was ever laid out. These are system stored procs. Do you think a MS developer sat down and created these in an SSMS window and then executed them? Maybe, but my guess is no. These scripts are "generated."

    Jared
    CE - Microsoft

Viewing 15 posts - 1 through 15 (of 22 total)

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