On my last post I compared several programming languages based on the number of keywords they define and how many are needed, and not needed, in your code to build a simple OO program. We will see now how they compare on “Lines of Code”, but before that, let’s begin with some wiki-Definitions (taken from: http://en.wikipedia.org/wiki/Source_lines_of_code):
“Source lines of code (SLOC) is a software metric used to measure the size of a software program by counting the number of lines in the text of the program's source code. SLOC is typically used to predict the amount of effort that will be required to develop a program, as well as to estimate programming productivity or effort once the software is produced.”
Advantages:
1. Scope for Automation of Counting: manual counting effort can be easily automated.
2. Intuitive Metric: due to the fact that it can be seen and visualized.
Disadvantages:
1. Lack of Accountability: not really useful to measure productivity of a project only with results from the coding phase.
2. Lack of Cohesion with Functionality: program developed using less code can have better features.
3. Adverse Impact on Estimation: because only based on the coding phase, estimates can adversely go wrong.
4. Developer’s Experience: lines of code differ from person to person due to experience.
5. Difference in Languages: lines of code differ from language to language due to language design and features. It will require different effort depending on the language.
6. Advent of GUI Tools: GUI tools allow writing little code and achieving nigh levels of functionality. Those tools also automatically generate code (which shouldn’t be considered in the metric)
7. Problems with Multiple Languages: today’s software is developed in multi-language scenarios, hence it is difficult to attribute productivity and defect rates on them due its integration.
8. Lack of Counting Standard: no standard of what a line of code is (comments? Statements? Multi-line Statements, etc.)
9. Psychology: programmers get an incentive to write unnecessarily verbose code if measured by lines of code.
Measure programming productivity or effort is not really the objective of this post. What I wanted to show you is; how programming languages compare between them based on the number of lines you need to code to achieve exactly the same piece of code (OO Hello World), following exactly the same rules (same program structure, language standards conventions), and using the same features (same paradigm, no idiomatic code). Said that, let’s see the numbers.
Version 1 (Minimal)
|
Version 2 (Verbose)
|
Both (Minimal and Verbose)
|
THE CONCLUSIONS
How many lines of code you write is mostly guided by programmer's personal preferences unless some guidelines specify the contrary.
In this comparison, the functional languages F# and Scala are the ones with less lines of code, followed by the Scripting languages such as: Python, Ruby, Groovy and JScript.
Languages that support scripting capabilities are normally shorter than those that don't since no main method/class and extra blocks are required.
Programming languages using opening and closing curly brace { } as blocks usually requires more lines of code (or at least in my example) since the closing bracket counts as a new lines. You can see this between Java and C#:
http://carlosqt.blogspot.com/2010/06/oo-hello-world-c.html
http://carlosqt.blogspot.com/2010/07/oo-hello-world-java.html
Delphi Prism is again the one at the top of the list , as you can see both, the minimal and verbose versions of the code, differ only by 1 line. No doubt Delphi Prism is the most Verbose programming language in Keywords and Lines (of the 19 languages I'm comparing). Definitively, the separation of implementation and interface is what makes the difference! Just compare it with Zonnon and you will see what I mean.
http://carlosqt.blogspot.com/2010/06/oo-hello-world-delphi-prism.html
http://carlosqt.blogspot.com/2010/06/oo-hello-world-zonnon.html
VB.NET smaller than C#? Yes, unless opening curly brace { starts at the beginning block line.
http://carlosqt.blogspot.com/2010/06/oo-hello-world-c.html
http://carlosqt.blogspot.com/2010/06/oo-hello-world-vbnet.html
Bytes!
No comments:
Post a Comment