The Case of Better Readable Code

When you code, you write your programs either in all lower case, all upper case, or a combination of the two. Let’s take PL/SQL for example, almost all PL/SQL programming best practices and coding styles that I’ve come across recommend using upper and lower. The following is an excerpt from the book Oracle PL/SQL Best Practices By Steven Feuerstein:

PL/SQL code is made up of many different components: variables, form items, report fields, procedures, functions, loops, etc. All these fall into two major categories. Reserved words and program specific identifiers. Reserved words are those language elements that are used by PL/SQL. They have special meaning to the compiler and hence are reserved. Program specific identifiers are the names that a programmer gives to the various components of program such as variables, constants, procedures etc…

The PL/SQL compiler treats these two types of text very differently. You can improve the readability of the code greatly by reflecting this difference in the way the text is displayed.

To distinguish between reserved words and program specific identifiers, use of the upper and lowercase strategy is recommended. Use all UPPER case of reserved words and lower case of program specific identifiers. This increases the readability of the code.

Sure, this does increase the readability of the code. But, it sure does take extra time to think what words are reserved and what words are program specific identifiers and decide which case to use accordingly, upper or lower. Even if you know the reserved words by heart, it is still going to take you extra time to hit that Shift or the Caps Lock key every time you “switch context”.

So, unless you do not care about enhancing the readability of your code or you do not mind the extra time it takes to manually decide which case to use, I believe that an automated code formatter is an essential tool that every developer should have.

I use Quest SQL Navigator’s code formatter. It’s very powerful and has many formatting options:

Oracle SQL Developer also has a formatter, but it has far less formatting options than SQL Navigator. It is one area where Oracle SQL Developer needs improvement.


Possibly related:


Tagged , , , , , | Post a Comment