Programming: doing it more vs doing it better


A few years ago, very early into my programming career, I came across a story:

The ceramics teacher announced on opening day that he was dividing the class into two groups. All those on the left side of the studio, he said, would be graded solely on the quantity of work they produced, all those on the right solely on its quality. His procedure was simple: on the final day of class he would bring in his bathroom scales and weigh the work of the “quantity” group: fifty pound of pots rated an “A”, forty pounds a “B”, and so on. Those being graded on “quality”, however, needed to produce only one pot – albeit a perfect one – to get an “A”.

Well, came grading time and a curious fact emerged: the works of highest quality were all produced by the group being graded for quantity. It seems that while the “quantity” group was busily churning out piles of work – and learning from their mistakes – the “quality” group had sat theorizing about perfection, and in the end had little more to show for their efforts than grandiose theories and a pile of dead clay.

Jeff Atwood’s “Quantity Always Trumps Quality” post, though he himself took the story from somewhere else.

This little story has had a tremendous impact on how I approach software engineering as a craft. I was (and still am) convinced that the best way to get better at software engineering is to write more software. I was careful enough to not take the story too seriously – I have always strived to write readable, maintainable code without bugs. However, deep inside my mind was this idea that one day I would be able to write beautiful code without thinking. It would be as effortless to me as breathing. “Refactoring code” would be something left to the apprentice, not something that I, the master who has churned out enough ceramic pots, would be bothered with. I just have to keep making ceramic pots until I get there.

Three years later, I am still very much the apprentice. Rather than programming effortlessly, I have learned to program more deliberately. I have learned (the hard way) to review my code more thoroughly and to refactor it now rather than later. I get pangs of guilt and disappointment every time my pull request has to go through another round of review. I am frustrated when I deliver a feature two days late. As an engineer I want to, above everything else, churn out (the right) features as fast as possible.

Today, I came across an essay that would let me resign from my perpetual struggle to “get faster” at engineering:

I used to have students who bragged to me about how fast they wrote their papers. I would tell them that the great German novelist Thomas Mann said that a writer is someone for whom writing is more difficult than it is for other people. The best writers write much more slowly than everyone else, and the better they are, the slower they write. James Joyce wrote Ulysses, the greatest novel of the 20th century, at the rate of about a hundred words a day

William Deresiewicz, Solitude and Leadership

I can strongly relate to this – I would often read and re-read something that I wrote and then I would go back and change it, only to repeat the process again. Though comparing my modest penmanship (keymanship?!) to “the best writers” is outright sacrilegious, even I have in the past noticed that the slower I write, the better I write.

The equivalent in software engineering terms would be to (nothing you did not know before, except for maybe the last point):

  1. Put more thought into the design of your systems
  2. Refactor liberally and lavishly
  3. Test thoroughly
  4. Take your sweet time

As I said, nothing you did not know before. Also, this is almost impossible to pull off when you have realistic business objectives to meet.

But James Joyce probably did not write Ulysses with a publisher breathing down his neck saying “We need to ship this before Christmas!”.

So the secret sauce that makes good code great and the average Joe the next 10x programmer might be this – diligence exercised over a long time.

How does this affect me? Disillusionment. Writing more software does not automatically make you a better programmer. You need the secret sauce, whatever that might be.

Announcing matchertools 0.1.0

Matchertools is my “hello world” project in rust, and I have been chipping away at it slowly and erratically for the past couple of months. You can now find my humble crate here. The crate exposes an API that implements the Gale-Shapley algorithm for the stable marriage problem. Read the wiki. No really, read the linked Wikipedia page. Lloyd Shapley and Alvin Roth won a Nobel prize for this in 2012. Spoiler alert – unlike what the name indicates, the algorithm has little to do with marriages.

This project is so nascent that it is easier for me to list what it does not have:

  1. No documentation
  2. No examples
  3. Shaky integration tests
  4. No code style whatsoever. I haven’t subjected the repo to rustfmt yet (gasp!)
  5. Duct-tape code.
  6. Not nearly enough code comments.

Meta

I had recently adopted a new “philosophy” in life:

Discipline will take you farther than motivation alone ever will

Definitely not me, and more a catch-phrase than philosophy

Most of my side projects do not make it even this far. I go “all-in” for the first couple of days and then my enthusiasm runs out and the project is abandoned before it reaches any meaningful milestone.

