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.

2 thoughts on “It’s the Little Things: The PL/SQL NULL Statement, and why Every Language Should have One

  1. To me it looks more like a broken parser and it confuses people (e.g. https://stackoverflow.com/q/13172779/581205). The error message says nothing about empty blocks being prohibited and nobody really expects it.

    I could love a language prohibiting empty blocks, but I hate those providing no helpful syntax error messages.

    Writing things like

    if (somethingElse) ;

    is crazy, but a language should foremost make it easy to do the right thing and then prevent doing the wrong things. And for Java, there’s http://checkstyle.sourceforge.net/config_blocks.html#EmptyBlock
    and also EmptyCatchBlock.

    1. Error messages are a different story :-) We’ll have a piece coming up soon about how languages and language implementations are often too closely coupled, which heavily impairs the user experience…

Leave a Reply