<< JPA 2.0 - New features - Part 1 | Home | Fair Trade Coffee in the Sydney CBD >>

JSR-666 Extension: Significant whitespace

Making life easier for the worlds squids

In many software development teams that I've worked on, code reviews are done by printing out the code to be reviewed. This is in turn read and scribbled on with red ink by developers suffering from a delusion that their coding standard is better than mine. An example of some such code:

public boolean equals(Object o)
{
   try
   {
      if (Calendar.getInstance().get(Calendar.MONTH) == 1
            && Calendar.getInstance().get(Calendar.DATE) == 29)
      {
         return true;
      }
      else
      {
         Thread.sleep(10000);
         return new Random().nextBoolean();
      }
   }
   catch (Throwable t)
   {
      // Something must have gone wrong, try again
      return new Random().nextBoolean();
   }
}

When reading the above code, the obvious problem that jumps out is that it contains no less than ten curly braces. When printed for a code review, this is a waste of valuable ink. The squids of the world have been working overtime to provide the ink needed to print out all the code that needs to be reviewed, it is about time we gave them a break. I'd therefore like to propose to the JSR-666 expert group an extension that curly braces be replaced with significant whitespace.

The previous code example would become:

public boolean equals(Object o)
   try
      if (Calendar.getInstance().get(Calendar.MONTH) == 1
            && Calendar.getInstance().get(Calendar.DATE) == 29)
         return true;
      else
         Thread.sleep(10000);
         return new Random().nextBoolean();
   catch (Throwable t)
      // Something must have gone wrong, try again
      return new Random().nextBoolean();

A fine piece of code that would pass any code review.

This feature will also solve a number of other problems, for example, it will eliminate the age old argument over whether braces belong on a newline or not. It will also force developers to write neatly structured code.

This feature will not require any JVM changes, but will require compiler changes. Existing code may need to be changed, however, if the existing code was well formatted to begin with, it should suffice to simply run the following command in vim:

:%s/\{|\}//g
Tags : ,


Re: JSR-666 Extension: Significant whitespace

I can't believe you're suggesting Java join the fascist ranks of Python in removing the artist's ability to instil beauty into his/her creations in whatever way they see fit. Shocked and outraged! Shocked and outraged I say!!

Re: JSR-666 Extension: Significant whitespace

Save the artistic formatting for Perl, it never gets printed out for code reviews anyway because no one can actually read it.  But when it comes to a choice between saving the squids of the world, or letting a Java developer live in a fantasy world where he or she is a penniless pauper under the guise of an artist, I say save the squids!!

Re: JSR-666 Extension: Significant whitespace

Hi James,
First of all - well done for keeping the fight alive for the poor little squids!

But still I want to say that Java needs curly brackets, although in your example here they were really redundant.

I am afraid that the squids will have to keep on squeezing :(

cheers

Re: JSR-666 Extension: Significant whitespace

As Alexander, points out there are still semantically significant curly braces in Java. Anonymous inner classes are one example. Good idea, though. Applying the cleanliness ideals of Python to Java would not be a bad idea. :-)

Add a comment Send a TrackBack