08-Jul-2007 19:06 | Comparison : Java and K

OK, I know nothing about the programming language K. So I won’t criticize K itself. What I want to talk about is the comparison of Java and K.

I don’t get it why people always think that if they need fewer lines to write a program in one language than in another that the said language is better than the other one. The comparison shows fairly clearly that this is no good metric for comparing programming languages. While the Java program takes up 37 lines of code and the K program only one, the K program is far worse to understand since it’s one line of curly parenthesis, other special characters and some variables. I can learn all those special characters for all those special functions I need only rarely. Do I want to do that? No! I prefer to know that a class contains a specific kind of functionality and that I can find those functions with the autocompletion support of my IDE if I need them.

I’d also surmise that refactoring the K program would be somewhat more difficult than refactoring the Java program. I prefer the Java program because of its better readability and extendability.

K has probably its fields of use where it’s far better suitable than Java. Definition of mathematical algorithms is probably one of them, but that’s not the point here. I have no need for a comparison of two languages that have totally different uses.

Please stop those “I can express this in X in 1 line of code where Y needs 100 lines of code, so X is the better language”. It’s boring.

Trackback (URL)
Comments

I don't know K but I think that LoC is _one_ relevant metric.

Paul Graham (http://www.paulgraham.com/gh.html) states (Hacker == great programmer):
"Perhaps great hackers can load a large amount of context into their head, so that when they look at a line of code, they see not just that line but the whole program around it. [...] (I cheat by using a very dense language, which shrinks the court.)"

I have programmed a little with Lisp, Python and Groovy and their desity makes a big difference to Javas verbosity.

I think there are different nuances to it. Assembler is very verbose if compared to Java. You are responsible for the move of every bit and byte in Assembler. You could also say that Basic is too verbose when compared to Java because it lacks concepts that we work with when developing software for our customers. You have to work around those limitations and end up with a bigger program than if you had written it in Java.
But here comes the other extreme: If you define a language that has some construct for each situation that may arise while developing, you get a very bloated language. You have to learn much and gain little.
A hacker can write a program in that language that takes up only one line, but only few other people will be able to read that program without leafing through the spec. And sometimes the hacker who wrote the code will have to think twice before he can tell what his one-line program does.
I think the first metrics should be: readability, ease of refactoring, suitability to the problem at hand. When you compare two languages and both are equally good at those metrics, only then I would use the LOC metric.
But taking LOC as the only or first metric, is IMHO the wrong way. You can say "Look, my program uses fewer lines of code" and I say "Lets meet in a month" and talk about changing requirements and refactorings". So in my point of view, all those LOC comparisons are ridiculous. If for example the K-guy had proven that K is also better in those other metrics, I would have said "Look K is better readable, it's good in refactorings and it's suitable for the software we normally write (which is individual software for banks, insurances etc.) and as an addition the language is so mighty that I need only a fraction of code I normally have to write. Let's dump Java and take K."

Leave a comment