Choosing the right language for the job

Quick: Which programming language would you use for a big project?

There is no single answer to that question without a few more specifics. The “right” language to use depends heavily on the type of problem at hand. What about a thought experiment?

Here is a list of all programming languages that I know at least a little:

Ada, Awk, Assembler, BASIC, C, C++, C#, COMAL, Common Lisp, D, Delphi, Erlang, Factor, Forth, Go, Haskell, Java, Javascript, Lua, OCaml, Turbo Pascal, Perl, PHP, Python, Scheme, Shell, Tcl, Visual Basic Classic, Visual Basic .NET

Let’s skip the oldies that don’t run on modern hardware or operating systems anymore. Say goodbye to BASIC, COMAL, Turbo Pascal and Visual Basic Classic.

Now let’s fantasize about a program I want to write. It should be portable across the most important platforms of today, it shouldn’t require a big setup step. Just a single file to download and execute, that’d be fine. And it should be as cheap as possible, as I don’t want to spend lots of money on a personal side project just yet. Those requirements aren’t that weird for a non-web app. Let’s go over them in detail:

I want my programs to deploy as a self-contained executable: Lots of scripting languages and VM based systems can’t do this, so we can strike out Awk, C#, Erlang, Java, Javascript, Lua, Perl, PHP, Python, Shell and Visual Basic .NET. Ouch. As a heavy C# user at work, that’s a language I’ll miss dearly. But single file executables still need the Framework installed for the time being, so it’s a no-go.

I want my sources to be platform independent, so we strike out Assembler. For developing larger applications I want either a sound type system with templates or generics, XOR duck typing: Goodbye, C, Forth and Go.

For my home-brewn projects I want free development tools: Delphi has to go, too. D and Lazarus sadly still don’t make the stability cut. Ada and C++ drop out because I happen to like Garbage Collection as much as I dislike typing my fingers off just to sum up a list of numbers. And the single-file packagers for Java are a little steep for my taste.

So what we end up with is a small but interesting list:

  • Common Lisp
  • Factor
  • Haskell
  • OCaml
  • Scheme
  • Tcl

Look Ma, no C like syntax! Instead we have two Lisps, two full-blown functional languages, albeit differing in purity, a concatenative language and my beloved quirky little Tcl. Which would be my weapon of choice, unless we need max performance. Strange that a language many programmers have never heard of would be my top choice…

Tcl is great for quick GUI projects that don’t have to be as fast as possible. With a Tclkit you can pack your application code, libraries and configuration files, even media files, into a single executable. It’s great for quick-and-dirty programming, but when it comes to performance, it sucks.

Now if we change our requirements a little, the list would look entirely different. If we don’t mind a big installer, and our target platform is Windows, but we need SPEED!, suddenly C# is the tool to use, maybe with a C DLL thrown in. Or use Java with a nice installer. Or could we…? Yup, just use that C DLL that encapsulates the performance-critical stuff in a Tcl program, and you’re good.

As long as your program doesn’t get too big, that is. Now we face a different problem: While C# is a mostly statically typed language, Tcl is not. Static type systems are great if you work together with other programmers in a big team, as you can use tools like ReSharper and FxCop to look for pitfalls. No chance here in a Tcl source. Same thing with Lisps or Factor: Formidable tools for a single hacker, but a disaster if you have a team of programmers with differing skill sets working on a big piece of code. Suddenly interfaces between chunks of your application and a whole lot of tests become paramount.

On the other hand, interfaces and tests should be what drives your development efforts anyway. Divide your application into separate modules, define sound interfaces, and every team member picks a module to hack on. Why should the programming language used matter here? You should use the same big test suite in a C# project that you would have in a Tcl source. What is it that makes us think that dynamic typing is bad for big teams? The practice of factoring a problem into smaller parts was described oh so well in Thinking Forth, a masterpiece of programming literature that few people read as it seems to be about Forth only. Hint: It’s not. Only on the surface. Factoring is all the same, in every language you’ll ever use. But here it is, described in terms of Forth, a language that considers the difference between a single byte and a “cell” (read: Machine word) a type system. Seems like static typing isn’t that important for big teams after all.

On the other hand again, I LOVE ReSharper. Seriously. Nothing beats that feeling of being on top of it when you open a file of code and see the most common issues in it highlighted within a second. No chance here in a dynamic language like Tcl.

I’ll need to think topic about this a little more.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s