Earlier quoted context omitted.
Impressively simple - though there being three ways of doing something is a complexity in itself. Perhaps I’m being too critical.
Not if only one is the right one in all cases. In python you can also do s = set() s.add(1) s.add(2) and s = set(x for x in [1, 2]) But I wouldn't call that having three ways to do the same. Disclaimer: I don't know java well, just commenting based on the comments above and my python knowledge.
All New Java Language Features Since Java 21
111–120 of 130 posts
Re: All New Java Language Features Since Java 21
#112Earlier quoted context omitted.
I think VT's are only going to be interesting if you need 1000s of them doing tiny amount of small work often. For me I have been waiting for them for 20 years, as the blocking IO made MMO development impossible. In the meantime we got NIO in 1.4 that only became performant and stable around 1.7 so it's been a slow progress. I dug out my old blocking server code from back then and with a fresh coat of paint I'm ready…
> For me I have been waiting for them for 20 years, as the blocking IO made MMO development impossible. I'm not into this area of work, but wouldn’t Netty have been helpful even before VTs became available?
Also Netty is one of those middleware "pretend to help but really bloat" libs.
I would sincerely recommend to avoid those as implementing on top of lower common denominators always is faster in the end after all the Netty bugs have been sorted.
Re: All New Java Language Features Since Java 21
#113After trying out many languages at many places, I reached the conclusion that Java, as weird as it may be, is my favorite language. There were times I hated it, but turns out I really just hated messy, over-engineered legacy code and working in a gray cubicle at aging MegaCorps. The language itself is quite beautiful when used properly and with modern features. It just really needs a makeover and better tools.
I can't see why you'd pick Java over C#. IMO its basically all the same preferences with slightly more consistent syntax choices. That said, Java is great too. It's underrated considering what a workhorse it is.
Re: All New Java Language Features Since Java 21
#114Earlier quoted context omitted.
This is amazing news! Two questions for you: - how’s the environment? Build tools, dependency management, etc. it used to be a PitA back then. - how has the typing system and generics evolved to support this? Have they introduced any type of variance?
Generics still kind of suck but they’re workable enough. As far as I am aware they’re broadly unchanged and I don’t think they added any kind of new variance. It turns out, though, it’s still good enough for sealed interfaces and the like; I don’t have too many issues with it, though that might just be Stockholm syndrome at this point. Maven is terrible as always but Gradle is generally fine. I use IntelliJ community…
Re: All New Java Language Features Since Java 21
#115Java is becoming a poorly implemented Scala.
Re: All New Java Language Features Since Java 21
#116I’ve worked in Java for over 20 years. Being the “lingua franca” of the enterprise is its biggest strength IMO, but it is also perplexing to me that it was able to do that in the first place. The language itself is not bad. The tooling around it is very good. But the codebases you encounter written in it, particularly in the enterprise, are often horrible.
Mind sharing why do you consider Java tooling to be good (and largely, what is good here)? The reason I ask is that I recently had to join a Java project at my company, and having a background in Node/Rust/Perl/Lua and some C++, I found the Java tooling to be extremely unsuitable for my taste. A simple example: there is no standard LSP server, and the amount of jumps required to have a working setup with FOSS tools a…
Re: All New Java Language Features Since Java 21
#117Java is becoming a poorly implemented Scala.
Scala is a dead and complex language.
Re: All New Java Language Features Since Java 21
#118Earlier quoted context omitted.
No, you shouldn't write that. Your variable should represent the complete implementation. Where you use it should be as generic as possible, for example, the parameter in a function call.
Why would you want that? The whole point of an interface or superclass is to let you swap implementations without changing everything. I also like the nudge it gives you to use only the higher level methods, rather than the ones specific to the subclass unless they're needed. That also improves flexibility.
Declaring a local variable as an interface to hide functionality so you can swap out functionality later is misunderstanding the fundamental theories around interfaces. Your variable should be whatever the function or method returns. If you want to abstract the type so it can be swapped out, create a function that returns an abstract type. Don’t tell the HashMap constructor it did the wrong thing. Now that I think about it, I’d recommend you use “var” in all cases, and not try to redefine the return values from a function.
Re: All New Java Language Features Since Java 21
#119Earlier quoted context omitted.
Scala is a dead and complex language.
Scala definitely had some missteps but its much nicer to program in than Java and simpler as well. I mainly program in Go these days but I could imagine explaining the benefits of Scala over Go to my coworkers. It would be embarrassing trying to do the same with Java however.
In my opinion Java is a much better language than Go. I can’t imagine anyone liking Scala would prefer it over Java.
Re: All New Java Language Features Since Java 21
#120Earlier quoted context omitted.
Not if only one is the right one in all cases. In python you can also do s = set() s.add(1) s.add(2) and s = set(x for x in [1, 2]) But I wouldn't call that having three ways to do the same. Disclaimer: I don't know java well, just commenting based on the comments above and my python knowledge.
In python, those give a mutable set, which is what I was referring to above. Also not to put too a fine a point, you'll never see python code like that in the wild, but even in code reviews these days, it's common to find Java code written like in my example because the syntax for sets in Java came after Java 8