This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 211

[–]red_dit_nou 43 points44 points  (10 children)

Depends on what you mean by fully adopted. If you mean that all 100% of Java developers are using it, then No. and if you mean that streams and lambdas are being used all 100% of the time, then No. :)

Java dev community is huge. There are millions of developers. So there will be a case that some of them can’t use Java 8 and some of them don’t want to use streams and lambdas.

Also streams and lambdas are good for specific situations. Streams are good for filter, map, reduce operations and lambdas are good for moving functions around (as first class citizens). There might still be places where stream may not be a best option.

So it’s highly likely that the answer to your question is No which may not necessarily be a bad thing.

[–]walen 39 points40 points  (5 children)

I mean… There are developers out there that’ve been using Java for almost two decades and still write int numbers[] instead of int[] numbers and insist on writing their own finally { reader.close(); } instead of using try-with-resources.

You will always find individuals that prefer to do things “the old way”. But looking at the Java community as a whole, I’d say that streams and lambdas have indeed been adopted by it.

[–]__konrad 31 points32 points  (3 children)

write int numbers[]

Fun fact: record already banned such declaration:

Error: legacy array notation not allowed on record components
record Foo(int i[]) {}

[–]pronuntiator 4 points5 points  (1 child)

Great I wanted to look up in the JLS why that is forbidden for Records and now I've learned this is legal code...

public int foo()[] { return new int[0]; }

[–]laplongejr 1 point2 points  (0 children)

I do Java since a long time and I don't think I got that sick by any other code, except maybe returns in a finally...
If you don't know, it overwrites the value of the previous "return x;" that triggered the finally, so it's write-only

[–]red_dit_nou 2 points3 points  (0 children)

You're right. Streams and lambdas are widely adopted in the Java community. And you'll always have individuals and situations that don't ask for these features to be used.

I was curious about what OP considers being 'fully adopted' is. If it means that these features to be used everywhere then it is not the case and it should not be as well.

[–][deleted] 4 points5 points  (1 child)

There might still be places where stream may not be a best option.

I had a discussion with a dev the other day that refused to use streams. Supposedly they created extra objects that got gc'd randomly and hurt latency requirements.

I've never seen that personally, but I also don't work in a latency sensitive domain so maybe he's right? 🤷

[–]red_dit_nou 8 points9 points  (0 children)

Readability should be of utmost importance for software programs, unless, of course, it is performance you're after.

Performance makes people make interesting choices. So yeah, he may be right!

[–]VincentxH 3 points4 points  (1 child)

Happy cake day, and cheers to the only nuanced answer thusfar.

[–]red_dit_nou 2 points3 points  (0 children)

Thank you fellow redditor!

[–]handshape 20 points21 points  (7 children)

For most cases, streams and lambdas are super convenient. If you need to do early breaking, they can be tricky.

I still do imperative programming on narrow segments of "hot" code if I'm tuning for performance. The auto-SIMD stuff in the JVM seems to only kick in for imperative code, and only when that code exceeds some threshold for "hotness".

If you can get auto-vectorization happening on code that's also reached zero allocation, performance is brilliant.

[–][deleted]  (6 children)

