…meie igapäevast IT’d anna meile igapäev…

2012-05-04

The three L’s of programming

Filed under: Programmeerimine,Rant — Sander @ 18:20:28
Tags:

Html-source-codeRecently I’ve done quite a lot of interviews with candidates for a position of junior programmer, reviewing their test assignments and so forth. This has led me to wonder – what exactly am I looking for? How can I tell the difference between someone who will be a good programmer, and someone to whom programming will be just a nine-to-five job. Or, more precisely, what makes someone a good programmer?

I’d like to think I am a good programmer myself – or at least strive to be one. Sure, I will never be a coding guru who has all of Knuth memorized and can solve the travelling salesman problem with 23 cities using seven different algorithms without a computer. But I’m good enough for my daily chores.

This post tries to formulate some of the ideas I’ve had. I won’t pretend this to be an absolute, universal and final truth, these are just my thoughts on the subject.

Love

You have to love the code.

There is no other way to put it. You have to be passionate about what you do. The happiness when you pull off something above and beyond what the framework authors intended. Or the deep satisfaction from just finishing a really good piece of code. Or even the frustration of hunting an ever-illusive bug – and the joy upon fixing it.

If you have that passion, then you’re half-way there already. Everything else will come – knowledge, experience, “code-sight” – but if you lack that love, then you’ll never be a good programmer in my book. There is simply no replacement for it.

Largely, this is the reason why the famed Indian programming sweatshops (which were such a rage four or five years ago) are now mostly out of the picture. You had a circle of twenty university graduates and a supervisor walking around behind them, making sure everybody are coding as fast as they can. No slacking!

But the result of such work was simply not worth the price of $500..1000 per developer/month. As far as I know, a lot of the major players have now stopped outsourcing the work to such places (which are not necessarily in India, you can find programming sweatshops in quite a few places around the world). It is just cheaper to pay local, higher-paid programmers to do the same work in half of the time and a tenth of the bugs.

If you lack that love of code, then you still may write a decent code. But it will never be a brilliant code, it will just be a code that sort of works. You’ll lack the spark, the similar spark that makes Shakespeare different from a copywriter.

But what is there to love about the code?

It is the same excitement that a poet gets from writing a poem, or a painter from painting. It is the act of creation, the “develop” part of the word “developer”. We write some lines of text, which abides to the certain rules, and suddenly ex nihilo! we have a website, a video player, a database engine or something else.

Learning

If you are looking at your own code from two years ago and it looks fine, it doesn’t mean you were a good programmer two years ago. Quite the opposite, it means you haven’t grown as a programmer within these two years. You haven’t learned anything.

Programming is all about learning. New languages, new frameworks, new ways to do things, new tricks. Like Lewis Carrol’s Red Queen put it, “It takes all the running you can do, to keep in the same place.”

If you want to become a programmer, you will not be able to stop learning the day you left the university. In fact, you’ll realize that a lot of what your Alma Mater taught you is, frankly put, useless.

My own way to become a programmer was… convoluted, to say the least. Some day I will write a post about it – but suffice it to say that I don’t have a formal education in programming. I am completely self-taught. And, in a way, that is a good thing. Constantly learning something new is normal for me, whereas people just out of university often go “but I was taught to do it this way?!”

And so far, every time I’ve looked back at myself from two years ago, I’ve been able to go “boy, was I stupid back then. I am glad I am so much better now.” I hope this never ends.

Lazy

A programmer I used to know needed to generate some HTML. Cleverly, he used helper methods to do that. He needed H1, so he created a method similar to:

  1. public static string GetH1(string content)
  2. {
  3.     return string.Format(“<h1>{0}</h1>”, content);
  4. }

He also needed a H2. So:

  1. public static string GetH2(string content)
  2. {
  3.     return string.Format(“<h2>{0}</h2>”, content);
  4. }

And then he needed H2 with an ID. Lo and behold:

  1. public static string GetH2(string content, string id)
  2. {
  3.     return string.Format(“<h2 id=’{0}’>{1}</h2>”, id, content);
  4. }

