Home > Uncategorized > How are C functions different from Java methods?

How are C functions different from Java methods?

According to the right plot below, most of the code in a C program resides in functions containing between 5-25 lines, while most of the code in Java programs resides in methods containing one line (code+data; data kindly supplied by Davy Landman):

Number of C/Java functions of a given length and percentage of code in these functions.

The left plot shows the number of functions/methods containing a given number of lines, the right plot shows the total number of lines (as a percentage of all lines measured) contained in functions/methods of a given length (6.3 million functions and 17.6 million methods).

Perhaps all those 1-line Java methods are really complicated. In C, most lines contain a few tokens, as seen below (code+data):

Number of lines containing a given number of C tokens.

I don’t have any characters/tokens per line data for Java.

Is Java code mostly getters and setters?

I wonder what pattern C++ will follow, i.e., C-like, Java-like, or something else? If you have data for other languages, please send me a copy.

Categories: Uncategorized Tags: , , ,
  1. Nemo
    February 4, 2020 14:05 | #1

    What is the time line of the data? The style of Java written at first release was rather different than recently written Java.

  2. February 4, 2020 17:31 | #2

    @Nemo
    The paper they came from was published in 2016, so I’m guessing the source is from 5-10 years before then.

    The use of language constructs changes as new features are added to the language, but it takes many years for this to happen.

    Does something as basic as nesting level change? I cannot think of any reason why it should, but data continues to regularly disagreed with what I think.

  1. No trackbacks yet.