Pythonic Java. Yes, or no?

Posted by OscarRyz on Programmers See other posts from Programmers or by OscarRyz
Published on 2010-12-27T20:07:28Z Indexed on 2010/12/27 21:00 UTC
Read the original article Hit count: 384

Filed under:
|
|
|

Python use of indentation for code scope was initially very polemic and now is considered one of the best language features, because it helps ( almost by forcing us ) to have a consistent style.

Well, I saw this post http://bit.ly/hmvTe9 where someone posted Java code with ; y {} aligned to the right margin to look more pythonic.

It was very shocking at first ( as a matter of fact, if I ever see Java code like that in one of my projects I would be scared! ) However, there is something interesting here. Do we need all those braces and semicolons? How would the code would look like without them?

class Person
  int age

  void greet( String a )  
    if( a == "" )  
      out.println("Hello stranger")
    else  
      out.printf("Hello %s%n", a )

  int age()  
    return this.age

class Main  
   void main()  
       new Person().greet("")

Looks good to me, but in such small piece of code is hard to appreciate it, and since I don't Python too much, I can't tell by looking at existing libraries if it would be cleaner or not. So I took the first file of a library named: jAlarms I found and this is the result: ( WARNING : the following image may be disturbing for some people )

http://pxe.pastebin.com/eU1R4xsh

Obviously it doesn't compile. This would be a compiling version using right aligned {} and ;

http://pxe.pastebin.com/2uijtbYM

Question

What would happen if we could code like this? Would it make things clearer? Would it make it harder?

I see braces, and semicolons as help to the parser and we, as humans have get used to them, but do we really need them?

I guess is hard to tell specially since many mainstream languages do use braces, C, C++, Java, C# JavaScript

Assuming the compiler wouldn't have problems without them, would you use them?

Please comment.

© Programmers or respective owner

Related posts about java

Related posts about python