Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java and whitespace-as-syntax (ala Python)?

There is a part of java syntax that bugs the crap out of me: that's curly braces and semicolons. Is there some sort of translator that exists that will allow me to use all of the Java syntax except for this? I want to do something like this:

public class Hello:
    public static void main(String[] args):
        System.out.println("I like turtles.")

public class Another:
    public static void somethingelse():
        System.out.println("And boobs")

It's Python's whitespace as syntax model, I've grown to love it. I believe it's cleaner, and easier on the eyes. If it doesn't exist, I'm actually considering heavily investing time into writing a parser that would do this for me. (Ideally it will open it up, format it with whitespace, and when saved, save as just java syntax with braces and all)

Would this cause problems elsewhere in the language? What kind of hiccups can I expect to run into? I want to use all of the rest of the Java syntax exactly how it is otherwise, just want to modify this small niggle.

I can already write and read code just fine in Eclipse. And yes, I already know how to use code formatting tools and all the auto-complete options available to me, this is merely a preference in coding style so please don't answer with "You should learn to get used to it" or "You should use an IDE that does braces FOR you"...no. I don't want that.

like image 780
ThantiK Avatar asked Nov 22 '10 23:11

ThantiK


People also ask

How are Java and Python related?

Java is a statically typed and compiled language, and Python is a dynamically typed and interpreted language. This single difference makes Java faster at runtime and easier to debug, but Python is easier to use and easier to read.

Why does Python use white space?

Python uses white space for two things: newlines terminate logical lines, and changes in indentation delimit blocks. Both of these behaviors are somewhat contextual. Python distinguishes physical lines from logical lines. A physical line is an actual line of text: a string of characters, terminated by a newline.

Is Java the same as Python?

Java and Python are two of the most popular programming languages. Of the two, Java is the faster language, but Python is simpler and easier to learn. Each is well-established, platform-independent, and part of a large, supportive community. But that is where the similarities end.

What is semantic whitespace in Python?

Python's "semantic whitespace" is syntax that gives meaning to a common pattern in code. Most code that way by convention anyway. If that pattern has meaning then curly braces can be used for something else (in python's case: dictionary literals).


1 Answers

Can you switch to Jython? Python's syntax, Java's runtime environment.

like image 99
Russell Borogove Avatar answered Oct 03 '22 10:10

Russell Borogove