Empty code blocks


Jason McCreary shared this code example back in 2018. He commented that the do nothing block was dead code, and you should start the if statement at the second block:

if (env('APP_ENV') == 'development') {
    // do nothing...
} else {
    if ($request->getScheme() != 'https') {
        // process request...

My first instinct is to disagree. This is a form of inline documentation, and a reminder that something can be done there, both of which are useful if you’re working in a team. It’s also scaffolding that gives you space to add functionality later. But then again, your code would double in size if every conditional was treated this way.

I’d say it’s useful if the do nothing comment constituted something meaningful, like a task manager ticket number, a summary of the desired feature, a #TODO or other programming tag, or a link for more information. Otherwise it’s probably wasted space.

Author bio and support


Ruben Schade is a technical writer and infrastructure architect in Sydney, Australia who refers to himself in the third person. Hi!

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite bespoke cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or send a comment. Thanks ☺️.