But I consciously rate limited myself this time. I had only one aim – work on matchertools every day. I did not really care about the amount of time I spent on the project every day, as long as I made some progress. This also meant that some days I would just read a chapter from the wonderful rust book and that would be it. However, I could not stick to even this plan despite the rather lax constraints – life got in the way. So my aim soon degenerated into “work on matchertools semi-regularly, whenever I can, but be (semi) regular about it“. Thus in two months, I taught myself enough rust to shabbily implement a well-known algorithm. Sarcasm very much intended.

Though I was (am) horrified at the painfully slow pace of the project, the “be slow and semi-regular but keep at it” approach did bear results:

  1. I learned a little rust. I am in love with the language. The documentation is superb!
  2. I produced something, which is far better than my side-project-output in the past 18 months – nothing.

Besides, I have realized that much of what happens around me is unplanned and unpredictable to a larger degree than I had thought. I am currently working on revamping the way I plan things and the way I react when my plans inevitably fail. A little Nassim Nicholas Taleb seems to help, but more on that later.

Starting up on a Saturday ‘noon

I had a sudden itch to build something from the ground up. I knew the moment it started to itch that the itch will not be cured until I sink hours into something laborious and intellectually satisfying. I wanted to build a company from the ground up. If a stupid photo-sharing app like Instagram could make so much money despite bringing almost zero utility to the user, I’m pretty sure anything can make money. On hindsight, I realize that I might be just another clueless programmer who can’t figure out how the hell Instagram, vine, yo, and WhatsApp made so much money. I mean come on, did the world really need another texting service? Or another photosharing service when there were facebook, Flickr and a whole ton other services? Don’t even get me started on yo. I admit it. I’m just jealous. I know that Instagram is engineered well.

Anyways, my glorious new “startup” would be called “Use my space”. It’s kind of very very similar to Airbnb but different. I won’t pretend that I came up with an idea that is nothing like Airbnb and serves a completely different user base. That’s not true.

Gist: you get to rent out soccer ground for a weekend brawl with friends, a rusty old shed for your hardware project e.t.c

It’s sunday noon and the infinite pool of passion and vigour that I assumed I had to bring my idea to life is seeming to dry up. I’m already not-optimistic, though not entirely pessimistic. However, I had put together a couple of screens yesterday night to create a UI prototype so that I can pitchto probable co-founders. Oh what a fallacy. Here are the screens. Proof that I was willing to put on the designer hat for the sake of a product.

All screens were made using Inkscape on Ubuntu:

Image attributions:

Assembled a computer

I was without a computer for a whole year. A whole frigging year. And THIS is my reward:

Christened alduin, after the big black dragon from skyrim

Specs

  1. Core i3 6100 @ 3.7Ghz. Skylake.
  2. 8 GB Corsair vengeance DDR4 2133 RAM. Single stick
  3. Zotac GTX 950 Amp! edition. 2GB VRAM. Entry level graphics card.
  4. Adata 120 Gb SSD
  5. Gigabyte GA H110m motherboard. Micro ATX form factor
  6. Antec X1-T cabinet
  7. Cooler Master Storm Devastator gaming combo – backlit keyboard and mouse.
  8. BenQ G2255 21.5 inch monitor. 1920 x 1080.
  9. APC 600v UPS, an extension cord, a used office chair, a really cheap computer table.

And finally, a 60k (INR) hole in my wallet.

But I’m happy I have a computer and I’m happy that I could assemble it. Most of the parts were ordered from theitdepot.com with the monitor coming from Amazon.in.

Why I chose to assemble a desktop, as opposed to buying a laptop

I had to live without a computer for almost a year. Why? Because the Nvidia 610m GPU in my Asus k53SD laptop died. No, you can’t replace just the video card. You have to buy a whole new motherboard because mobile GPUs come soldered to the motherboard. But can’t you just unplug the video card and use the integrated GPU? No. It doesn’t make sense but apparently, that’s how mobile GPUs work. Did I say that I was asked to pay for a new processor as well? Yeah! Because k53 motherboards have the processor soldered to it. At least that’s the explanation the repair guy told me. So ordering a cheap motherboard without a graphics card from eBay won’t work because you can’t pull out the processor from the damaged board and put it in the new board.

Broken hearted, I agreed to pay the price for a new board and a processor – only to find out that it is difficult to source the motherboard because my 2 year old model is outdated.

If that was a desktop, I could have just pulled out the graphics card and everything would have run fine on the iGPU. Everything except the few games I play.

I promised myself that I would never ever buy a laptop as my primary computer again.

