Code is not code

Code is language

Code is something you can see and read but can't understand. The whole point is to hide its real meaning in plain sight. It is coded. Code, that we use in programming is not hidden. You can read it, you can understand it, you can extend it. What we refer to as code is just a language.

A year into working as a programmer, I was deeply into optimization. I would spend hours on a program, optimizing it to the max even if it was to shave off a micro second. If you use JavaScript, then you know that performance is important. Interpreted code is slow by nature, but add to it the layer of the browser, the DOM, and under powered devices and it becomes even slower.

It is important to make sure the code you write in JavaScript is optimized to run as fast as possible in any given environment. And since the browser is tied to the internet, making sure your file is small makes it download faster. As a result, I started writing smaller files. Smaller not because they were better but because, who needs those long variable names anyway?

So this code:

(function(){
    var spans = document.getElementsByTagName("span"),
    titles = [];
    for(var i = 0;i<spans.length;i++){
        if (spans[i].className === "title"){
            titles.push(spans[i]);
        }
    }
    for(var i = 0;i<titles.length;i++){
        titles[i].onclick = function(){
            window.location.href = "#"+this.getAttributes("data-id");
        };
    }
})();

Becomes this (not recommended):

!function(d,u,s,r){
    var a = d.getElementsByTagName(s),t = [],i,l = a.length;
    for(i = 0;i<l;i++){
        (a[i].className === u)?t.push(a[i]):0;
    }
    l=t.length;
    for(i = 0;i<l;i++){
        t[i].onclick = function(){d.location.href = "#"+this.getAttributes(r);};
    }
}(document,"title","span","data-id");

The bottom one is shorter but very hard to read. It is the typical definition of code: it is obscure, not everyone can read it, but the compiler goes through it like butter.

The top one is much easier to maintain by humans. It is its own documentation without the need of comments. This is what programming languages are supposed to be, languages. They are easy to understand by both humans and computers. The code we write in our programs are the equivalent of words in the English language. Each word has a meaning, each sentence is a statement and all put together they describe instructions for the computer.

Cryptographers produce code. As coders, we write instructions in a language that both human and machine can understand.


Comments

There are no comments added yet.

Let's hear your thoughts

For my eyes only