Sunday, April 14, 2013

Groovy and Java class sizes in practice

The shared perception is that Groovy offers productivity gains over Java. So how many times is an average Groovy class smaller than Java? Here is how it works out at our company. At Carfax we have about 10 years of Java and 5 years of Groovy in our codebase. The entire dataset is 3 million lines of code. For this comparison I only included Java files which have been modified since the introduction of Groovy so as to account for how coding practices change over time. Summary of the results is in the table below (LOC stands for lines of code).

 JavaGroovy
total classes26,1355,681
avg. LOC9870
median LOC5738

Groovy files are shorter overall, but not by that much. Groovy classes are around 70% the size of Java classes. The one difference I was able to find is for the subset of small classes, under 300 LOC. Take a look at the diagram below.

Raw data:

LOCJava %Groovy %
0-93.110.7
10-198.719.0
20-2911.710.4

Notice how 30% of Groovy classes are under 20 lines of code, while it is only 12% for Java. It appears that useful Groovy classes can be smaller than in Java, which matches the "less boilerplate" perception of Groovy. It is surprising at how small an effect it actually has in practice. If you open up an average Groovy file in our codebase, it's not going to take much less screen space than Java.

No comments:

Post a Comment