Rant ahead

When I assembled my computer, there were very very few laptops with the latest skylake (6th gen) processors inside. This was in February end and almost 5 months after skylake was made available to consumers. Almost all the laptops listed at amazon and other e-commerce sites were running 4th generation processors. However, I did not see any price drops. An ivy bridge core i3 was listed at the same price as a haswell i3 which was listed slightly below the price of a broadwell laptop – and broadwells were rare. I suppose this happens only in India.

So what laptop will 45k Indian ruppees get you? A haswell mobile (mobile processors are always slower than their desktop counterparts) core i5 with 4 gb RAM and no dedicated GPU. If you are lucky you would get an 8GB SSD where windows would be preinstalled. Yes, 8GB. 720p Screen.

Guess how much my assempled pc would have cost sans the graphics card? 42K. And that’s including the chair and the table.

Hence proved that desktops are more bang for buck if you actually are concerned about performance (A.K.A gaming) and do not mind the lack of portability.

Motherboard refused to power up. By 2.30 A.M I realised that the power connector was loose *sigh*

KDE, Gnome, Unity and cinnamon – why should you care?

You shouldn’t.

It really doesn’t matter. But geeks and fanboys support their favorite desktop environments with religious fervor out there. If you’re ever in doubt, just pick one and go. The next n paragraphs are on how and why I switched from KDE to cinnamon.

(Desktop environments in linux are more less like themes in windows – and more. Get started with linux here)

I was running a linux mint 15 KDE on my computer till now. It was not a stable version (based on ubuntu 13.10) and had quite a few broken things in it. Worse – I couldn’t get the latest (and the greatest) version of firefox from the repositories – the newest version that was available was firefox 27. So I decided to upgrade my OS and since there was a general idea that KDE was heavy on resources, I thought I’d give cinnamon a try. But a quick glance at the forums made it clear that KDE is not as heavy as it used to be. It boots like a snail, true. But once you actually start doing something KDE seems to use less memory than ubuntu’s unity.

So, I installed linux mint 17 cinnamon without any problems. I was disappointed to see that it took as much time as KDE to log in, even though it was supposed to be lighter (I was wrong, cinnamon is faster, read on!). However, cinnamon was super snappy when I started clicking things, and to my surprise, had everything I wanted! It is true that you can’t tweak cinnamon to the extend you can tweak KDE. But cinnamon had just the right things for me. The default wallpapers are no good though, and I quickly went in search of wallpaper packs.

Desktop
Desktop : You will have a harder time finding wallpapers that go with the default green icon set

Switching workspaces is sweet, and considerably faster than the 3D cube in KDE (you can turn this off, but I couldn’t resist it while I was using KDE). Pressing ctrl+alt+ quickly takes you between workspaces with a swish. Yes, an audible, annoying “swish”. Also, it displays “workspace 1” or “Workspace 2” when you switch into the corresponding workspace. I quickly changed the workspace labels to “Home” and “Development”. I haven’t decided what to do about the “swish” yet. To my disappointment, it is not possible to have different wallpapers for the different workspaces. This is a complete let down. But a quick search revealed that only KDE has implemented this feature so far. Moving on, I configured ‘hot corners’ – Move your mouse to the upper left corner and all the active windows are lined up in a nice grid. If unity had these (supported out of the box), maybe I would have never moved from stock ubuntu. Move mouse to the lower right and it shows the desktop. These are configurable, of course.

Meanwhile, the slow startup time was driving me mad. I did not wipe out my previous OS for this! I got so pissed I downloaded and installed the 64 bit version of Mint 17 cinnamon. What a relief! Faster and snappier and me happier! I now remember that my previous KDE was 64 bit. On comparison, cinnamon 64 bit is definitely faster.

Window switching
Window switching : When I go to the upper right corner

Oh, and now I have nvidia drivers by default now. Optimus do not work yet, but prior linux distros I tried didn’t even detect my card, and installing nvidia drivers almost always crashed my system. Nvidia nouveu was selected as default (no hardware acceleration) and proprietary drivers from Nvidia were listed as well. However, switching to proprietary drivers crashed cinnamon, and kept crashing until I switched back to Nouveu. This was expected since I have an optimus card. Might have worked if I was on a desktop.

Since I have the name sake Nvidia drivers now, decided to try steam on linux. Opened up software centre to install steam, and uh oh, its less bloated and more snappy than its ubuntu counterpart. For the first time in my life, I’m using software manager rather than the command line apt-get to install things I need. It gave me great app suggestions and I found myself installing minitube, a native youtube client for streaming content from youtube (which crashed cinnamon – reported by multiple users).

