Tag Archives: code

One Liners and Overengineering

Sometimes being a developer is hard work

And that is because you have to study and understand the code other people write. Now, this has many aspects in terms of understanding. There are many people who write code. Some of them are good at it, some are not. It all comes down to two categories in my opinion.

“I’m bored of this thing” people

These people  write code just enough to finish the feature. Not very descriptive code, just enough to get the job done, nothing more. Their variables are often misunderstood, they do not have the proper names or sometimes they have a twofold meaning. Something like:


$thisVariableMightContainAStringOrATraitedSuperObject

Their code structure nonetheless is pretty much the same like :


function addOrSubtract ($addOrSubtract, $firstOperand, $secondOperand)
{

if ($addOrSubtract == '+') {

  return $firstOperand + $secondOperand;

else {

  return $firstOperand - $secondOperand;

}

Their tests also are somehow like the above example. They tend to irrationally use the same structure, using the “feature” of loosely typed languages.

One Liners

Now these people I love. They are trying to do the same thing with the above people, only, they delve into it. They are bored also at first, but when they see that their code can be optimized, they are “one-lining-em”. They do not use the wrongly inferred type as the above people, and their code is “a mystery” yet “it gets the thing done” in one line. Supreme elegance in my opinion.

example :


[].forEach.call($$("*"),function(a){
a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16)
})

Now these One Liners are writing the best optimized code.

The above line was taken from this guy’s blog who explains the exact function of what it does. It is amazing how much you can learn by just one line of code.

What it does is to apply a single pixel outline to all the elements of a page, randomized with a different color. Simply paste the above line in your browser’s console and see what happens. The purpose of this line is to debug your css layout in the page.

If you have a look at the above page you will see that this line is taken from a simple gist and there are a lot of people who are suggesting revisions on how to write that single line.

I will conclude by saying that programming

is something that is quite complex at times. People who do it for a long period, tend to do the above things in order to “escape” the routine of writing plain code. Over-engineering and trying different things (in all the acceptable frameworks of programming, like optimization, maintainability, debug free code) is something that is being constantly done, to keep oneself from doing something different even if one does not have the capability of doing so.

What I mean is that, after you have seen all the technologies, you have used all the “regular path” ways of a construct, you are always trying to do something in a different – peculiar way so as to “escape” the straight-forward, more “boring”, more “effort consuming” way.

And believe me, I have seen this from many, many people that are indeed very good engineers.

After all, Lazy people make the best inventors…
Doing a thing as simple as touching one's left ear, could prove quite complex...
Doing a thing as simple as touching one’s left ear, could prove quite complex…

Parse Error PAAMAYIM NEKUDOTAYIM

Now I get it. PHP is a collective language created by multicultural people all over the world.

 

Well, ok. Which makes you think that all errors should be properly explained in a common language. Since we do not all speak the same language (apart from math that is) English is a good candidate.

Surely it is not Greek. Surely it is not Persian. And by any means its not Hebrew either.

Yet, this :

PAAMAYIM NEKUDOTAYIM

Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM

Okay. If you google it , turns out that PAAMAYIM NEKUDOTAYIM means double colon (::) in Hebrew.

Turns out that the two main guys who wrote the Zend Engine that translates PHP to executable code, were from Israel.

And after all those years this has somehow not changed. Which eventually will make your eyes bleed. Since it would be the same as writing: “Dipli Anw Kai Katw Teleia”