4 ms·
Java isn't my favorite language, but since I use it fairly often I would love to have functions be first class.
by hendzen 15y ago
Java isn't my favorite language, but since I use it fairly often I would love to have functions be first class.
- sage_joch 15y agoThe first thing I'd change about Java is to do away with checked exceptions. Yours would be a close second, though.
- frio 15y agoI'd add "with" statements. No more: Closeable dbConnection; try { dbConnection = CloseableFactory.getConnection(); doWork(dbConnection); } catch (CloseableException ex) { // log it or whatever } finally { // the really annoying, stupid, crufty boilerplate bullshit try { if (dbConnection != null) dbConnection.close(); } catch (CloseableException ex) { // it's probably already closed } } Instead, it'd just be with (Closeable dbConn = CloseableFactory.getConnection()) { doWork(dbConn); } (Assuming the "with" statement eats errors relating to the instantiation/closing of the Closeable, anyway). Bliss. And I know there's stuff like Google Guava's Closeables.closeQuietly(conn);, but still, a with statement would be awesome.
- benjiweber 15y agoIf only it already existed in Java http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html http://docs.oracle.com/javase/tutorial/essential/exceptions/...
- frio 15y agoWow. I hadn't looked at Java 7 much; I've been under the assumption adoption would be reasonably slow so haven't really dug into it yet. Cool!
- quanticle 15y agoI would add query expressions (like list comprehensions from Python or LINQ).
- tikhonj 15y agoYou, and everybody who has responded to you so far, should check out Gosu[1]. It takes Java syntax and (among other things!) adds first-class functions and lambdas, adds a with statement (called "using") and gets rid of checked exceptions. [1]: http://www.gosu-lang.org http://www.gosu-lang.org In addition to solving all the problems people here are complaining about, it adds type inference, mixin-type-things, a superior collections interface (map and friends) and a bunch of other nice features. However, the best bit (from a Java developer's perspective) is that it looks and behaves almost exactly like Java, just improved. Going from Java to Gosu is trivial but very nice.
- Sandman 15y agoThis looks very nice. From what I've seen, the only thing I'd change is the way it deals with exceptions. Specifically, I'm not very happy with this way of throwing exceptions (example taken from Gosu documentation on exceptions [1]): throw "x does not equal zero" and then later chatching them like this : catch( e ) { if( e == "x equals zero" ) { return( e + " handled locally." ) } I want to be able to specify the exact type of the exception, and catch them based on their type, instead of having to throw a generic error and then check using "if" statements whether it's expression is equal to a particular String or not. If I understood correctly, this is what Gosu is actually doing, right? [1] http://gosu-lang.org/doc/wwhelp/wwhimpl/js/html/wwhelp.htm#href=Gosu%20Reference%20Guide/exceptionhandling.10.3.html http://gosu-lang.org/doc/wwhelp/wwhimpl/js/html/wwhelp.htm#h...
- tikhonj 15y agoIf I remember correctly, you can catch exceptions by type; you just don't have to. The code looks like this: try { // Maybe throws IOException } catch (e : IOException) { // Handle it } I think this does exactly what you want. There's more documentation here[1] (the documentation format is a little annoying, unfortunately). [1]: http://gosu-lang.org/doc/wwhelp/wwhimpl/js/html/wwhelp.htm#href=Gosu%20Reference%20Guide/exceptionhandling.10.3.html http://gosu-lang.org/doc/wwhelp/wwhimpl/js/html/wwhelp.htm#h...
- 15y ago