It’s the Little Things: The PL/SQL NULL Statement, and why Every Language Should have One
Syntax is one of those topics. One of those emotional topics that lead to very very very important discussions. I personally like PL/SQL. It is extremely verbose, and precise. It forces you to adhere to a very strong and rigid type system, slowing you down, which is likely to help you avoid mistakes.
There is one thing in PL/SQL that I like in particular. There is no such thing as an empty block.
While in Java, you could write:
// Just an empty block: {} // An empty block with a label: label1: {} // Or, in fact, the empty statement: ; label2: ;
The problem with the above from a mere syntactic perspective is that an empty block may have been left unintentionally empty. An empty statement may not even be visible at all. Consider this in the context of an if statement:
if (something) { } if (somethingElse) ;
In PL/SQL, this isn’t possible. There is no such thing as an empty block. The following doesn’t compile:
BEGIN END;
Nope:
ORA-06550: line 2, column 1: PLS-00103: Encountered the symbol "END" when expecting ...
Or, take the IF
statement. No emptiness allowed here, either:
IF 1 = 1 THEN END IF;
Doesn’t work.
If you DO want to create empty blocks (e.g. as placeholders for code you’ll write later on), you’ll have to explicitly put a dummy statement there. PL/SQL has such a statement. The NULL
statement:
BEGIN NULL; END; IF 1 = 1 THEN NULL; END IF;
That makes sense. You immediately see: OK, nothing going on here.
Conclusion
Verbosity helps decrease the number of bugs in your code. The less people can be concerned with syntax (see again, the discussion about very very very important topics), the more they can focus on what they really intend to write. Let’s swallow our pride. When we get used to a language, we’ll accept ANY language. They’re all flawed and quirky. It doesn’t matter. But at least, the language should keep us from arguing about different ways to style it.
Now, let me go reformat all that moron’s lower-case PL/SQL code. Who the hell would write lower-case begin
and end
!??
Reference: | It’s the Little Things: The PL/SQL NULL Statement, and why Every Language Should have One from our JCG partner Lukas Eder at the JAVA, SQL, AND JOOQ blog. |