DISQUS

Eddie Awad’s Blog: The Case of Better Readable Code

  • David Aldridge · 2 years ago

    I'm a fan of init caps - there's a reason why directions signs on freeways/motorways don't use all lower case or (worse still) upper case letters, and it's because the human brain is better as interpreting when you give more visual clues to the words.


    eg. from easiest to read to hardest ...


    Exec DBMS_Stats.Gather_System_Stats


    exec dbms_stats.gather_system_stats


    EXEC DBMS_STATS.GATHER_SYSTEM_STATS


    Mind you, it drives other people crazy, but that's just another advantage for me :)

  • John Flack · 2 years ago

    That's a good argument for automated code formatting, Dave. I can reformat your code to look the way that I find most readable. Eddie - I use the code formatter that comes with TOAD - looks like it is the same one you use with SQL Navigator - interesting, but not surprising - both tools are from Quest.

  • Eddie Awad · 2 years ago

    because the human brain is better as interpreting when you give more visual clues to the words



    Exactly. Another example:


    <ol>
    <li>select employee_id from employees</li>
    <li>Select Employee_Id From Employees</li>
    <li>SELECT employee_id FROM employees</li>
    </ol>

    I believe that number 3 is the easiest to read. There is a visual clue that SELECT and FROM are reserved words.



    both tools are from Quest



    Right. I'm not surprised either that they use the same formatter.

  • David Aldridge · 2 years ago

    Personally, and this is very much IMHO, I don't get the reserved word thing. The list changes with each release and with each product (SQL, SQL*Plus, PL/SQL) and if one is supposed to recognise them well enough to capitalise them then the capitalisation ought to be regarded as redundant.


    IMHO

  • William Robertson · 2 years ago

    I'm with Eddie: "Select * From" is to my particular brain cluttered, twee and unreadable. I would sooner see all-lowercase, or else (as I do) routinely go through PL/SQL Developer's .kwf files adding words like COLLECT and NTILE so they show up properly.


    Although I do use code formatters, my problem with them is that the default settings do criminally insane things like right-aligning SQL keywords, and they can't seem to do fairly obvious things like starting a new line for a subquery.

  • jared · 2 years ago

    I'm with David on this.


    With SQL, if it is not in quotes, I write it lower case. The exceptions are when I pass the code through a formatter.


    If I happen to be writing PL/SQL that is to be of any consequence, I may name my variable with init cap on each word, with the initial character in lower case.
    eg. thisIsMyVariableName


    If it is some really serious PL/SQL (more than a 100 lines or so ) the variables will probably be prefixed with character to indicate the data type.


    eg. dThisIsADateVariable

  • Eddie Awad · 2 years ago

    The point I'm getting here is that you can never expect everyone to like the same coding format that you like and vice versa. This makes the need to enforce code styling and formatting standards (among team members) even stronger.