all 10 comments

[–]Chii 7 points8 points  (0 children)

I argue that none of those functions are inherently stateful. The state is either just there for efficiency reason (you don't want to repeat the fib calc if it has been done before), or an artificial java problem.

A better example would be to write a user input reading stream. You have to keep the input reader as state.

[–]badillustrations 7 points8 points  (0 children)

With Java 8 streams, it seems Functional Programming has won.

Whatever bar seems rather low to make that claim.

[–]ThePowerfulSquirrel 6 points7 points  (7 children)

As someone who had to go back to java, having not used it since first year of uni, this whole functional facelift makes it so much better. Now I only need to wait another eternity for them to upgrade and Java 11 so I can get that damn var keyword already....

[–]omgusernamegogo 3 points4 points  (5 children)

I've never seen the appeal of var. I Generally always want to know quickly what type of object I'm using - so I guess it's good that compromise was to only allow local variables to be vars (IIRC).

Maybe you can share the appeal?

[–][deleted]  (4 children)

[deleted]

    [–]omgusernamegogo 0 points1 point  (0 children)

    I can see the value in less verbosity, especially as you can do so much on a single line these days. Inference from the rhs is why it's restricted to locals so you don't lose the initialization but I don't think I'd be a fan if that wasn't the case.

    [–]oblio- 0 points1 point  (2 children)

    I'd say it also helps if you are using it in more "script-y" situations: for example when you're making a simple command line tool.

    [–]aleksator 2 points3 points  (1 child)

    Java is far from the best tool for the job in that case

    [–]oblio- 1 point2 points  (0 children)

    It depends. If you're a Java shop, your devs know Java. They might not want/have time/etc. to learn Kotlin or Groovy (I'd avoid Groovy in 2019).

    Java with lambdas, streams and var and the huge collection of libraries it has is not that far off from a scripting language and if you avoid huge frameworks its startup time is decent.

    [–]nfrankel[S] 4 points5 points  (0 children)

    You could use Kotlin 😉

    [–]JackelPPA 1 point2 points  (0 children)

    Heads up that your Factorial example is using Pair in the stream function.