Density

July 6, 2009
By lispian

I’ve long been complaining — some would say bitching — about how verbose it is to code in many languages today. In many cases I am sorry witness to people programming in C/C++ or Java and writing thousands upon thousands of lines of code only to end up with a piece of code that coudl easily have been expressed in a denser language in a few hundred lines of code.

Today I came across a nice table produced by Larsson Omberg comparing the code required to do some value decomposition in Mathematica, Matlab, and Python. It’s from 2005 but much of this probably still holds for his example.  What we see is the following:

Mathematica: 276 lines of code
Matlab: 52 lines of code
Python: 71 lines of code

What we see is a density advantage of 5 times for Matlab and about 4 for Python over Mathematica. And Mathematica is already a dense language. Imagine coding the same solution in C/C++ or Java? We’d probably see at least twice as much code over Python for C/C++ and Java. That means the Mathematica code would be 10 times as dense, an order of magnitude. What that means is that on larger pieces of code you effectively 1/10th as many bugs, assuming the bugs/loc metric of 0.5 bugs/1000 loc is correct that means if you write less code you’ll have fewer bugs. Plus, you get the advantage of less coding = faster development. Less code = less bugs = faster quality assurance. In addition smaller code bases are easier to comprehend and you can use smaller teams, more savings.

If you want to see some people who’ve posted on bugs in code you can check out these pages I’ve read.

Overall, “less is more” or, more accurately, “less is better” is what we should be attempting to attain. One of my frustrations with computer science — other than that it’s not really a science, as Knuth rightly points out — is that we’re still more or less programming the same way we did in the 70s. There really hasn’t been any major leap forward. It’s still the same but instead of a small amount of code to get something done now you need thousands upon thousands of lines of code.

Perhaps I’m showing my age, but I would have thought by now we’d still only be programming small programs because the edifice that is computer science would provide us with ample libraries to leverage and languages dense enough for us to express our thoughts into efficiently. Instead, we just have glorified variations of C requiring inordinate amounts of typing. It’s just so sad.

Comments are closed.

Musings

A blog of my musings. Some folks find it interesting and so I continue. Hopefully it will remain fairly interesting. At worst, it'll keep me writing orthogonally to my day job.

 

July 2009
M T W T F S S
« Jun   Aug »
 12345
6789101112
13141516171819
20212223242526
2728293031  

StatPress

Visits today: 6
Total page views: 7509