Syntax Intuitiveness aka IQ Test

A simple and real world lesson on programming language syntax intuitiveness.

Introduction

As a polyglot I have coded with dozens of languages, ranging from Lisp and Forth to ML and Java and even Ruby (yes, I confess!). I have seen many programming constructs and syntaxes that hardly anything surprises me (beyond Javascript). Most of the times I can somehow understand a code that is written in a language that I do not know (like Haskell). However, to put an end to my arrogance, the gods pushed me in a direction to see something such non-intuitive and mysterious that made me search the web to just roughly understand what it does.

The Puzzle

I was reading a piece of C++ (the almighty!) code and stumbled upon a line like below:
int main() {
  //...
  aName otherName(...);
  //...
}
I tried to make sense out of line 3; I tried hard but got nowhere. "What on earth is that? Looks like a method definition but it's not....um...um...um...what the...!?"
A search for aName in the source tree made things a bit less obscure:
typedef std::unique_ptr aName;
It seemed some kind of pointer magic was going on but I still couldn't understand the mysterious line 3! By the gods...it looked like a method definition that returns aName type but it was not!
Finally, disappointed by my intuition and creativity, I searched the net to seek the wisdom. The answer was far far away from my expectation. Line 3 is a variable declaration, for gods' sake!. It defines the variable otherName of type aName and initialises it with whatever goes between the parenthesis! Yes! My wildest hunches were not even close.
It's in the C++ 11 standard and is called Smart Pointer; Guess why!? You have to be smart to understand the syntax! Kudos to the C++ ISO committee.

The Lesson

I thought standards and language revisions are there to make the language more intuitive and simpler; I was wrong.

Image source: themarkcryan.com

Comments

Popular posts from this blog

Variables in GNU Make: Simple and Recursive

Checkmate on Your Terms: A Personal Journey with Correspondence Chess

Firefox profiles: Quickly replicate your settings to any machine