~ 1 min read

Concise Code - Where to Draw Readability and Obscurity Line?

I have recently found myself writing this code and I wondered, should I be writing such code at all? Is it too obscure?

return (tokens!= null && tokens.length >=1 && tokens[0].compareToIgnoreCase("NIL") != 0) ? tokens[0] : null;

It is pretty straightforward but it will require some mental power to process this code.

It is a often advocated that the code should be self documenting and I think it indeed should. Some thinkg only hacks and edge cases have to be documented but I still think placing notes in the strategic places in the code saying in a few words (few here means literally 3 to 5 words) what this piece of code does/is supposed to do.

Developers often take pride in complex and obscure code. This is, I guess some sort of narcissism in a shape of saying "I am so smart" instead of "I am so pretty". Let's call this the "Narcissistic code complexity syndrome"

Many times I do prefer writing such code however because I like the conciseness of it. Maybe I am deluding myself and I actually am a victim of narcissistic code complexity syndrom?

Let me know in the comments.