News for hackers. Stuff that matters.
Re:Java 12 by _bxg1 on Tuesday March 19, 2019 @05:44PM (#19436299)
Java has evolved pretty far past its strict OOP roots. I haven't kept up with the last few versions, but it added lambda functions way back in Java 8, for example. There's definitely syntactic baggage holding it back in some ways, but it's added lots of features for more modern functional-programming styles (one mentioned in this release is expression-style switch statements).

More importantly, the JVM ecosystem is much bigger than Java itself. The JVM is a highly-optimized, cross-platform, garbage-collected environment on which people have built much more progressive languages that lack the syntactic baggage of Java: Scala, Groovy, Clojure, Kotlin. Clojure is one of the most popular and performant Lisps we currently have, and Scala is one of the closest things we'll get any time soon to a practical version of Haskell. Both of these projects got to avoid building their own garbage collectors, which is an enormous lowering of the effort barrier. And to top it all off, all of these languages' binaries are interoperable, which not only allows you to use different ones for different parts of the same system, but makes it much easier to gradually migrate your legacy codebase to a newer, better language.

I don't know if I'd start a new project in Java-the-language, but it's far from a Cobol situation.

Re:Java 12 by vorg on Tuesday March 19, 2019 @06:28PM (#19436726)
> The JVM is a highly-optimized, cross-platform, garbage-collected environment on which people have built much more progressive languages that lack the syntactic baggage of Java: Scala, Groovy, Clojure, Kotlin.

Apache Groovy has inherited all of the syntax of Java. When Jeremy Rayner built the Antlr 2 based syntax for Groovy back in 2005, he began with the syntax for Java, then added the Groovy-specific grammar to it. The latest version of Groovy still uses that syntax, so if Java has syntactic baggage, then Groovy has it too.

I'm picking Groovy will still have that baggage-laden syntax for a while yet. 2 yrs ago, Daniel Sun built an Antlr 4 based replacement grammar, but the Groovy project managers at Apache are taking their sweet time in rolling it along. They even had its optional preview removed from the version 2.6 beta of Groovy.

Re:Java 12 by _bxg1 on Tuesday March 19, 2019 @07:05PM (#19437066)
I wasn't aware of Groovy's roots, but that doesn't diminish the point. It elected to take on Java's baggage; the JVM didn't impose it.
Re:Java 12 by spricket on Tuesday March 19, 2019 @09:30PM (#19438032)
No idea that Groovy was designed by the guy of Antlr fame... Pretty humbling TBH.

Check out Kotlin though. It's seriously great and doesn't share lost of the performance penalties of Groovy

Re:Java 12 by olavgg on Wednesday March 20, 2019 @09:12AM (#19441699)
Groovy with static compilation is very fast and memory efficient. In most cases it is equal to Java. Though you are supposed to use Java and Groovy together for maximum performance and developer productivity. Groovy is not a replacement for Java, but rather an extension
Re:Java 12 by ptx on Wednesday March 20, 2019 @06:11PM (#19447521)
What makes Groovy unsuitable as a replacement for Java, if the performance is now comparable?
Re:Java 12 by zmmmmm on Thursday March 21, 2019 @06:10PM (#19457868)
For the masses, imho, all round Groovy just isn't polished enough and is too complex. We are bringing someone up to speed now and there is an enormous amount to teach. There are a range of pitfalls that you have to alert them to. Mind you, a lot of other Java replacements are like that (eg. Scala).

Particularly though, the static compilation is just not comprehensive enough. It tries to do type inference but it's limited and invariably you end up having to add type casts in ugly places to convince it that expressions are valid. Occasionally it actually flat out refuses to compile something valid and you have to find a different way to do it. Sometimes it compiles with one version of groovy and then is broken in the next. It works great though to selectively add to hotspots of code and in other places to speed them up and define them better.

Having said that, we are essentially using Groovy as a java replacement and for our team I think the above costs are well worth it. This is partly because we have a heterogenous application that is partly dynamic in its nature and Groovy's dynamic scripting ability is amazing for this. The fact we can code our whole back end in the same language makes it super easy and well integrated.

Re:Java 12 by zmmmmm on Wednesday March 20, 2019 @06:06AM (#19440551)
> doesn't share lost of the performance penalties of Groovy

That's a bit of a myth these days. Groovy may even be more performant than Kotlin when used with static compilation.

Re:Java 12 by dmux on Wednesday March 20, 2019 @10:17AM (#19442412)
The new parser is available in the Groovy 3 alphas.
Re:Java 12 by vorg on Wednesday March 20, 2019 @03:54PM (#19446173)
The Apache project managers removed the new parser from the Groovy 2.6 betas over 6 months ago after officially canceling it and saying Groovy 3 would be the next release. But no real work has been done on Groovy 3 since then. I'm guessing they really intend releasing version 2.6 some time in the future. Perhaps they'll say "Groovy 3 is still far off and Groovy needs another release, so let's resurrect Groovy 2.6". Don't expect to see Groovy 3 move beyond alpha version anytime soon.
Re:Java 12 by boksiora on Tuesday March 19, 2019 @07:12PM (#19437120)
thank you for this comment. it brings a lot of light on the ecosystem
Re:Java 12 by ilovecaching on Tuesday March 19, 2019 @06:11PM (#19436581)
It seems to be a popular notion that adding constructs common in FP is somehow a modernization of C++ or Java. FP isn't a set of features, it's a style of programming. It's actually a bad idea to try to retrofit a paradigm on top of an existing language. You should build tools that do one thing well, and if they no longer suit your style of programming, you should switch to a tool that is designed to fit your needs.

A lot of my reasoning was criticizing the JVM itself, not Java. VM languages add unnecessary complexity in the post container world where ephemerality and kernel APIs (containers) can give the same advantages, although I think Kotlin and Clojure and remarkably good languages.

Re:Java 12 by coldtea on Tuesday March 19, 2019 @06:15PM (#19436627)
>It seems to be a popular notion that adding constructs common in FP is somehow a modernization of C++ or Java. FP isn't a set of features, it's a style of programming.

And historically, nobody cared for that style of programming in its pure form (where "nobody" is in the casual sense: a few FP-lovers, but not the 95% of working programmers).

From 1960 to today it remains niche in its pure form, even the most popular language following it fully (e.g. Clojure or similar) is still a niche language.

We found out, on the other hand, that people care for mixing that style of programming with OO, imperative, reactive, and other styles.

And that's what modern JS, Java, C#, Rust, etc (even C++) give us.

And since FP is a style, it can be followed quite effectively in almost any language -- as long as it has some basic features, which, as you observed, Java has added.

Re:Java 12 by willtim on Tuesday March 19, 2019 @07:28PM (#19437268)
> And since FP is a style, it can be followed quite effectively in almost any language.

It's not black and white. FP is more like a spectrum, with pure functional programming more towards the opposite end, just before total functional programming. Put another way, adding lambdas to Java does not make it like Haskell. Even Scala cannot effectively be used as Haskell substitute, as some in that community eventually realised.

It remains to be see how much of FPs benefits (composition, abstraction, reasoning) can be fully realised in languages with rampant side-effects and mutation.

Re:Java 12 by ilovecaching on Tuesday March 19, 2019 @06:24PM (#19436682)
Pedantically, you can't just redefine a term to suit your need calling something "pure" or "unpure". There are many other styles of programming that are data oriented and are a better definition for Rust and some circles of Javascript than functional, but ergonomics of composition and partial application leads to something far short of FP.

> We found out, on the other hand, that people care for mixing that style of programming with OO, imperative, reactive, and other styles.

Which is why you forgot to mention Scala, which shows us how great such a promise land can be when we try to please everyone.

> JS, Java, C#, Rust, etc (even C++) give us.

Out of the languages you mentioned, only certain circles of Javascript (React) and Rust are arguably functional as I mentioned above. Javascript has been a real exception to the rule in how its lack of real class support left a vacuum for some FP. C++, C#, Java, and the majority of Javascript are object oriented and always will be.

Re:Java 12 by iainmerrick on Tuesday March 19, 2019 @06:41PM (#19436855)
Pedantically, you can't just redefine a term to suit your need calling something "pure" or "unpure".

No, I think they are using those terms correctly. In FP, “pure” means absolutely no side-effects. So if you add an FP-style library to an existing imperative language, that’s “impure”.

Re:Java 12 by ilovecaching on Tuesday March 19, 2019 @06:53PM (#19436962)
That's not the context in which the word was used, but it's a fair point. I have worked professionally with Haskell, and while I am not good at it (my forte is Erlang which is what I would consider "close to functional"), other developers I have worked with were very good, and watching them code in non functional languages and listen to how they thought about solving problems is were I developed the idea that adding a few features doesn't make a language functional.
Re:Java 12 by _bxg1 on Tuesday March 19, 2019 @07:01PM (#19437034)
> It's actually a bad idea to try to retrofit a paradigm on top of an existing language. You should build tools that do one thing well, and if they no longer suit your style of programming, you should switch to a tool that is designed to fit your needs.

I categorically disagree. Nearly any program has pieces that benefit from OOP and pieces that benefit from FP and everything in-between. The most prevalent and useful languages support multiple paradigms (C++ is a mess for other reasons).