27 August 2012

Four hours

On Sunday I had the pleasure of introducing a C/C# programmer to Python.

I always tell people it only takes 4 hours to learn Python, and I say it because it’s true. But when I actually see someone pick up a whole new language from scratch, port some existing scrap of C code to Python, learn where the documentation is, set up virtualenv, and write a web app that sends somebody a text message, all in four hours f’real wall-clock time, well. It gets me right here.

When I was interviewing for Mozilla, Mike Schroepfer asked me two questions. (I bombed them both; to this day I have no idea why they hired me.) One was something like: why is it that dynamically-typed languages can be so much more productive than statically-typed languages? I mumbled something inane about not having to write out the types. Worst answer ever, and I knew it.

It was especially chastening because I had spent a lot of time thinking about it, apparently without drawing any insightful conclusions.

The question seems a little passé to me now, but only because about a decade of my life was a fantastically stupid flame war over that one thing. Not because we really finished with it.

I wonder if we could have a better discussion about this now that we’re all grown up. Maybe I’d have something intelligent to contribute now.


I. J. Kennedy said...

So, why IS it that dynamically typed languages are more productive? I feel it too, but I can't put my finger on why.

jto said...

Well, the dynamically typed languages are typically much higher-level. Arrays and hash tables are built into the syntax. The libraries are designed for getting things done. So you can do more with less code, which means you have fewer bugs and less to maintain. Huge productivity win. But that's a high-level/low-level distinction, not static/dynamic.

I think the thing about static types is that actually figuring out the types for some kinds of code is a major distraction, and it doesn't really buy you anything.

I *want* to like static typing. I like having my spelling errors detected at run time. In principle it seems like types should be a huge win. But in practice I have to have just as many tests whether I'm coding in Python or Java. That's the bottom line. It seems like if static typing were really preventing an important class of bugs, I'd have fewer tests.

Raph Levien said...

What, then, about a language like Go, which is like a dynamic language in that arrays and hash tables are built into the syntax? Also that you have to write out the types a lot less than, say, Java. Yet, it is statically typed (though it does give you an "any" type in the form of interface{}) and, in my experience, does give a lot more confidence at compile time about certain classes of bugs I've been bitten by in dynamic languages.

jto said...

The static languages keep getting better. Go in particular I don't care for. The main sticking point is error handling.


Anonymous said...

How about not having to do a lot of explicit casts?

For me it's like walking a dog: if you take a short leash you walk as much as the dog and you have more control over its actions; on the other hand if the leash is long enough the dog can get tired in less time and without making you sweat, but things can get messy.

(also that's maybe the reason projects written in dynamically typed languages tend to not scale very well, so in a way productivity may depend on what you choose but the proper choice may not always be the same)