And then he also needed H2 with a class. I’ll spare you from the code now, but you can guess what he did.

But this was just for H1 and H2 tags. He needed various other tags as well – img, div, p and so forth. And yes, you guessed right. He had overloaded methods for each and every one of them. The helper class ended up with about 30 methods in a several hundred lines of code.

Me, I’m a lazy bastard. I would have written:

  1. public static string RenderTag(string tag, object attributes = null, string content = null)
  2. {
  3.     tag = tag.ToLowerInvariant();
  4.     var html = new StringBuilder();
  5.     html.AppendFormat(“<{0}, tag);
  6.     if (attributes != null)
  7.         foreach (var prop in attributes.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
  8.             html.AppendFormat(” {0}=\”{1}\“”, prop.Name, prop.GetValue(attributes, null));
  9.     html.Append(content == null ? “/>” : string.Format(“>{0}</{1}>”, content, tag));
  10.     return html.ToString();
  11. }

Less than dozen of lines of code without empty lines and braces. And that’s it for every tag you can imagine. Call it any way you like – RenderTag(“br”); RenderTag(“h1”, null, “header”);, RenderTag(“h2”, new { id=”myId”, @class=”myClass” }, “subheader”); – it just works. You can even render tags inside tags with that method.

Sure, I wouldn’t use that method to render a full website, but for a few dozen lines of HTML that was needed, it would have been perfect. Far faster to write than hundreds of lines of repetitive code.

The point where I’m getting to is that you can be eager and write more code. Or you can be lazy and figure out a way to write less code. Being lazy is a good thing in a programmer. It forces us to find patterns and promotes code reuse. It makes us more effective. It makes us better.

Or, to use the words of Terry Pratchett, “Having to haul around extra poundage was far too much effort, so he saw to it that he never put it on and he kept himself in trim because doing things with decent muscles was far less effort than trying to achieve things with bags of flab.”

—-

tl;dr: just read the damn thing.

2012-04-16

I don’t believe in evolution

Filed under: Rant,Terve mõistus — Sander @ 16:11:02
Tags: , ,

EvolveFish I don’t believe in evolution.

I can hear what you are thinking: Is he an idiot or something? Even though he has an MSc in animal ecology and an unfinished PhD in evolutionary ecology, he still doesn’t believe in evolution?!

But here’s the thing: evolution is a scientific theory, same as the theory of gravity, germ theory, cell theory, quantum theory, theory of relativity and many others.

Unlike religion, science doesn’t work with beliefs – you take the facts supporting the theory and compare those with facts not supporting the theory. Then you decide if the theory is correct – or perhaps you should improve the theory, choose an alternate theory or scrap the whole thing altogether.

And the theory of evolution has literally hundreds of thousands (if not millions) scientifically validated observations and experiments supporting it. You have scientific articles, monographs, experiments (yes, there are loads and loads of experiments on evolution), observations and so forth.

And now we take the facts not supporting or invalidating the theory of evolution… oh, wait. There aren’t any.

There is not a single observation or experiment that invalidates evolution. No fossil rabbits in Precambrian strata. No human footprints next to dinosaur footprints. No genetic data showing the synchronized bottleneck of Noah’s ark in all of the animal species. No radioactive dating results or anything else disproving the Cambrian explosion.

There simply is nothing. Or, like Richard Dawkins put it, “Today the theory of evolution is about as much open to doubt as the theory that the earth goes round the sun”.

So, I don’t believe in evolution. But I also don’t believe in the chair I’m sitting on right now. I can prove the latter exists by an empirical observations (looking and touching it) and testing (I sit down – if didn’t fall on the floor, the chair probably exists).

Evolution has been proven. And it does not require belief.

2010-05-19

Rant: Eesti riigi infosüsteemidest vajalikku infot jahtimas

200px-Coat_of_arms_of_Estonia.svg Leidsin, et Wikipedias on Eesti looduskaitsealade template ja nimekiri päris vananenud. Lihtsalt on lisandunud uusi kaitsealasid, pindalad ja staatused on muutunud. Otsustasin siis need mõlemad uuendada – ei tohiks ju olla kuigi keeruline võtta meie E-stonias need andmed võrgust ja sobivasse formaati lükata.

Statistikaaamet? Seal on mulle vajalik info olemas… kuid pärit aastast 2003. What gives?!

eesti.ee.logo.cropped Alguses ei leidnud ma ühtegi sobivat andmekogu. eesti.ee’s on ainult üldsõnaline jutt, “Kaitsealad on inimtegevusest puutumatuna hoitavad või looduskaitse erinõuete kohaselt kasutatavad alad koosluste, ökosüsteemide, maastike või liikide kaitsmiseks; nende uurimiseks ja tutvustamiseks.” Täiendava otsimisega leidsin lehe Riigi infosüsteemi haldussüsteem RIHA. Pane see leht nüüd kohe omale järjehoidjatesse, see tundub ainuke koht olevat, kus avalikult mingit moodigi riigi infosüsteemide kohta teadmisi saab. Miks ei ole olemas avalikku wiki-laadset lehte, kuhu ID-kaardiga sisse loginud saaksid koodinäiteid jm lisada?

kkr.logoSealt leidsin Eesti Looduse Infosüsteemi ehk EELIS’e ja Keskkonnaregistri avaliku teenuse. Kuid mõlemad tunduvad olevat n-ö lõpptarbija teenused, ehk tegelikult normaalses formaadis andmeid ei saa. Leidsin isegi mingi salapärase Keskkonnaregistri WSDL’i, kuid selle taga teenust ei õnnestunud mul leida, võimalik et iseenda rumaluse tõttu.

Huvitav, kas keegi tõesti siiani teeb avalikke registreid ja andmekogusid, millel puudub võimalus veebiteenuste abil infot pärida? Või on maniakaalsed ametnikud leidnud, et info ei tohi olla lihtsalt päritav? Mul on üsna ükskõik mis tüüpi veebiteenus on ja kuidas seda pärida – SOAP, REST, XML-RPC, OData, mida iganes – aga andke mulle andmed kätte lihtsalt ja töötlemiseks sobivas formaadis.

Nii tundubki praegu olevat ainuke võimalus võtta Keskkonnaregistri koostatud HTML ja parsida sealt välja mulle vajalik info. Õnneks on olemas projektid nagu HTML Agility Pack, mis seda oluliselt lihtsustavad. Või teab keegi targem vastavate teenuste asukohti ja kirjeldusi?

Aranea Web Framework[13] Omaette teema on Aranea Eesti riigiveebis. Ma ju tean, et Webmedia võidab enamiku riigihangetest, aga kas tõesti peab alati Aranead kasutama? Või ei ole probleem Araneas vaid arhitektuuris ja arendajates?

Kõike üritatakse sessioonis hoida. Mitte millelegi ei anta ligipääsu läbi aadressiribal näidatava URL’i – alati tuleb anda “Viide sellele lehele” ning vähemalt Keskkonnainfo lehel see funktsionaalsus enamasti ei tööta, rääkimata inimsõbralikust ja otsimootori-sõbralikust REST-stiilis aadressist. AJAX’iga tõmmatakse taustal terve leht, samal ajal layerit “Oota” näidates. Kui alustada pikka ja aeglast otsingut ning see katkestada, siis tagasitulles leitakse otsing sessioonist ning alustatakse seda automaatselt uuesti. Riigikeskkondades tuhnides olen saanud kümmekond viga – ning seejuures näidatakse infot, mida tavakasutaja kindlasti ei peaks nägema, “org.araneaframework.core.NoSuchServiceException: No such service 'Service 'zSDtoGTb' was not found under…”. Keelestringide asendus ei tööta igal pool. Süsteemi kiirus varieerub laiades piirides, olles sageli võrreldav ülesmäge roomava teoga.

Kas tõesti puuduvad riigi standardid, mis ülalpool kirjeldatud olukorda aitaksid vältida? Ma tean, et ma olen kusagil (RIA kodulehel?) mingeid alusdokumente kunagi näinud.

Järgmine lehekülg »

The Rubric Theme Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 68 other followers