News for hackers. Stuff that matters.
Re:Java finally getting closures, method handles and traits ... by fingerprinter on Sunday January 23, 2011 @07:55PM (#2133830)
Background: I started programming Java in 1996 or somewhere around there. I was a huge advocate of Java over things like C/C++ for quite a long time and I believe in early 2000 it was the best choice. I no longer believe Java is the best choice for most projects as there are saner alternatives out there including Scala, Clojure and Jruby (for the JVM) and other languages/VMs altogether if you want out of the JVM.

Bottom line: Java seems dated.

Now, to my rant.

import java.util.*; interface Sortable<T, U extends Comparable<? super U>> extends List<T> { void sortBy(Extractor<? super T, ? extends U> e) default Impl.sortBy; static class Impl { public static<T, U extends Comparable<? super U>> void sortBy(Sortable<T, U> sortable, final Extractor<? super T, ? extends U> e) { Collections.sort(sortable, #{T a, T b -> e.extract(a).compareTo(e.extract(b))}); } } }

I HATE this code. This is an example of when Java went downhill to me and started to get really, really ugly. I always thought Java was verbose, but with generics and others things it started to get ugly. That was enough for me. I knew Python and Ruby and decided to go a different way. Found Erlang and Clojure started to mature on the JVM. Bye bye Java.

Re:Java finally getting closures, method handles and traits ... by nicpottier on Monday January 24, 2011 @01:57AM (#2134532)
Agreed.

I've been programming Java since the Alpha days and it is getting to the point where all the extended syntax is a bit outrageous.

The real problem is that most of these extensions are required to make Java more powerful, certainly generics / templating was a huge boon. But examples like the above make my eyes hurt.

I suppose my question is whether you can add all the features that make functional languages powerful while also retaining static typing. That's what Java is trying to do. In same cases the type safety is a huge boon to building a large system with many people working on it, in others something more dynamic allows you to be far more productive. I'm not sure you can have both and still have code anybody wants to write.

I haven't played much with Clojure yet, not sure if that is the best of both worlds.

Re:Java finally getting closures, method handles and traits ... by DennisP on Monday January 24, 2011 @09:33AM (#2135225)
> I suppose my question is whether you can add all the features that make functional languages powerful while also retaining static typing.

Of course you can. Look at Scala. (And on other platforms, F#, ML, and Haskell.)

Re:Java finally getting closures, method handles and traits ... by wlievens on Monday January 24, 2011 @03:48AM (#2134695)
I've read this criticism a lot, so I'm really curious:

How would you 'clean up' generics syntax in Java?

Re:Java finally getting closures, method handles and traits ... by kaffiene on Sunday January 23, 2011 @08:13PM (#2133872)
I've been writing Java for a while now. I've never seen nor written code anything like that. Heavy use of generics is usually hidden away in APIs and don't usually occur in non-trivial ways in normal code.
Re:Java finally getting closures, method handles and traits ... by kujawa on Sunday January 23, 2011 @08:22PM (#2133887)
You mean code that was interesting to write, and not just another fucking web template?
Re:Java finally getting closures, method handles and traits ... by Jach on Sunday January 23, 2011 @10:17PM (#2134108)
It's not that much of a hyperbole...

    Map<String, Map<String, Map<String, Map<String, String>>> > meta_data = new LinkedHashMap<String, Map<String, Map<String, Map<String, String>>> >();
    ....
    for (Map.Entry<String, Map<String, Map<String, Map<String, String>>> > schema : meta_data.entrySet()) {
I really would rather just type:

    meta_data = {}
    ....
    for schema in meta_data.iteritems():
Re:Java finally getting closures, method handles and traits ... by julian37 on Sunday January 23, 2011 @10:28PM (#2134130)
This has become a bit simpler with Java 7: http://weblogs.java.net/blog/forax/archive/2009/08/27/diamon...

EDIT: link to better article

Re:Java finally getting closures, method handles and traits ... by nevster on Monday January 24, 2011 @02:15AM (#2134568)
If you've got a structure like that, you've got bigger problems than the verbosity of the declarations!
Re:Java finally getting closures, method handles and traits ... by Jach on Monday January 24, 2011 @02:48AM (#2134615)
Oh come on, it's not that ridiculous to have a map only 4 levels deep. (Though I'll admit the code there is a patch-job over a much worse design that will all be refactored one day...) It's just ridiculous to express in Java. JavaScript's pretty much built on the idea of nested objects/maps.

    new Ext.Panel({
        width: 400,
        height: 400,
        title: 'Pie Chart with Legend - Favorite Season',
        renderTo: 'container',
        items: {
            store: store,
            xtype: 'piechart',
            dataField: 'total',
            categoryField: 'season',
            //extra styles get applied to the chart defaults
            extraStyle:
            {
                legend:
                {
                    display: 'bottom',
                    padding: 5,
                    font:
                    {
                        family: 'Tahoma',
                        size: 13
                    }
                }
            }
        }
    });
Re:Java finally getting closures, method handles and traits ... by nevster on Tuesday January 25, 2011 @01:34AM (#2138275)
That's fine. My point is, it's extremely uncommon to come across this kind of structure in Java-land. Typically, there'd be separate classes for these objects - so you'd end up with a Panel class with fields width, height, title, renderTo and items. Items would be another class with it's subsequent fields. And so on with no maps in sight.

You're example Java declaration doesn't seem to actually capture the Javascript code you've got there - ie each initial string does not map to another Map - in some cases it just maps to an integer or string.

By the way - I totally agree that the declarations of stuff in Java with generics is way too verbose.