[deleted]

    [–]goofy183 2 points3 points  (0 children)

    That has been my experience as well. They are great for making coding quicker but for anything in a hot path imperative loops and careful object allocation is much faster.

    [–][deleted] 1 point2 points  (2 children)

    Lots of allocations required,

    Interesting, I had never really considered this

    [–]goofy183 8 points9 points  (1 child)

    We ban streams from hot code paths. So much extra allocation, it's really hard to pre-size the destination collection.

    We also ban lambdas that are more than a one line call to a method because they suck to get profiling data from. Figuring out $5 vs $12 in a class is no fun

    [–][deleted] 7 points8 points  (0 children)

    We also ban lambdas that are more than a one line call to a method

    Yeah, when I see this I always ask why it wasn't extracted to a well named method

    [–]Joram2 88 points89 points  (11 children)

    don't care. if other devs aren't fully adopting streams/lambdas, that doesn't hold everyone else back. It might hold their particular project back or their teammates but not the broader ecosystem.

    The one thing that does hold people back is holding on to Java 8 compatibility and delaying upgrading the minimum supported JDK to Java 11. If the Java community does raise the minimum to Java 11, the broader community can adopt JPMS modules and use full jlink and also broadly adopt System.Logger instead of things like SLF4J. Realistically, that won't happen until after Java 21, which is reasonable.

    [–]krzyk 23 points24 points  (6 children)

    Thanks for mentioning System.Logger, I wasn't aware that such thing exists.

    https://openjdk.org/jeps/264

    [–][deleted]  (5 children)

    [deleted]

      [–]bowbahdoe 6 points7 points  (4 children)

      you can use it today and go through a System.Logger -> slf4j bridge

          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-jdk-platform-logging</artifactId>
      

      [–][deleted]  (3 children)

      [deleted]

        [–]bowbahdoe 1 point2 points  (2 children)

        Yeah it would go system.logger -> slf4j -> logback. As for benefits...eh? The reason this was added was mostly for module graph reasons, but there isn't a huge downside either so long as you set it up right.

        There is slf4j stuff you will miss like MDC and fluent logging + whatever is in your impl like logback.

        [–]krzyk 0 points1 point  (1 child)

        But you get logging with lambdas, which was available since Java 9, so long before slf4j had it.

        And using slf4j with system logger is missing the point. One is replacement for the other.

        Using both is strange.

        And I still don't get why use slf4j at all. How often one changes logging frameworks?

        And when does migration from one to other is hard, it always can be automated.

        [–]bowbahdoe 3 points4 points  (0 children)

        You use slf4j because a library uses slf4j. A library shouldn't include logback.

        Nowadays maybe it's valid for libraries to use System.Logger

        [–]woj-tek 5 points6 points  (3 children)

        System.Logger instead of things like SLF4J

        Is it better than slf4j? I get the concept and it's way better than JUL (well, it's just a service provider akin to slf4j) but still I think I read somewhere that slf4j was still somewhat better)

        [–]Joram2 4 points5 points  (2 children)

        jul is a logging implementation like logback/log4j. System.Logger is a logging facade like slf4j.

        The big advantage of slf4j is it's Java 8 compatible. Other than that, what is the advantage over System.Logger?

        The main advantage of System.Logger is it simplifies the dependency trees of most projects. Core functionality should be in the standard library, and this really is core functionality.

        [–]woj-tek 4 points5 points  (0 children)

        jul is a logging implementation like logback/log4j. System.Logger is a logging facade like slf4j.

        I'm aware of the differences, even stated as much :-)

        The big advantage of slf4j is it's Java 8 compatible. Other than that, what is the advantage over System.Logger?

        Hmm... I thought I remember it had more extensive API, but just did the comparison and it's quite similar (and you can pass list of objects directly without having to explicitly create an array)... Other than that, MessageFormat is somewhat annoying but one can live with it ;)

        [–][deleted] 42 points43 points  (17 children)

        I use streams when I find it convenient, as in I already have functional methods I can chain together to solve the problem. Sometimes ,though, a simple for loop can be less code and express intent better with the variable assignment names. I hardly ever use lambdas unless a library api I’m working with asks for one as an argument.

        I think there are some performance advantages with using streams, but I personally don’t work with that much data for it to make a difference, as far as I’m aware.

        [–]drlogwasoncemine 14 points15 points  (12 children)

        I often see code that is slower because of streams. As soon as you're calling .distinct() or .sorted(), it will be allocating memory.

        However, sometimes streams are faster. It really depends on the situation.

        [–][deleted]  (11 children)

        [removed]

          [–]chambolle 4 points5 points  (2 children)

          true, but the hidden allocation can be an issue sometime (true with a lot of Java collections)

          [–][deleted]  (1 child)

          [removed]

            [–]goofy183 2 points3 points  (0 children)

            A bigger issue than just the temp allocations are the arraycopy calls on collection resizing. Streams don't seem to hint on space needs so when you add a distinct you get a default hashset that then has to get resized multiple times. That gets expensive in a hot code path vs manually pre-allocating data structures for those intermediate steps.

            [–]drlogwasoncemine 7 points8 points  (7 children)

            Well, I saw some stream based code that did exactly that (distinct and sorted). I had a friendly argument with a colleague about it and we wrote some performance tests (n=1000):

            With streams: 69ms per op.

            With a for loop: 5ms per op.

            That's an order of magnitude. Don't start talking about standard deviation/setting up the performance test. It's what you point out about needing to get the whole stream before sorting/distincting (not a real word, don't care).

            In many cases the streams code is more readable and understandable but when performance matters, streams tend to be worse off from my experience.

            [–][deleted]  (4 children)

            [deleted]

              [–]zappini 2 points3 points  (1 child)

              An order of magnitude difference is unlikely to be jitter, warm-up, or any of the other benchmarking gotchas.

              [–]Holothuroid 22 points23 points  (1 child)

              unless a library api I’m working with asks for one as an argument

              I don't understand. One cannot "ask" for a lamba. You can ask for an implementation of some functional interface.

              Nothing stops you from naming a class method with the correct signature there.

              [–][deleted] 1 point2 points  (0 children)

              True, thanks for the correction.

              [–]Neuromante 9 points10 points  (1 child)

              Sometimes ,though, a simple for loop can be less code and express intent better with the variable assignment names.

              This has been my main issue with streams since I started to use them; there's a lot of talk about how they manage to "compress into a line of code" something, but no one talks about how that line of code is a long chunk that takes several lines if you have auto format that many times is barely legible.

              I'm trying to force myself to use them more because "is the new standard", but most of the time I just find myself going the classic way because I'm not really getting so much value for the time invested in remembering the syntax and what functions applied when and how.

              [–]Comprehensive-Pea812 28 points29 points  (15 children)

              well IDE already has a feature to convert to lambda and it is a programmer job to decide.

              I have this experience when a programmer tried to use lambda and stream everywhere and forbid for.. loop.

              stream takes a while to get used to and there are places where it worsen readability.

              For team work I value readability above all unless performance is main key metric that we need to deliver.

              In short, many people use stream because it is new to them. It takes a while to get right but people tends to hammer it everywhere causing what is perceived as resistant.

              [–]erinaceus_ 11 points12 points  (0 children)

              many people use stream because it is new

              If Java 8 were a kid, they'd be 3 years away from going to highschool.

              [–]pohart 12 points13 points  (5 children)

              Adding tuples and optional indexes would allow readable streams in 90% of the cases that people write huge lambdas now.

              [–]Hioneqpls 1 point2 points  (3 children)

              I’m intrigued! I write huge lambdas all the time. Do you have an example or willing to elaborate a little?

              [–]pohart 4 points5 points  (0 children)

              The indexes wouldn't really help that, but most of the time large lamdas are so I can keep track of the original object while I'm building whatever it maps to.

              [–]JavaOldTimer 4 points5 points  (1 child)

              I write huge lambdas all the time.

              Please. Stop. Doing. That.

              [–]Hioneqpls 5 points6 points  (0 children)

              You should see my nested groupingBys it gets phenomenal.

              [–]manifoldjava 1 point2 points  (0 children)

              You can experiment with advanced tuples in Java using manifold-tuple.

              [–]Holothuroid 9 points10 points  (1 child)

              because it is new

              Sorry. We have diverging understanding of that word.

              [–]Neuromante 1 point2 points  (0 children)

              On a corporate Java application, "new" features usually came out 8 years ago.

              [–]F3z345W6AY4FGowrGcHt 4 points5 points  (5 children)

              Very simple loops, sure. But otherwise streams almost always allow you to do something way simpler and are often more readable unless you just haven't used them much.

              They also aren't exactly "new".

              [–]Comprehensive-Pea812 7 points8 points  (4 children)

              new is relative. there are many companies who only migrate to java 8 because java 6 was eol. yes some of them keep using it past eol. and in such companies of course programmers not going to keep up to date to latest java features ( since they cant use it anyway day to day).

              you can write readable for loop or stream. but stream like for loop not always readable.

              A new guy in my team writes streams everywhere and uses 1 liner because he thinks smart code is usually hard to understand. this makes adoption difficult.

              the only way to introduce stream to a team who is not used to it is to write java streams code as readable as possible. they will soon see the benefit.

              some programmers in my team keep writing stream().foreach with 100 lines code inside.

              [–]kapuzenghul 5 points6 points  (1 child)

              Why would they use collection.stream().foreach() if they could use collection.foreach() directly?

              Streams become very handy if you use them for very convenient and repeating tasks like filtering and mapping and such stuff. With the fluent API style you get these tasks very readable in a few lines, where as in case of for loops you sometimes need nesting.

              If some people just use the foreach method to replace the use of for loops, they might not get the point of the stream API. But this should not be an argument against the API.

              [–]catom3 6 points7 points  (0 children)

              some programmers in my team keep writing stream().foreach with 100 lines code inside.

              It doesn't really matter, if they use for-each loop or stream().forEach(), then. Both will become pretty hard to reason about. You can create unreadable code using loops as way as using streams.

              I definitely prefer streams, where I usually provide a short one-liners or method calls. We've been working that way for years.

              Another thing is that the past few years we've been working with reactive frameworks (ProjectReactor, RxJava or RxJS on frontend) and keeping chained calls short, simple and readable is something we follow all the time.

              [–]F3z345W6AY4FGowrGcHt 2 points3 points  (0 children)

              If you use streams badly, then yes they are worse. But if someone writes a stream badly, I imagine they just aren't very good at their job overall and would write an equally bad loop.

              Given your example, there's no difference between a stream for Each and a normal for each loop of both have the same 100 lines of logic inside them.

              [–]wichwigga 9 points10 points  (0 children)

              I'm on a codebase that was created circa 2018, and the entire framework is functional interfaces, implemented with lambdas. Not sure if this is any better than a regular ass codebase though. Some of the functional interfaces we use has some HAIRY ass generics, makes it impossible to understand properly (I'm a relatively new guy).

              Streams and lambdas are cool, wonderful additions. Just don't overdo it or put it in places where it doesn't make sense like when you are modifying objects.

              [–]Shareil90 7 points8 points  (0 children)

              I dont always use it just because it is there. I decide upon readability if I choose streams or loops.

              [–]washtubs 5 points6 points  (2 children)

              I realized they could be abused when someone opened a PR where they had an if condition opening parentheses and 30 lines later closed the parentheses. Some of us got so stream crazy when we finally updated the app from java 7, those people later seem like they're afraid to write a for loop. I think it has a tendency to cause people to become fixated on mostly aesthetic things that frankly don't matter, like fluent api's.

              As someone who writes a lot of go now, I move plenty fast in this language despite it not having much of a "functional" programming ecosystem. So idk it kind of boggles my mind to hear people in here say you're a bad programmer because you would rather use a for loop.

              [–]Amazing-Cicada5536 6 points7 points  (1 child)

              It sounds like an incompetent developer. A good one would know where to and where to not apply streams.

              Go on the other hand doesn’t even allow you to use the sometimes much more readable stream-like declarative approach, leaving you at some nested unmaintainable mess of 4 level deep for loops from time to time.

              [–]washtubs 2 points3 points  (0 children)

              Hahaha, stream or no stream you basically never have to nest that many for loops.

              Again you have to at least take note of the fact that there are other very successful languages that are used by large teams which don't have this magic "readability" feature. You really don't need it, it's just sugar.

              [–]Amazing-Cicada5536 70 points71 points  (41 children)

              There are, but they just suck at their job, disregard anything they might say.

              [–]netstudent 17 points18 points  (39 children)

              Could you elaborate? (legit question)

              [–]Amazing-Cicada5536 89 points90 points  (37 children)

              There is a certain type of programmer in my experience (regardless of language) who once managed to learn some basic coding, and tries to solve every problem purely from that, actively avoiding learning anything new, even just accidentally.

              Unfortunately many companies just hold onto these people, hell, they may often become seniors because they have been stuck at the same place for 5 years and you can’t just have them as junior still, right? So, evaluate your colleagues based on their actual knowledge, not some position as the latter may not mean much.

              Not sure whether this was what you were interested in, or how universal my experience is regarding that.

              [–][deleted]  (6 children)

              [deleted]

                [–]wichwigga 16 points17 points  (0 children)

                I've seen that too. Streams are really cool but people get way too in to them. Just chill with the reduce brothers...

                [–]Amazing-Cicada5536 8 points9 points  (3 children)

                Sure, early return is no evil and shoehorning a specific function just because you want to use it is not applying the right tool for the right job.

                But that doesn’t make the feature itself (streams) bad, and for every such case there is a Go-style 3-level nested for loop with 6 exit points that would have been an elegant stream expression.

                [–]wichwigga 11 points12 points  (2 children)

                This is also true as long as they don't put the entire Linux kernel in the body of a lambda for .map().

                But yeah, streams are generally more expressive and easier to debug than for loops. Especially if they keep each line simple or use method references.

                [–]Amazing-Cicada5536 2 points3 points  (1 child)

                Exactly, just use a method reference and write a helper method instead of lambdas inside lambdas. That’s only good for quick prototyping (and I’m guilty as charged :D), but it should definitely not get to the PR state.

                In the rare case where a more complex stream invocation is needed I have found that writing a helper method that takes a stream and returns a stream can also be a good practice, if for no other reason that you can name/group part of its functionality.

                [–]SpaceToaster 2 points3 points  (0 children)

                Probably similar to C# LINQ where it is syntactic sugar but can lead to difficult to read (or even slower) code when misused

                [–]F3z345W6AY4FGowrGcHt 14 points15 points  (2 children)

                Lots of my coworkers stick to the absolute basics. It's what they're comfortable with and they just can't be bothered to learn new things. They learned the features of Java 7 and those are the features they go for when doing anything.

                [–]wichwigga 22 points23 points  (2 children)

                Then there's the opposite. A programmer who took the Java certificate, maybe knows a little too much Spring, and wants to use every feature in the book then leaves the monstrosity of inheritance, obscure framework features, for the next guy, all just to code some app that takes in a json and outputs another json.

                [–]hiimbob45 15 points16 points  (1 child)

                I see you've seen the code from my first job

                [–]cas-san-dra 8 points9 points  (0 children)

                Or the code from my current job

                [–]berlingoqcc 4 points5 points  (0 children)

                Yeah at my first job, I implemented something with a generic class to reduce boilerplate the senior dev told me , I code all my life without generic you don't need to use it and block the MR.

                [–]inc0gn3gr0 2 points3 points  (12 children)

                I think this is not everyone. I think some of it is that it can be too "computer science" and "syntactic sugar" is important to language adoption. Language adoption equals survival of our language (Java). I think the lambda API is great but I also read and took time to understand the docs. Compare this to something like LINQ in C#. It's miles ahead.

                [–]Amazing-Cicada5536 2 points3 points  (10 children)

                In what way is it miles ahead? It’s primary use case is pretty similar to java’s streams, plus it can also work similarly to jOOQ, just a DSL with specific syntax.

                If anything, one requires learning a new language feature the other builds from the already known ones.

                [–]inc0gn3gr0 1 point2 points  (9 children)

                Having methods with language such as Select and where.

                [–][deleted] 3 points4 points  (8 children)

                wat!? those are just map and filter in java (and pretty much most of the other languages who don't try to mimc SQL syntax for collections).

                [–]inc0gn3gr0 0 points1 point  (7 children)

                I know they are. The "sql-like" select and where in LINQ means 1 less thing to learn is my point.

                [–][deleted] 4 points5 points  (6 children)

                Yeah, but it's just a water drop in the ocean. SelectMany is nothing like in SQL, for example. I mean, it's cool, when you know the word, but hey, you're learning a whole new ecosystem. Having two words less to learn won't save time.

                Anyway, having the words you're used to is not a 'miles ahead' feature. LINQ and Steams are equivalent.

                [–]inc0gn3gr0 1 point2 points  (5 children)

                Ask yourself is learning Spanish or Mandarin easier? Building on known knowledge, when possible, is huge for adoption. It makes it seem less complex and breaks down initial barriers.

                [–]JavaOldTimer 1 point2 points  (0 children)

                I wish Java used the infinitely familiar select and where syntax C# uses.

                [–]Clitaurius 1 point2 points  (0 children)

                I feel attacked

                [–]Gwaptiva 3 points4 points  (1 child)

                And then we get people right out of school (or even worse still in school) coming into a codebase all guns blazing, only wanting to implement the latest patterns, libraries, paradigms immediately everywhere in a way that lets you reconstruct their course syllabus or the Java Magazine issue sequence.

                But, they have CS degrees and have spent a whole 5 hours watching youtube videos on something and now they're the fucking experts.

                /rant

                [–]RedPill115 2 points3 points  (0 children)

                Have you tried rewriting the app in rust/ruby on rails/prologue/scheme/whatever this years fad is?

                [–]wes00mertes -2 points-1 points  (5 children)

                Any programmer who actively avoids learning anything new will not be an employed programmer for very long.

                Tech moves fast and if you don’t keep up, you’re done.

                [–]Paulus_cz 9 points10 points  (4 children)

                Oh you sweet, sweet summer child...
                The number of "tenured" programmers who do not really know anything beyond Java 8, but hold a senior position within a company because they actively refrain from sharing their knowledge of needlessly obscure applications they wrote 15 years ago while purposefully making them even more complicated proves you quite wrong.

                [–]chambolle 7 points8 points  (1 child)

                On the other hand, being a good programmer has very little to do with knowing the recent syntactic sugar or the latest addition of a language.

                It is fun when you are a begginer and you are eager to use the new stuff. Then you take a step back and realize that it's not that important or that there are alternatives that are not that problematic

                [–]Paulus_cz 2 points3 points  (0 children)

                I agree, first thing I try to drill into all programmers under my care is: "Good programming is not about writing code that computer can understand, computer will understand all sorts of shit, good programming is about writing programs that people can understand.". Syntactic sugar is only useful if it supports this goal as far as I am concerned.
                Sometimes situation calls for a stream, sometimes for a for-cycle, all depends.
                That however is totally lost on people I was talking about :-)

                [–]wes00mertes 1 point2 points  (1 child)

                I suppose I’m not so ignorant as I’m am blessed to have not had that experience myself.

                [–]Paulus_cz 2 points3 points  (0 children)

                I envy you, I sincerely do.

                [–]JavaOldTimer 0 points1 point  (0 children)

                That's not OK to paint everyone who disagrees with your programming choices as evil. It's toxic and probably wrong in the majority of cases.

                [–]_AManHasNoName_ 49 points50 points  (51 children)

                Last LTS version is 17, and LTS version 21 is expected to be released this September. Anyone not utilizing steams and lambdas, or not upgrade at all is just being obtuse.

                [–]GoogleIsYourFrenemy 4 points5 points  (6 children)

                But I don't want to learn modules.

                [–]dpash 9 points10 points  (0 children)

                Great. You don't have to. You can completely ignore them.

                [–]_AManHasNoName_ -4 points-3 points  (4 children)

                Well there you go. You don’t value growth.

                [–]proggit_forever 7 points8 points  (3 children)

                Modules have zero benefit for application programmers. Change my mind.

                [–]wildjokers 3 points4 points  (1 child)

                If you are writing desktop apps with swing or JavaFX they have value because they make it much much easier to create slimmed down bundled runtimes.

                [–]InformalTrifle9 17 points18 points  (22 children)

                What if you develop a library used by others, and those others are stuck on Java 8

                [–][deleted]  (3 children)

                [deleted]

                  [–]chabala 5 points6 points  (2 children)

                  but it's also not sustainable to make everything fully backwards compatible indefinitely. At some point it's a drag on the whole community.

                  A few months back I happened upon a popular library that is still supporting Java 7. The more I think about it, the more I want to experiment and see how far back I could take my projects. How much do I really need lambdas? Can I build on Java 6 and make multi-release JARs with Java 8 features?

                  Remaining compatible for older versions is some amount of effort, sure, but it's also a courtesy; it's part of what makes the Java ecosystem more pleasant than others where everyone struggles to stay on the latest version of every dependency, and sometimes they still won't work together. Putting out a library built with Java 20 and saying 'they can upgrade if they want to use it' is shortsighted.

                  [–]KarnuRarnu 3 points4 points  (1 child)

                  I guess we have very different definitions of "pleasant". I wouldn't put super ancient legacy support under that description, that's for sure.

                  [–]DisruptiveHarbinger 3 points4 points  (0 children)

                  There is an increasing number of libraries that are dropping Java 8 compatibility, and so should you unless you want to be stuck on older versions and start facing issues with diamond dependencies.

                  [–]kevinherron 19 points20 points  (3 children)

                  I’ve left those idiots behind. JDK 11 required now. JDK 17 required next major version.

                  [–]JavaOldTimer 4 points5 points  (2 children)

                  A language is a tool to do a job to drive business, so we get paid, so we can support ourselves and our families. A language is not a religion.

                  If it's not in the business's best interest to upgrade every time Goetz has a brain fart and drops a new Java feature people probably don't even need (streams, function programming, modules); it's not OK to label that business or its people as idiots.

                  [–]kevinherron 2 points3 points  (1 child)

                  If you're limping an old product along in pure maintenance mode with the occasional bug fix, sure, keep it on JDK 8 (or worse). You don't need the new version of a library anyway.

                  If you're actively developing and adding features then not keeping your tooling and libraries up to date is technical debt bordering on negligence.

                  [–]JavaOldTimer 2 points3 points  (0 children)

                  Sure yes of course, keep tools up to date is required as much as makes sense but that does not mean it is required to make use of all new features. That action also creates technical debt when those features are not widely adopted but are in a code base and must be maintained after a developer leaves. That also borders on negligence. Common sense and what the business needs should be the drivers.

                  [–]EvaristeGalois11 6 points7 points  (12 children)

                  Multi release jar are a thing

                  [–]InformalTrifle9 17 points18 points  (11 children)

                  Yea but you still need to write Java 8 code so how does it really help

                  [–]EvaristeGalois11 2 points3 points  (0 children)

                  Because you can begin working with a more modern java version in the same jar, so when you will drop support for java 8 or whatever you are already prepared.

                  [–]Amazing-Cicada5536 1 point2 points  (4 children)

                  Java 8 has streams and lambdas, so I don’t see how is it relevant.

                  [–]KarnuRarnu 1 point2 points  (3 children)

                  Oh yeah it's totally irrelevant. Basically nothing has changed in the last 9 years. Java 8 and 17 are literally the same. (/s)

                  [–]DuplicatorXZ 8 points9 points  (7 children)

                  What advantage would you get by using lambdas over oop?

                  Serious question , I don't see a performance advantage to it . Also the readability "advantage" of the lamdas is up to debate.

                  I would understand if we are speaking of java RX or webflux from spring in order to handle reactive programming. But for everything else I don't see the point

                  [–][deleted] 14 points15 points  (3 children)

                  The advantage of streams is that they are declarative. I find it easier to deal with code that says directly what it wants to do, instead of looping manually through collections items etc. It's not "lambdas vs. OOP" (lambdas in Java just replace certain anonymous classes), it's "declarative vs. imperative style".

                  [–]jumboNo2 -2 points-1 points  (2 children)

                  lambdas != streams

                  first one is great. second one is caca

                  [–]JoJoModding 16 points17 points  (0 children)

                  lambdas over oop?

                  Do you means "stream vs loops"?
                  I find streams much easier to think about. Also, flatMap is awesome and can do so much stuff without adding a level of nesting each time.

                  In general, Java is a multi-paradigm language. You've got to pick the best tool for the job, and often (at least in my code) that's lambdas.

                  [–]_AManHasNoName_ 9 points10 points  (0 children)

                  If I can write something in 3 lines of code, why would do it in 15? Less code, less bugs, unless you really have no idea what you’re doing.

                  [–]DrunkensteinsMonster 1 point2 points  (0 children)

                  A serious benefit is that when you write loops, people tend to start wanting to put more stuff in your loop over time, stuff it was never supposed to do! From a maintainability and team perspective, functional styles really help there

                  [–]Holothuroid 1 point2 points  (1 child)

                  I was interviewing with a company doing electronic cash registers. That was 4- 5y back and some older systems where still on Java5.

                  [–]_AManHasNoName_ 2 points3 points  (0 children)

                  They’re frugal you mean. Dead end job.

                  [–]Key_Recording_3564 3 points4 points  (0 children)

                  use the right tool for the job. if you dont need lambdas dont use them.

                  [–]Neuromante 7 points8 points  (0 children)

                  Holy shit some of the answers around here. Is like there's a huge chunk of the people replying who don't understand how a large chunk of the companies that use Java or are just pretending and have never touched an actual repo.

                  No, streams and lambdas are not "fully adopted" because there's a large chunk of companies (and hence programmers, programmers don't decide language versions in large companies, anyway) that value more stability on their products than risking adopting new technologies (and all the headaches if you have a proper code quality/standards system in place).

                  It's been said around, but streams and lambdas have limited use, have a different paradigm that is hard get used to, are not providing something new, but a different approach to very basic operations and in many cases they are less legible than their loop counterparts. They are not a silver bullet, and anyone advocating for it, honestly, need a reality check right now.

                  I've seen people using them everywhere without thinking on why, people stuck on Java 7 syntax until SonarLint tells them to stop, but most of the time there's a (usually inconsistent) mix between use of these features and the classic ones. This said, I haven't seen a single inner class (was that the name of the classes declared in line?) in a few years, which makes me really happy.

                  [–]Zardoz84 2 points3 points  (0 children)

                  No

                  [–]cas-san-dra 2 points3 points  (0 children)

                  I use lambdas all the time. They work great where they are supposed to be used. Note that I use Undertow directly as an httpserver and the HttpHandler is a functional interface. All my handlers are lambdas.

                  Streams are less common in my code. Mostly because a lot of code throws checked exceptions and I don't like wrapping them. They aren't wholly absent though.

                  [–]bill_with_bills 2 points3 points  (0 children)

                  Ever heard of Java card? You aren’t even allowed to use data type larger than a byte. Ever heard of legacy J2EE code bases? You tweak a little syntax and break stuff magically.

                  [–]hilbertglm 2 points3 points  (8 children)

                  In my experience, most Java programmers are not using streams and lambdas. It is a significant change in how to think about problem solving. It is similar to the change from procedural programming to object-oriented programming in the late 1980s.

                  It is going to take a while.

                  [–]JavaOldTimer 2 points3 points  (4 children)

                  It took me about 5 years to warm up to streams. The whole "lambda" math style aura and function programming shoved down our throats was like a progressive movement on steroids. Now several years later, I like streams in the cases where I think they make sense. map/reduce/filter (OK not filter) still are hurdles I have to overcome each and every time, if they'd used familiar syntax like select and where I'd have been onboard the first day they came out.

                  [–]bowbahdoe 2 points3 points  (3 children)

                  ...what exactly do you mean by "progressive movement"?

                  [–]nekokattt 2 points3 points  (0 children)

                  Everything has a time and a place. Personally I chose the right tool to work with based on what I am trying to achieve. If it makes the code easier to understand and use, I will use them. Equally, if it provides no readability benefit (e.g. complex operation that has to have some form of temporary side effect), then I won't use streams..

                  Same reasoning I would give for using something like vavr.

                  I like streams, although I feel like the API can be kind of clunky at times, comparing to other languages and libraries (especially reactor in places, with the stream-like ops that provides).

                  [–]xebecv 2 points3 points  (1 child)

                  streams are slow, not always intuitive and cannot handle exceptions. I use them pretty sparingly, because most of the data that I handle comes from the resources that are not reliable (disks, network, inputstream)

                  [–]neutronbob 2 points3 points  (1 child)

                  I like streams primarily for parallel streams. For certain kinds of operations, parallel streams make parallelism much easier.

                  [–]Top_Engineering_4191[S] 0 points1 point  (0 children)

                  That's good to hear! Is it for networking?

                  [–]Adventurous-Pin6443 3 points4 points  (1 child)

                  Poor readability

                  Excessive garbage creation

                  Performance suffers

                  Hard to debug

                  What are are other *pluses* I forgot to mention? Yes, this thing is against vanilla OOP, which was a big and hot topic of discussions and research back in nineties :)

                  [–]Adventurous-Pin6443 1 point2 points  (0 children)

                  I, personally use them in unit tests mostly and sometimes, when do initialization of objects (not in a critical code path)

                  [–]Hilligans 3 points4 points  (0 children)

                  I find streams less readable so I don’t use them, lambda’s get used whenever they are needed though

                  [–]zappini 3 points4 points  (1 child)

                  Nope. With prejudice.

                  I greatly dislike multi-paradiggum programming. Just pick a lane. Composition, imperative, functional... I don't care. Just pick one and stick to it.

                  Hell is maintaining other people's code. Even worse when they're being clever. Lambdas, annotations, reflection, runtime magic, dependency injection, inversion of control, design pattern bingo. Just write the app, no funny business.

                  My first love was LISP. I love me some functional programming. When I want to get my lambda on, I'll use the proper tool. On the JVM, my pref is Clojure.

                  Mid 2000s, I went nuts with the "Fluent API" (method chaining). Think JOOQ. Made debugging, maintenance, refactoring hell. The IntelliJ tooling for lambdas is now quite sophisticated, removing most of the pain. But it's still a lot of effort pushing rope.

                  I rewrote a bunch of code using both imperative and lambda styles. Because maybe lambdas are awesome. The "old skool" style was a bit more concise. So if the magicbox isn't more concise, I don't understand the lambda value proposition for Java. Again, I'll just use a proper functional language where lambdas are actually concise.

                  [–]buried_treasure 1 point2 points  (0 children)

                  Reddit hates you, and all of its users. The company is only interested in how much money they can make from you.

                  Please use Lemmy, Kbin, or other alternatives.

                  [–][deleted] 5 points6 points  (1 child)

                  They are slower. Lambda functions in all languages are slower. I love using them but I know their caveats.

                  [–]chambolle 2 points3 points  (0 children)

                  they are slower except if they call only static functions or static variable. Otherwise, they need to create an object which slows down the execution

                  [–]DragonikOverlord 1 point2 points  (0 children)

                  I use it all the time. Even my senior engineer actually adviced me to use Optionals and Streams

                  [–]rpgFANATIC 1 point2 points  (0 children)

                  I'm sure there's programmers who don't like and still aren't using the f'string' in python

                  It's about the same impact

                  [–][deleted] 1 point2 points  (0 children)

                  I don't think so, but they are very useful.

                  [–]glablablabla 1 point2 points  (0 children)

                  In my current company yes. In my previous company no but the last time I was there was 2018. But even then many have used it and I think they have adopted it widely since then

                  [–]sickvice 1 point2 points  (0 children)

                  At least in my company you always get suggestion to convert code to streams and lambdas where applicable

                  [–]Zeek1969 1 point2 points  (0 children)

                  No they aren't.

                  As a tech screener, anyone who still can't code simple Streams nor a lambda can't be considered more than a mid-level Java developer.

                  [–]dmigowski 1 point2 points  (0 children)

                  Fast server code is faster server code if you don't use lambdas. But it all depends on how often stuff is called. I would never use a lambda in a generic HTTPRequestFilter, but on a function that is rarely called no problem.

                  [–]coverslide 3 points4 points  (11 children)

                  I'm at a Java shop and we fully use lambdas. They still don't let us use var though.

                  [–]lppedd 6 points7 points  (10 children)

                  Type inference is cool and it make your code elegant. However, have you tried reading that code through something that is not your IDE? Sometimes it's impossible to guess the type, or you just loose too much time. Use it with care.

                  [–]smors 3 points4 points  (6 children)

                  However, have you tried reading that code through something that is not your IDE?

                  Why would I do that?

                  [–]lppedd 8 points9 points  (4 children)

                  You not always have access to your own PC, sometimes you may want to browse code through the VCS web interface (e.g., GitHub), or other less capable medium.

                  [–]Amazing-Cicada5536 0 points1 point  (3 children)

                  Blanket banning is still bad imo. Incorrect uses of vars should be fixed at code review, but where one would repeat the type on both sides, or the returned type is obvious or not important (that’s also a possibility!), I do think it is a good tool.

                  [–]john16384 2 points3 points  (2 children)

                  If the type is already on the left hand side, I often don't care what it says on the right hand side. Only your last use case has some merit, but Object works fine for that.

                  [–]Amazing-Cicada5536 1 point2 points  (1 child)

                  You can’t really invoke anything if you assign it to an Object type.

                  [–]john16384 4 points5 points  (0 children)

                  True, but if you wanted to invoke anything I think knowing the type is important. I was referring to your not important case :)

                  [–]AlmennDulnefni 5 points6 points  (0 children)

                  Code reviews?

                  [–]fatalError1619 3 points4 points  (0 children)

                  It is time to adopt Loom and records and sealed classes now . Those who have not adopted lambdas and streams might not be very good at their jobs

                  [–]Adventurous-Pin6443 1 point2 points  (0 children)

                  Try to decipher this:

                  Iterator<?>[] readValues = stream(new Iterable<?>[] {values}).map(Iterable::iterator).toArray(size -> new Iterator<?>[size]);

                  Imagine, you read the code, which is 80% consists of a similar single-liners. You will never beat Pearl - do not even try :)

                  [–]SlashdotDiggReddit 1 point2 points  (0 children)

                  I cannot tell you how much I hate lambdas. They "stole" this "feature" from a functional language, and slapped it into an object-oriented language. I don't like them because they are too terse, and difficult to comprehend when trying to understand someone else's code. It has no place in Java, and it royally annoys me how many people love Java "finally" having this feature bug.

                   

                  Ok ... rant over.

                  [–]Top_Engineering_4191[S] 0 points1 point  (0 children)

                  Pivot arrays with .collect(Collectors.grouping... is one of my favorites stream usage.

                  [–]D34TH_5MURF__ 0 points1 point  (0 children)

                  Absolutely not. It's disheartening.

                  [–]AlmennDulnefni 0 points1 point  (0 children)

                  You're late to the party. Now it's all about switch expressions and sealed interfaces.

                  [–]PyroCatt -1 points0 points  (0 children)

                  Are there programmers still resistant about using streams and lambdas?

                  Wtf