Mint 17 came with it usual share of bundled applications and proprietary codecs to get me started. Torrent client was working (though it took me somewhile to get it to capture magnet links) and steam is downloading monochroma demo.

Verdict? Comfortable, convenient, way thinner (on the memory) than KDE, and way better than everything except KDE (tied).

S-tall-man the tall man

SPACE – Society for the Promotion of Alternative Computing Environments celebrated their 10 years of existence today here at Trivandrum and they invited none other than Richard Stallman to do the talking. I was 13 or 14 years old when my father first told me about Richard Stallman and about the ‘big things’ he were doing with computers. The only impression I got from his photo was that he was a particularly huge man with huge beard and loooong hair. Today, I saw this guy ‘for real’. Mr.Stallman has had a rather warm relationship with the government of Kerala and he had visited the state several times before. After all, this guy had convinced our government to get rid of the windows PCs and move to free software. Thanks to Stallman – I’m not using that retarded Turbo c++ compiler to compile my c++ programs.

Not so huge from where I am sitting!
Not so huge from where I am sitting!

Shake hands for freedom
Shake hands for freedom.

The talk was semi-boring. The people on the dias dozed off while Stallman was buzy giving us a lecture on digital freedom. Neverthless, he did come up with a few new things to say. There was the usual tandrum about security and privacy on the internet and unjust surveillance. He explained that he has never owned a portable (mobile) phone and never will. Said he would rather not use that piece of technology than let someone spy on him. A friend brought to my attention the rather unusual similarity between Stallman’s way of talking and the flavorless, emotionless voice used by Microsoft windows to read things aloud. If I were blind, I would have (could have, to be more precise) mistaken Stallman’s lecture for a windows machine reading text aloud!

Then he moved on to his forte – free software. As usual, he specifically portrayed Microsoft and the ‘ithings’ as evil and what you and me call open source as a lesser evil. Open source was not enough for him, he wanted things to be ‘free’. This raised a few eyebrows, and I think it raised my eyebrows the farthest. But I already knew this from the wikipedia entry on him so I was more or less feigning surprise. Also, as he had been doing for years, he emphasized the necessity and the importance of referring to linux as GNU/linux (pronounced GNU slash linux or GNU plus linux) instead of just linux. He gave a convoluted philosophical explanation to it but it was bull shit. It seems the man has a problem with Linus Torvalds.

Then he said something really meaningful. He said that people have the right to use proprietery software and it is actually OK to do so. “Even though they are hurting themselves”, said Stallman, “they are not doing harm to the society”. But, governments and states are established for the purpose of serving man. Institutions and frameworks with public benefit in mind should never ever use proprietary software. Doing so puts the “national security at risk”. This makes sense. Now that he has said it, I feel victimized when I remember that the only operating system available on our school computers were Microsoft Windows. I feel that me, along with a bunch of other kids, were forced to use commercial software that was just popular but not universal. Since we were learning to program and not to ‘use’ computers it would have been better if we were trained on a *nix machine – at least it is free and can be modified at will. Using only Microsoft windows at school is like having to eat only one flavour of ice cream while you are at school. States should not have the option of using proprietery software. The source code should be able to be examined to make sure that there are no backdoors or security threats than can be engineered to be used for malicious purposes. Good thinking Mr.Stallman 🙂

There was another revelation in there for me – Stallman claimed that Facebook monitors a lot of people – people who don’t even have a Facebook account. The logic was this. When your browser loads a website that contains the ‘Share via Facebook button’, your browser requests the Facebook server to provide it with the blue and white ‘F’ image. Your browser tells the Facebook server that it is for your computer (your ip) and for using at this website. Hurray, Zuckerberg knows which site you are surfing!

As for me, I would go with the open source guys. Stallman and software that is ‘truly liberated’ is an extreme, and I don’t like extremes. Not because extremes are difficult to live with, but because such extremes almost always have little practical value and their advocates are often fanatics who refuse to be convinced otherwise. Neverthless, people like you and me are indebted to Richard Stallman for things like GNU, and drum rolls please – gcc (GNU C Compiler).

P.S – Mr.Stallman held an auction at the hall and sold a ‘gnu’ doll – and I came to know that there is an animal called gnu and it lives in africa. The doll was sold for rs.2500.