You are here: Home / Blogs / Syntax Intuitiveness aka IQ Test

Syntax Intuitiveness aka IQ Test

A simple and real world lesson on programming language syntax intuitiveness

Confused LooksIntroduction

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 the...!?"

A search for aName in the source tree made things a bit less obscure:

typedef std::unique_ptr<SomeType> aName;

It seemed some kind of pointer magic was going on but I still couldn't understand the mysterious line 3! By the 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:

Filed under: ,
Anonymous says:
Jul 07, 2015 07:08 AM

that has nothing with C++11. it's just basic class instance creation with usage of constructor. and code like that exist in C++ from day zero.

Add comment

You can add a comment by filling out the form below. Plain text formatting. Comments are moderated.

Question: What is 1 + 4 - 1 ?
Your answer: