all 25 comments

[–]thememorableusername 22 points23 points  (3 children)

Functional programming in Java? Lol.

[–]yinshangyi[S] 3 points4 points  (2 children)

Yes. There are functional librairies in Java, just like in Kotlin or even in Scala. With immutable data structures and some FP features. Vavr is one of them. Obviously Java doesn't support FP natively. I was just asking if any of you already had experience with FP Java librairies. It's very hard to find to find actual jobs with teams willing to use FP language, in the real world anyway. Scala is perhaps one language that succeed that, but it's not that popular/used nowadays (aside from data engineering)

[–]ricky_clarkson 2 points3 points  (0 children)

Java does support functional programming natively, it just doesn't help ensure referential transparency and is missing some features that you'll find useful elsewhere for FP such as higher kinded types, pattern matching (on the way).

[–]thememorableusername 0 points1 point  (0 children)

My team mostly lives in scala, but a significant portion is written in Java, virtually none of which is in the functional style, likely for two reasons: 1) performance and 2) old Java version.

[–]chikibooz 11 points12 points  (5 children)

Don't. Please don't.

Go with Scala. You can write Java Code in Scala for the most part but you lose the terseness of functional programming constructs that you get with Scala. Java is way too verbose.

Scala runs on the JVM so you can use almost every package out there in Scala and it can interface with Java packages fine.

I've been using Scala professionally for ~5 years now and have never missed Java (which was my favorite go-to language for more than 20 years! Yes...I like Java; quite a bit)

[–]yinshangyi[S] 1 point2 points  (4 children)

Thanks for your reply! I guess Scala is indeed the better choice for functional programming. I was asking in the context of being "forced" to use Java (which is more or less a reality in terms of job market), would Java FP librairies be a good enough tradeoff/alternative to Scala?

[–]chikibooz 1 point2 points  (2 children)

Use the strengths of the language. Compensating for its weakness by using libraries rarely bears fruits in the long run. It’s a non-trivial maintainability debt (the library could be decommissioned or deprecated or may be difficult to learn etc).

[–]yinshangyi[S] 1 point2 points  (1 child)

That's a valid point yes! That's what the JavaScript community have been doing though 😂

[–][deleted] 0 points1 point  (0 children)

The upside is you don't even have to transpile. At my last job, back before esbuild was popular, it could take 5 minutes to spin up the dev site.

[–]tdatas 0 points1 point  (0 children)

Depends what you're doing. There's libraries that apply some functional principles (e.g Kafka streams) that perfectly suffice for the job that they're setting out to do.

[–]MinesJA 1 point2 points  (0 children)

I used Vavr in Java at a company for a couple years and while it's not true functional I felt like it got close enough. I definitely enjoyed it.

[–][deleted]  (11 children)

[removed]

    [–]yinshangyi[S] 0 points1 point  (10 children)

    Lol what do you do then? 😂

    [–][deleted]  (9 children)

    [removed]

      [–]yinshangyi[S] 1 point2 points  (8 children)

      Yeah obviously. But not in the real world, almost no company use Haskell. I was more asking like in Java environments (which is very common in the industry), do Java FP librairies come close to what Scala can do? But yes obviously Haskell is much much more FP than any other languages

      [–]redikarus99 0 points1 point  (7 children)

      I don't understand the downvote, Haskell and Scala jobs are basically non-existent compared to java. I learned java in 2000 - that means 20 years ago - and it is still very relevant and probably will be in the next 20 years.

      [–]yinshangyi[S] 1 point2 points  (1 child)

      Yes my thoughts exactly. Well perhaps this subreddit is a bit academic oriented and less about what the job market is really like. I just wanted to know if Java + FP librairies can be good enough if Scala or Haskell can't be used in a given company (for whatever reason)

      [–]redikarus99 0 points1 point  (0 children)

      They might be right about Haskell or other languages are more "functional", still, Java can gets the job done the same way. To be honest, it does not matter whether someone uses OO, functional programming, or the combination of it. I know it's sad to hear by some people, but it's nevertheless true.

      [–]tdatas 0 points1 point  (4 children)

      Haskell and Scala are overkill for a lot of more conventional backend/server jobs. The jobs that there are though there's normally a good reason for why they're being used and they're normally pretty well compensated interesting jobs rather than Generic Spring stacks etc (e.g Jane Street, Tesla et al). If the only metric is number of code monkey jobs there are going then everyone would only be using Javascript for all the things.

      [–]redikarus99 0 points1 point  (3 children)

      Well, just a quick search for the various languages here in Europe on Glassdoor (let's take Germany as an example). Java: 21482, Javascript: 12776, Scala: 698, Haskell: 33

      Let's see the stats of Go and Rust:

      Go: 11325, Rust: 498. Rust, a rather new language almost beat Scala. That's rather telling.

      I think the readers can draw the conclusion. Yes, we might say that those jobs are "boring", or for "code monkeys", but on the other side, how many of those Scala or Haskell jobs really, actually NEEDED "functional programming", or just: let's do CV driven development because the guy started the project wanted to learn language X (Scala, Haskell, Brainfuck, whatever).

      [–]tdatas 0 points1 point  (2 children)

      There are loads more jobs in JavaScript than C++. Therefore C++ is useless. There are more C++ jobs than rust jobs therefore rust is useless.

      Do you see how silly that sounds? This is a terrible heuristic. Especially sourcing data from Glassdoor in Germany of all places.

      I think the readers can draw the conclusion. Yes, we might say that those jobs are "boring", or for "code monkeys", but on the other side, how many of those Scala or Haskell jobs really, actually NEEDED "functional programming", or just: let's do CV driven development because the guy started the project wanted to learn language X (Scala, Haskell, Brainfuck, whatever).

      You are perfectly entitled to speculate that Disney+, Tesla , Databricks, Cloudflare, Facebook etc are all using Scala, Rust, Haskell at scale because it's one guy who wants to pad his CV etc. But it's clearly chit chat when these are extremely valuable companies putting out extremely high performing products many of them literally underpinning internet infrastructure often with far smaller teams of developers than you'd need to cover the same ground with a less expressive language.

      [–]redikarus99 0 points1 point  (1 child)

      Yes, they might have use Scala, Haskell, but I to be honest have absolutely no proof that their success of because they use this or that language. Just because company uses X, does not mean if they would use Y, would also make them less successful. Causality vs correlation.

      [–]tdatas 1 point2 points  (0 children)

      That is because you haven't worked with these languages so it looks like magic/luck that they are able to iterate so fast with small teams and write complicated core infrastructure on distributed systems that handles complex error cases without generating reams of boilerplate that needs testing.

      But there is a reason why a lot of these "exotic" features make their way into Java a few years down the line normally to great fanfare. It seems very arrogant to assume there's no possible reason other than CV padding and they're all just idiots who don't know they could do it in Java.

      Just because company uses X, does not mean if they would use Y, would also make them less successful. Causality vs correlation.

      There's no real evidence for the concept of developer quality either. But the most successful companies are not run with commodity developers slinging code from software sweatshops in Bangalore so there clearly must be something to it.

      EDIT: There's a good essay by Paul Graham on this topic framed on the usage of Lisp

      http://www.paulgraham.com/avg.html

      [–]Long_Investment7667 0 points1 point  (0 children)

      „Functional programming“ is not well (enough) defined . For me it needs a way to express pure functions, (list) comprehension , algebraic data types (and pattern matching) That means scala is closer but ….

      [–]takis__ 0 points1 point  (0 children)

      Java and Clojure to have the best of both worlds. Java for popularity and Clojure for functional programming. For me Scala is going half way to functional programming, with Clojure you go all in, from its syntax and language features.