Leave me alone when I’m coding

Recently, Roy Bahat, president of IGN Entertainment, wrote about why he’s learning to code. This part of his post, coming from someone who isn’t a programmer by profession, was especially insightful:

Every time I open my editor, I’m reminded that I can’t just “jump in for a few minutes” the way I can with my usual work – either because coding isn’t like that, or because I’m not good enough yet. It takes me time to rev up, remember what I was supposed to be doing and how it fits together.

How often have you had to explain to someone who isn’t a programmer that you can’t just dive in and start coding right away? That it takes some time for you to settle down with the program and become really productive? That a single 3-hour stretch of uninterrupted coding could never be substituted by three one-hour blocks separated by meetings?

I wish everyone who enters software industry – in non-programming roles – would understand the fact that a programmer’s day isn’t neatly split into neat 60-minute blocks in Microsoft Outlook calendar. The only way they could understand is if they tried writing some code of their own. Sadly, I don’t think that’s going to happen in most software companies.


PS. I just noticed another great article on Roy’s blog on the same topic: Learning to code might become a basic job requirement. Do read it.

Paul Graham has written an article about the same topic – Maker’s Schedule.

Tabs vs. spaces for indentation

A few days ago I was arguing with a friend about the right way to indent code. Being a spaces-for-indentation fanatic myself, I complained about the hard tabs he was using in one of his github repos and he in turn expressed shock that I actually waste time on this space-for-indentation thing.

If you’re an indentation fanatic, you would probably – like me – classify programmers into 4 categories:

  1. People indenting with spaces
  2. People indenting with tabs “\t”
  3. People who mix spaces and tabs
  4. People who don’t indent

Did I hear you mutter “That 4th type are NOT programmers”? Of course they aren’t. In fact, in my book they are right up there alongside Suaron‘s minions, Lord Voldemort‘s Death-Eaters, and Darth Vader and the Sith as the most evil creatures that ever walked on the earth.

Unfortunately for those of us that try to hold on to our sanity, there are hiring managers out there who hire these people and let them pollute others’ beautifully written code. As long as they are allowed to write code, we might as well accept the fact that they exist in the programming world.

Which brings me to the type 3 folks. Their mixture of tabs and spaces makes it a nightmare to read code, but at least you can convert the tabs in most editors and get something close to readable code. At least they try to indent, and that’s a lot better than code that’s fully left aligned. Anyway, if you’re one of the people doing this… stop it. Just stop. Please.

That finally leaves the two sets of programmers that indent exclusively using either spaces or tabs. Personally I prefer spaces, but that’s probably because I write Ruby code often and using two spaces for indentation is the common convention in the Ruby community.

Why use tabs?

Tabs for indentation has one clear advantage over spaces. You can customize how much indentation should appear. For instance, if your teammate likes 8 column indentation (what kind of people do you work with?) and you prefer 4 columns, well, you don’t have to do anything. Once you’ve set your editor to display 4 column tabs, you don’t have to worry about how many columns your teammates see. As long as you both consistently use hard tabs, you’ll both be fine.

Why use spaces?

Most Ruby and Python programmers would swear by spaces-for-indentation. People in both these communities almost unanimously agree with indenting with spaces and it’s especially important in Python because of its use of whitespace for delimiting blocks.

The best thing about this is that it makes the code look consistent everywhere. Since everybody in these communities uses the same indentation rules, it’s not much of a problem, but no such consensus in many other languages.

Conventions

While looking around for conventions in major open source projects on indentation, I came across the Linux coding style document:

Tabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3. Rationale: The whole idea behind indentation is to clearly define where a block of control starts and ends. Especially when you’ve been looking at your screen for 20 straight hours, you’ll find it a lot easier to see how the indentation works if you have large indentations.

I find this strange. Draconian almost. Eight character indentation seems so 1980. And yet one of the most important open source projects in the world imposes these rules, and some of the best programmers in the world follow them. In such cases, using tabs for indentation makes sense, because then heretics like me can set the tab width to 4 (or even 2! – what madness!) and happily read the code.

[To the author of the document quoted above: If you've been looking at your screen for 20 hours straight, that means you ought to be taking a break, rather than increasing indent levels on your program. ;-) ]

Anyway, what’s most important about indentation is that you -and your team – do it consistently and follow the same guidelines. Here’s what Jeff Atwood of Coding Horror has to say of tabs v/s spaces in Death to the Space Infidels!:

Choose tabs, choose spaces, choose whatever layout conventions make sense to you and your team. It doesn’t actually matter which coding styles you pick. What does matter is that you, and everyone else on your team, sticks with those conventions and uses them consistently.

Which he cheekily followed up with:

That said, only a moron would use tabs to format their code.

I certainly won’t disagree with that. The second part, especially.

Related articles:

Rails: "500 – Internal server error" caused by error in application.rb

Today, while working on my Ruby on Rails project, I got a “500 – Internal server error” page soon after I tried to run the project after running a migration. There was nothing else on the screen except for that one line.

I tried a few things, like restarting NetBeans, and opening another project to see if the problem was with my Ruby installation. (Other projects were running fine, so the problem wasn’t with Ruby.) I even tried running the project from another desktop, getting the same 500 error.

Finally, I did the one thing that I should have done first – checking the development log file. There I found that the problem was a tiny bit of buggy code in the application.rb file that was stopping the project from initializing properly. And because the application failed to initialize, I wasn’t getting those detailed error messages that I’m so familiar with.

Have you done something so stupid while developing an application? Forgetting to look at the first place where you could have spotted the problem and instead wasting an hour theorizing about what could be causing the problem?

IE6 No More – Let’s Kill IE6

Microsoft recently made an announcement saying that they will continue to support IE6 until August 8, 2014. That’s another 5 years. Can you imagine that? Another 5 years of supporting IE6 when HTML5 and CSS3 are just around the corner.

If you are a web developer, you probably hate IE6 as much as I do (or even more, if that much hate is ever possible). And like me, you are waiting for the day when the damn thing disappears off the face of the internet.

When I started this blog, I had planned to make it completely inaccessible to IE6 users, and instead display a message asking them to switch to some other browser. But then I realized that it’s too much effort to hack the template for the sake of spreading the message to the 1% of visitors of this blog who still use IE6.

Instead, I chose to leave all the IE6 bugs unfixed (this template looks awful on IE6) and added the banner from the IE6 No More campaign. “IE6 No More” is a campaign by a group of startups that are fed up with the ancient browser and want it to disappear. Do take a look at their website where they make a very good case against IE6.

However, there’s hope for us yet. Digg has restricted access to some of its features on IE6, Facebook is asking IE6 users to upgrade and YouTube will drop IE6 support very soon. If more big websites will also take steps in this direction, we won’t have to wait till 2014 for IE6′s death.

What browser do you use? Do you think all website should follow Facebook’s lead and ask users to upgrade?

If you are a developer, how much of you time is wasted fixing all those IE6 bugs? Have you worked on any website recently where you didn’t need to make it compatible with IE6?

PS. If you are a Firefox person and have your own website, why don’t you help spread the word about Firefox? The more IE6 users we convert, the better! ;-)