Empty statements

April 10, 2024

Empty statements

The empty statement does nothing.

EmptyStmt = .

I don’t think there’s much to say here. I suppose we could spend some time debating if/when an empty statement exists in our code. How many empty statements in the following?

Is it one? Zero? An infinite number?

How many “nothings” does this code do?

I can honestly say I’m not sure why “the empty statement” is even defined. It’s only mentioned four other times in the spec, once as one of the possible components of a simple statement:

SimpleStmt = EmptyStmt | ExpressionStmt | SendStmt | IncDecStmt | Assignment | ShortVarDecl .

And then three other times, in contexts similar to the one mentioned yesterday, where it’s mentioned in the context of “the last non-empty statement” in a list.

All in all, it seems this concept could have been left out of the spec without any ill effect. 🤷

In any case, you don’t really need to concern yourself with the empty statement. You’ll never use one. Or you’ll always use a countless number of them. I don’t know. It doesn’t matter. LOL

Quotes from The Go Programming Language Specification Language version go1.22 (Feb 6, 2024)


Share this

Direct to your inbox, daily. I respect your privacy .

Unsure? Browse the archive .

Get daily content like this in your inbox!

Subscribe