Sunday, November 15, 2009

The Criminal Coder

Mr. Reader, in case you have read my previous posts (in case, is the key phrase here), you might be by now thinking me to have lost my psyche. How can I, the ubiquitous attorney of coders on this planet (and Mars) call them evil? Well, to clear out doubts, they are criminals when compared to their superiors (read developers).

How can anyone deglamorise the developer by comparing him with a coder? To me coders are beginners, not absolute beginners, but people who know stuffs, but simply skip to do them, the way it is meant to be done, for laziness or for reasons I fail to understand. It’s not the lack of intellectual capacity that causes them to commit mistakes (read crime), its rather their sluggishness, that makes them do what they want to do, even if that brings about compromise in terms of the code they inject to dilute (read pollute) the system.

The following are some snippets from production code(basic changes made to trim the demo) that I have encountered, in this short span of life (read professional life), and when debugging performance problems in applications, stumbled upon them, and literally felt like giving digital life imprisonment to those who had the audacity to commit these bits!

  • Object declarations inside loops: For simple objects I sometimes feel it’s unavoidable to declare objects of types inside a loop, but for complex types, it’s simply a crime. The following code was intended to improve the performance of the application by spawning new threads. Don’t find the need to say more, the code is self explanatory (and yes, gives a boost to performance):

    public  void UploadXML()
    DataTable dt = GetDataTableFromXML();
    for(int i=0; i<dt.Rows.Count; i++)
    Thread th = new Thread(…);
    Guess what will be the first problem that your app may run into? An OutOfMemoryException.

  • Unacceptable usage of If construct: The code is overly expressive of my intent.

    for(int i=0; i<1000; i++)
    //Do something here

  • Overly expressive logic: I didn’t have the courage to congratulate this guy and kept shut even after seeing this. There were 10 checkboxes in the page and all of them had this. All of them!

    //As if Checked return a float
    bool b = (checkBox.Checked==true? true: false);
    And I have seen even experienced guys do a

    on a string. What more do you expect from visual studio? Auto-detect these overly expressive conversions? Surely, it would do so, may be in VS 2014!

  • Global declarations in methods: Why not lazy declare and initialize at the point of usage? We are not in the C age any more (or are we?).

    public void Foo()
    int a, b, c, d;
    //50 LOC before using c and d

  • Avoiding short circuits: Short circuits were provided in the language for some reasons, why not use them to decrease the number of characters typed and let the compiler expand them?

    bool a = false;
    bool b = true;

    //do something with b here
    if(a ==false)
    //this is left blank (and yes, intentionally)
    if(b == true)
    //Some code to execute
    //Again left blank (intentionally ofcourse)
    Why is the following so uncommon to write amongst few geniuses (strict pun intended)?

    if(a == true && b==true)
    //Some code to execute

    I know you might be thinking who on earth will follow the above pattern and dilute the code, but I have seen it far too many places to avoid mentioning it. Fact is, some coders simply forget the fact that an if can stay without an else. There are innumerable examples and I will certainly update this post to show some really valid places for short circuits, which were completely skipped (and did i mention, knowingly?).

The above list can’t ever be exhaustive, since each coder has his own pattern of seeing the code. At times I tend to give them (the coders) some leniency by considering their experience with a particular language, but most times, it’s just unacceptable and unforgiveable.

The following is a beautiful extract about the types of competence (or incompetence) that we encounter:
  • Unconscious incompetence: You don’t know what you don’t know.
  • Conscious incompetence: You know what you don’t know.
  • Conscious competence: You know how to do it, but you have to think your way through it.
  • Unconscious competence: You can do it without thinking. You just know what to do.

By the way, the reason I termed the above as crime, was because all those coders had live code at their disposal while adding these bits. They simply ignored the style of existing code used in the application and were arrogant enough to not tilt from their style of coding.

To me, that is simply unacceptable and unforgivable crime!

Hail Visual Studio! Save us from the criminal coders!

Sunday, November 8, 2009

The agonizing SME developer

Before you begin to think too much into SME, let me sync you up by expanding it for you to the Small & Medium Enterprise (SME). To me these enterprises are a source of raw mystery. When hiring or making decisions up front they are humble to use the latter portion of the acronym (considering themselves no less to Google or MS), and while sharing rewards and parting with their stuffs, the former part is acknowledged (the financial stability is, as they say, on the rocks, literally and did I mention, always).

An interesting find about the word "agony" is that it not only covers intense physical pain but also the "mental anguish" associated with or without it. Through recursion, I soon found out that anguish leads to extreme anxiety or emotional torment. Emotions, almost always, shell themselves into passions, which by the way, is the root cause of misery of all software developers on planet Earth and Mars (they, the guys at NASA, have been shouting all along that life exists at Mars and if life exists, you bet, software developers exist too). So what has a naïve SME developer got to do with agony? Well, at the lowest permissible degree, they were married, in time and space, forever and ever and ever (infinite loop begins, statement truncated).

