Is Java/OOP Code That Simple? (stats)

Is Java/OOP Code That Simple? A Statistical Look

I haven’t written Java code in quite some time now, and knowing that my memory isn’t always accurate, I wondered, “Was my code really that simple?”

To verify everything I just shared, I searched three old Java codebases — all projects that were in production in their day. I did a simple search for the <.*> pattern — to find any data types like <String>, <String, Integer>, etc. — and found these percentages of occurrences within *.java files in those three projects:

USAGE %    LINES FOUND    TOTAL NUMBER OF LINES
-------    -----------    ---------------------
  0.2         118                74,200
  1.4         686                49,189
  1.2         313                27,083       

So out of about 150,000 lines of Java/OOP code, there are 1,117 lines with a <.*> pattern, for a total percentage of 0.74%. (Note that those line-count numbers include blanks lines and comment lines, so the actual percentages are higher.)

I then manually looked through all of those <.*> lines of output, and found that these were the two most difficult lines to read:

SortedMap<String, Integer> wordCountMap = new TreeMap();
public Class<?> getColumnClass(int columnIndex) {

Coming soon ...

So, without any further comment at this point, that’s a look at using data types in some Java/OOP code.

In just a few chapters we’ll start looking at some Scala code — specifically how to solve problems with Scala and pure functions. But before we get to that, I need to introduce a wee bit of background material that will help that approach make sense.