Slashdot Mirror


Your Java Code Is Mostly Fluff, New Research Finds

itwbennett writes In a new paper (PDF), researchers from the University of California, Davis, Southeast University in China, and University College London theorized that, just as with natural languages, some — and probably, most — written code isn't necessary to convey the point of what it does. The code and data used in the study are available for download from Bitbucket. But here's the bottom line: Only about 5% of written Java code captures the core functionality.

2 of 411 comments (clear)

  1. Nonsense by Anonymous Coward · · Score: 4, Interesting

    the code written, in the summer of 2012 the researchers downloaded 1,000 of the most popular Java projects from Apache, Eclipse, GitHub, and SourceForge. From that they got 100 million lines of Java code and tossed out simple methods (those with less than 50 tokens).

    So they tossed methods that were wrtten well. (methods that only do one thing) So if you wrote a simple 2 line validation of an input field. Field must be populated. Field must match regex. They tossed that as chaff?

    1. Re:Nonsense by lgw · · Score: 5, Interesting

      So they tossed methods that were wrtten well. (methods that only do one thing) So if you wrote a simple 2 line validation of an input field. Field must be populated. Field must match regex. They tossed that as chaff?

      Why the Hell should you have to write code over and over to validate that a reference isn't null, or an int is positive, or other such cases. Sure that's all part of the interface contract anyhow, right? For that matter, why is "allowed to be null" the default rather than an exceptional special case. Why isn't there a simple operator that decorates a parameter as "nullable" with a single character.

      Why not simply

      public Foo foo;

      No getter or setter needed, by default it can't be null. For those odd cases where null actually means something useful, then just write:

      public Foo? foo;

      This goes double for C#, where "?" is already established as the "nullable" decorator.

      Worth noting that many Java coders use Lombock to effectively achieve this already, just with auto-generated getters and setters, since we lack the courage ad/or authority to just have public members instead of pointless getters and setters.

      And, above all else, give us a way to declare that the returned value can't be null, and auto-throw if it is, so the caller never has to check!

      --
      Socialism: a lie told by totalitarians and believed by fools.