The lifecycle of an agonized SME developer is what follows…

the morning
A beautiful day begins with a beautiful morning, and this, surprisingly doesn’t hold good any more for the SME dev. Unlike any other professional, the first thought that crosses his (not intending to be gender biased, it’s just natural, you see, it could have been her as well, instead of his) mind is: what can go wrong today, it’s such a beautiful day? Little does he know, that for no fault of his (yes, almost always, there is no fault of his directly, and I am being subjective here) the day will turn out to be, to say the least, bewildering!

the journey to the castle
Notwithstanding the delight of travelling via public transport (describing it as pathetic would be an understatement, hence skipped), he transcends to the castle a.k.a. office in other professions. The unquestionable devotion (no pun intended) towards his work is physically visible as he takes long strides and enters the castle. Life, society, culture, esteem, pride and many other eligible candidates of personal character stay out as he walks in to the castle.

the starters
The most crucial activity of the day begins, checking personal email account. And to just give an example of the overflowing talent in him, even the strictest of firewalls and blockages are incapable of preventing him from accessing his aspirations. His concealed talent, resembling his meager pay slip, can by no measures be hidden, no matter how much he endeavors.

the dream
Unlike other professionals of his age (and beyond), he doesn’t intend to spend (again, skipping waste to avert understatement) his time, forwarding mails to his friends (remember, the social thing in him just stayed out as he entered the castle?). Rather with translucent aspirations, all he searches for (with a far optimized index then what Google can ever manage) is a call from anyone (being complacent) from his list of dream companies. Aghast!  Unlike Google, which returns a million results for even the most horrendous search terms, he witnesses a no results found (that’s why Google roars about its better, less optimized index).

the call
And before he could balance himself, here comes the call, from no one else, but his PM or TL or MD or CEO (remember its SME, so even CEOs have enough time to get on with individuals) or anyone at a relatively higher position then him. Yes, this is it! Life, if ever existed, will cease to exist. Problems, in case they don’t exist, will be created and accredited to him.

the aftermath
The repercussions of the call, a tiny list of tasks, generally, varied in nature and ranging from simple to super complex tasks, to be, in all magnitudes of time, be completed by the currently running day. And did I mention it’s already lunch time!

the optimizations
Being super talented has its own advantages; it allows you to optimize time, beyond the ordinary, spent in professional activities. And the SME dev is no exception, he quickly walks through the tasks list, completing the tasks ranging from simple to considerably complex in irrelevant time spans. The ultimate desire at any point of the day that keeps him inclined - leaving for home (sweet home) at the right time.

the valor
Quickly sensing that the day isn't as good (sarcasm intended) as it was supposed to be, he aims towards his superior with one of the most irrelevant issues of his life, increment (presuming his steady association with the company, which simply refuses to end).

the crime
Approaching for increment in an SME is in itself an offense, unforgiving and regretful. Irrespective of the person being approached, the debate, most of the time leads to a plethora of branching discussions (healthy ones) about - the ubiquitous recession. Even though he wasn't the offender in bringing the slump to the economy in general, still, as a solemn employee of the company, it is his (and solely his duty) to forget increments, incentives, and any other term that relatively maps to the same meaning. He is a developer, passion feeds him, and code recharges him, why on earth has he the need of a better pay scale? Why do we need money? Mostly for our social activities, and if the very social element is missing, why direct the funds in the wrong place?

the return
With an absolute sense of satisfaction, understanding his very own importance in the company and the role (the most important one) that he plays in the general growth of the company (as alluded by his superior), he returns to his desk, unaffected by the discussions, proceeding to what he was supposed to do, code!
The evening is as stale as the dreams he has, and proving his multitasking abilities, he goes ahead in search of his dreams again (accessing his personal email account, remember?) while coding the most complex tasks, wishing them to auto-complete, be auto-verified and surely get auto-published.

the home coming
It would be audacious to imagine that nothing went wrong while the evening squeezed past. Client feedback (mostly neutral, the positive, if any, never make up to him, an auto-transfer mechanism transfers his credits to his superior's account), bug lists, pending tasks (even after a full dedicated day of work) and an extinguished desire to return home is what awaits.
 The journey to home is as exciting (remember the public transport factor?) as it can be and seldom enough does he get time to re-structure his goals (which by now have been declared static).

The day ends, as any other; battles won (and battles lost), nevertheless the passion, the dream, the very sense of being a developer, remains!

Be an SME developer, its an experience life apart!