Alternative Java-based languages

I feel like I’m in something of a rut with Java at the moment, as a language it’s feeling increasingly restricted and I’d like to try something new. Since I’ve got far too much existing code I’d rather not throw away, it’d be good to choose something which can call existing Java code easily.

Currently I’m still stuck in the past with 1.4, so ideally any alternative would also run on 1.4. Possible ideas are:

AspectJ
Looks interesting, and seems to have good support (particularly since it looks like it’s got good Eclipse plugins). Not sure what I think of the language though.

Nice
The language looks, uh, nice. But doesn’t seem particularly well supported. Has an Eclipse plugin but doesn’t look very complete.

Jython
Nice language, but lack of type safety gives me The Fear for anything non-trivial.

Pnuts
Java scripting language I’ve seen recommended a few times but havn’t actually tried. Anyone used this?

Java 1.5
Or maybe I should bite the bullet and just switch to 1.5. Doesn’t really address many of my gripes, but better than nothing. Mac people running 1.4 can just go and upgrade already. :stuck_out_tongue:

Any obvious/non-obvious ones I’ve missed? Anyone tried any of the above and have any comments or recommendations?

Cheers

Java can indeed be restrictive.

But when you want to move to something else, you might as well tell us
what you find restrictive, or we wouldn’t be able to name the proper alternative. :slight_smile:

I’m not entirely sure I know myself. ??? Ideally I guess I’d like some of the RAII from C++, and better handling of functions and interfaces. Stuff like multimethods and first class functions could probably reduce the copious amount of instanceof usage I’ve been straying into recently. Nice seems like it’s got the right ideas, perhaps I’ll give the eclipse plugin a try and see how well it holds up.

Unfortunately the bigger problem is that Java has about the best IDEs around, and anything else is going to be a step down by comparison.

I’ve been trying to walking away from Java for a while, just to find out inferiour IDEs which bounced me back right to Java.

After having coded PHP/CSS/DOM/DHTML/AJAX/etc/etc/etc at work, for a few months, I have felt the freedom, and at the same time, the bunch of horrific errors you get when typesafety is lost.

I’ve pretty much given up… there aint much besides Java with such good documentation, mature libraries and a good IDE. These three are required for productivity, in my opinion.

Are we stuck?

I’m going to buy a book about AspectJ on Amazon.com after I move just because I can get it for a few bucks plus shipping.

Personally, I would like something that’s just a little less verbose than Java but has roughly the same functionality. This would be no good if I couldn’t use libraries of code similar to the ones that come with the JRE. There are things that I can do without. I can even do without the AWT, but I need to have some way to at least create a graphical application window and switch between full-screen exclusive mode and regular mode. And I need to have sound support similar to Java’s.

Some examples of verbosity:

imports:

import java.awt.*;

I would prefer to just type “import java.awt;”

indentation:

public class A extends B implements C {
//indent here
public void method() {
//indent twice here
}
}

Since I usually have one main class per file, there’s no need for indentation within the class. In fact, I would rather have it be LIMITED to one main class per file (though inner classes would still be allowed). The syntax could just be:

public class A extends B implements C;

public void method() {
//indent only once
}

That may sound a little bit pendantic, but I’m indenting most of every file for nothing. If I have 3 nested for loops, my variable names take up all the space I have available after indentation. Some people would call this bad programming practice and tell me that my code is too complicated. I call this “why shouldn’t my code fit on the screen”.

In practice, I actually don’t indent the main class in the file, but Eclipse fights me on this by auto-indenting too far.

access modifiers:

In Java, I type:

public void methodA() {}

public void methodB() {}

public void methodZ() {}

In C#, I can type:

public {
void methodA() {}

void methodB() {}

void methodZ() {}
}

I would much rather type:

public:

void methodA() {}

void methodB() {}

void methodZ() {}

Granted, it’s not immediately obvious upon looking at a method in the middle what it’s access modifier is. In a class, I have all my public methods/classes/variables first, protected second, package third, and private last. I think that makes good sense and allows the access modifier blocks to be adequately descriptive.

no “final” required for parameters:

I have to type:

public void methodA(final int a, final int b, …, final int z)

to make it so I can’t set parameter variables equal to other values. This should just always be the case, no “final” required.

simpler enums:

This isn’t too important (and may be slightly off topic), but enums don’t need to have the capability to define different methods on each element of the enum. I think this kind of breaks enums a bit, but it does make them more powerful. I don’t normally use this capability.

I love enums, but I have a minor objection to them. If you define a static final variable in an enum class definition, you can’t use it in the enum element constructor calls. I define a separate class to store flag constants because of this. I don’t know if this can be fixed though because static variables are probably defined after enum elements so that the enum elements can be used in the variables.

simpler Runnables:

I understand that Runnable is an interface and has to be implemented this way. However, I don’t want to type:

