Inside BossConstructor: “MJava”

Over the course of the last years I have tried many different programming languages and honestly, none of them completely satisfied me as a programmer. While each language has cool and interesting features, they usually also have some annoying downsides. I could write about this topic for a long time, but at this point, allow me to simply sum it up as “For me, Java turned out to be the best bet.”.

Pros and Cons of Java
From my perspective, programming BossConstructor in Java offers several advantages:
– Very fast execution time (usually comparable with C++).
– Complete cross-platform compatibility (Linux, Win, Mac) without much additional though.
– Availability of many gaming-related libraries (OpenGL, OpenAL etc.).
– Possibility of creating browser-based Java applets.

What I dislike about Java is that it forces the programmer to write a lot of redundant code which does not contribute to the functionality of the actual program in any way. Consider this basic example:

Image

The first line repeats the class name, which is already given by the file name. In order to structure the code, both indentation and brackets are used. Finally, semicolons are required even if when most commands are single line.

Introducing “MJava”
In order to solve my “aesthetic problems with Java” while still being able to profit from Java’s features, I decided to write my own preprocessor. This preprocessor takes a .mjava-file and transforms it to a .java-file which can then be compiled by javac as usual. The whole process can be executed automatically using, for example, a makefile.

Image

So, how does a .mjava-file look like? Consider this basic example which is functionally equivalent to the above Java-code:

Image 

In addition to removing brackets and making the code more readable (in my opinion), “MJava” allows for several shortcuts to eliminate annoying and tedious code patterns:

Image

And these:

Image
Finally, the huge import blocks at the beginning of each file are no longer required. You can simply define one file which contains all the imports your project requires and everything will be included in all of your files automatically.

Conclusion
For me, creating and using “MJava” has proven to be very advantageous. The resulting code looks much cleaner and writing new classes and methods feels more fluent and intuitive. 
There are, however, still several bugs and lacking features. Block comments do not work (yet) and the MJava-preprocessor is very strict about indentation. Another problem is that syntax errors in a program lead to javac issuing compiler errors including line numbers which do not correspond to the actual .mjava-file, which can make identifying errors more difficult.

If you want to give it a try, please feel free to download and compile the preprocessor here and let me know what you think. The archive includes a simple hello world-program and a basic makefile:

https://dl.dropbox.com/u/1756025/MJava.zip