Runnable myRunnable = new Runnable() {
public void run() {
//method here
};

It’s not that big of a deal. I just have to type it alot. There should be some abbreviation, like the following:

Runnable myRunnable = {
//method here
};

Essentially, I want to be able to define code blocks as variables, just like in functional programming languages. It’s basically C# delegates, though less verbose. For methods with parameters, I could type:

ActionListener myListener(ActionEvent event) = {
//method here
};

This would basically be a shortcut for one-method interfaces. The one-method interfaces would just be delegates instead.

I think that if we want a better language, we’ll have to write it ourselves. I just don’t have the skill or the time to do so.

scala seems nice

@fletchergames

It’s not a full solution, but Eclipse does help with a couple of these niggles.

Class indentation: The code formatter is pretty configurable. You can set it to not indent declarations within class bodies, giving the effect you’re after. Not sure what happens with nested classes though. (This is version 3.3 btw )

Declaring anonymous classes: Enter “Runnable myRunnable = new Runnable(” and hit ctrl+space. Eclipse will fill in the rest for you. If you’re extending a class you’ll get a popup to choose which methods to override.

Block modifiers for public/private etc: It’s six and half a dozen. You group your fields and methods by modifier, I group them by functionality. eg: a public method is followed by the private methods that it uses.

Import statements: I reckon you’ll need to just suffer the cost (?) of two additional characters, in order to distinguish between classes and packages. In your example, what happens if some wag sticks a class called “java.awt” on the classpath?
Besides, who still types import statements?

IMHO anyway.

@OT

Instead of trying something new in another language, that you feel will be an inferior experience anyway, why not push to do something you have never done in Java before? A different kind of app, something that challenges your skills in a particular area, etc.

Most of those things, which you say require typing too much, are fully or partially automated by modern IDEs (personally I prefer IDEA).

  • imports: The IDE adds them automatically. No manual typing has been needed for years.
  • indentation: The IDE can indent and reformat the code automatically. I don’t even think about code formatting when writing code (except when using JMock), because the IDE takes care of it automatically during typing or with the press of a key shortcut. If you don’t want to indent the top level class members, just configure the code formatter (requires only checking one checkbox in IDEA’s code style settings).
  • access modifiers: Having such access modifier blocks or sections would limit the ordering of the methods far too much and possibly reduce the code’s readability. No thanks. I prefer the methods to be in a logical order, not sorted by syntax.
  • no “final” required for parameters: In IDEA, enable the inspection “Assignment to method parameter”.
  • simpler enums: Java’s enums can indeed be quite complicated. It’s better to use them only in a simple way. Otherwise other people might have problems understanding your code.
  • simpler Runnables: Java is quite verbose, so having a shorter syntax might improve readability. Typing, however, is not a problem because the IDE does all of that. In IDEA I just write Runnable r = new <Ctrl+Shift+Space, Enter> and the rest is autocompleted.

Between my last post in this thread, and now, I’ve written a little java-dialect…

Featuring:
[o] coding without a surrounding class
[o] defining methods
[o] multi-line strings
[o] closure-like thingies
[o] inner classes
some code in this java-dialect

Janino is a great tool… this might keep me from switching to PHP for my TinyCode webserver-project. Multi-line strings are such a must-have.

[quote=“bleb,post:8,topic:30860”]
I checked this, and I already have the code formatter configured the way I want it to be. It works when generating code automatically and when adding new lines in the middle of a preexisting class.

For some reason, it doesn’t always work when using the refactoring tool to move code to a new class. I’ve encountered a few other nuisance cases when there’s a syntax error in the code, but I really can’t blame anyone for that.

I guess I really shouldn’t be complaining about this since it’s not so bad now that I use Eclipse. It’s really a matter of personal preference more than a language feature.

[quote=“bleb,post:8,topic:30860”]
I didn’t know about that.

I suppose most of things I mentioned really aren’t that big of a deal. They’re just things I like to gripe about.

That’s not a bad little dialect.

The thing I don’t like about PHP is that it looks like it should have nice features like type safety but really doesn’t. You can write classes in PHP, but they are somewhat lacking.

If you are feeling adventurous, you could try out JRuby ( http://jruby.codehaus.org/ ). Netbeans6 beta has support for it, and it is Java-based Ruby implementation that lets you interact with Java pretty easily. 8)

I don’t know. The more I think about it the more I think the only practical solution is the well-established method of intergrating a scripting language and flicking between the two based on whatever bit of functionality you’re writing. Unfortunately this tends to waste your time dealing with odd bugs and behaviour at the glue/interface layer, and while it might be an overall win, it’s not particularly pleasant.

Perhaps we can find something similar to CppHeresy but for Java and using Jython/Nice/Something instead of Python.

My personal wish list:

  1. Proper C++ style ‘const’ so I don’t have to keep creating Immutable interfaces.
  2. First class functions, so I can do signals and slots.
  3. Some form of RAII, so I don’t have to remember to do tedious tidying up code.
  4. Templates/generics to remove all those goat-awful casts from everywhere.
  5. Multimethods, to remove all the instanceof scattered everywhere.
  6. Free functions.

Things I really don’t want to loose:

  1. Language-level support for asserts.
  2. Robust type safety and exceptions with stack traces.
  3. Reflection.
  4. Garbage collection.

Ironically, the first list are mostly available in C++ (or you can get 90% of the way there with some creative hacking), yet the second list is totally absent from C++.

And performant I guess…

Looks to me like it would take a whole bunch of people, a few years to knock up v0.1

Ugh, I can’t say I like your dialect, sorry :o ::slight_smile:
Multi-line strings just makes things hard to read (just one example is that there’s no way to see how many spaces are there between lines). What’s wrong with a ‘+’ between lines? It’s clear and hardly more verbose.
What problems with java does your dialect solve?

Personally, I do more and more programming in Scala. It has lots of features mentioned here and its performance profile is equal to Java (or even better like in this particular raytracing benchmark)

The world as a whole would run a lot more efficiently if there weren’t so many frickin’ languages around!

I don’t see programming languages being all that different; more = fragmentation = bad.

[quote]The world as a whole would run a lot more efficiently if there weren’t so many frickin’ languages around!

I don’t see programming languages being all that different; more = fragmentation = bad.
[/quote]
You mean like all the Application Server and Web Framework choices in the Java world :wink: