Live data from Hacker News

New language features since Java 8 to 17

advancedweb.hu

231–240 of 358 posts

Re: New language features since Java 8 to 17

#231
post #206

Earlier quoted context omitted.

Can you do something similar in Kotlin using this function scopes (that let you change the meaning of this in a lambda)? I’ve found those ok at defining EDSLs.

I've only ever done a hello world in Kotlin I'm afraid.

You should check it out. Definitely not as expressive as Scala for expressing EDSLs, but it has a couple of features (scoped this for lambdas and extension functions/properties that can be injected into a lambda's namespace by a scoped this type) that you can get a lot of mileage out of.

Re: New language features since Java 8 to 17

#232
post #212

Am I the only one who's seeing "sealed" classes as an unfortunate development? I can't count how many times I had to resolve to using PowerMock and hacking bytecode just to mock something in one of the libraries I use because it's ingenious author "final"-ed the whole API surface of the library (and bits of the implementation usually). Now this gives even greater tool to people who love to lock everything up and thin…

Don't think of it as a less powerful class, think of it as a more powerful enum. At least that's how it's meant to be used. It's a good feature in other languages, and like you said, "final" already exists, so you're no worse off on that front.

Re: New language features since Java 8 to 17

#233
post #56
post #41

Earlier quoted context omitted.

Hmm yes I guess you might be right given Android. It's a shame in a way that Kotlin was invented as Scala could have filled the niche too imho but that ship has sailed. It's too similar to both Java and Scala and doesn't really bring anything new to the table. Is that fair or does it have a great USP other than massive Google backing?

I don't think Scala ever could have filled that niche, I say this as someone that wanted Scala to be successful. The truth of it is that Kotlin is incredibly easy to learn, even for non-Java devs. It is definitely focused on a very low barrier to entry. I don't think this was an original goal but it's become a significant focus of the language especially after being selected to be the next platform language for Andro…

Kotlin is easy to write because every idiom is available - but calling that a low barrier to entry reminds me of how articles used to suggest Perl as a beginner language because it was expressive. I actually consider it more complex than Scala as a language, because a lot of complex Scala idioms are just library code that you can click through to, whereas Kotlin tends to implement them as part of the language. I fear for the people who will have to maintain large enterprise Kotlin codebases in 5-10 years' time.

SBT is inexcusably awful (and so is ScalaTest, which is a lot of people's first exposure to the language), and you might be right about the zeitgeist having moved on, but it's a shame; it's honestly a significantly better language design.

Re: New language features since Java 8 to 17

#234
post #160

Earlier quoted context omitted.

I don't think this is going to happen with Brian Goetz as language architect. He refuses to add many features that would address everyday pain points such as: * null safe navigation operator * properties * mutable records * a way to ignore checked exceptions (or at least having the stream API take functional interfaces that can throw exceptions) * adding functional methods like .filter()/.map() directly to collection…

Thank god for that, because those feature are either horrible on their own or superseded by better ones. You're getting a car and complaining for not getting faster horses. The features Java has adopted -- specifically, algebraic data types and pattern-matching -- will lead to better development practices, rather than making it easier to work with inferior ones.

> Thank god for that, because those feature are either horrible on their own or superseded by better ones.

Are they though? I agree mutable data classes and property _setters_ are bad, but what about the rest?

I personally like the idea of checked exceptions, but there is no doubt they failed to deliver on Java. Perhaps the good parts of this idea can be salvaged by having an easy way to explicitly wrap a checked exception, like with_context() in the anyhow Rust crate. Kotlin dumped checked exceptions in favor of Results, and I don't see how Java has anything right now that supersedes that.

Explicit nullability is unarguably a good feature. You could make a convincing argument that expressing it with an Option/Maybe is better than the road that Kotlin, Swift, C# and TypeScript took. But Java's Optional is not that solution, since the T within the Optional can still be null. And I'm not even getting into how verbose and unnatural using it feels, or the small issue of having to rewrite all the existing Java APIs to make it work.

The same goes for having eager collection operators. The JIT compiler might be able to inline and optimize simple stream operators, but the ergonomics of doing simple things on a collection is just bad.

But even if Java does all of that, just lack of extension methods and top-level functions make using Java a nightmare for me. If Java had extensions methods (or an equivalent concept like Type classes or the Uniform Function Call Syntax that D has), the previous complaint about lacking collection operators directly defined on Collection and Iterable will be a non-issue. Just let anybody who wants it define their own.

Re: New language features since Java 8 to 17

#235
post #94

Earlier quoted context omitted.

Is there a reason for that? I'd really love to get into android development, but I'm loathe to give up some of the nicer language features in Java. What version of Java is android supporting? At least 8, right?

Java's supported version on Android is a moot point: all new Android development should be made in Kotlin.

That's not entirely a moot point. Java-the-language is mostly replaced by Kotlin and Java-the-runtime is wholly replaced by ART, there is also the Java standard library. New standard library features, or third-party libraries from the Java ecosystem that rely on new language features like records will not be usable.

Re: New language features since Java 8 to 17

#236

Earlier quoted context omitted.

Most likely to Flutter. When Google will be ready to ditch Android API.

Android is based on the JVM, it will never switch to Flutter (and an aggravating factor is that Dart is an inferior version of Kotlin).

Java is an Android's curse. Just compare how completely native iOS and iPadOS beat it in terms of speed and power saving. I hope they will get rid of the Java remnants completely and focus on the native toolchain, frameworks, system libraries.

Re: New language features since Java 8 to 17

#237
post #44

Earlier quoted context omitted.

I must be in the minority of thinking java 7 was the last great version of Java. What I see today is a nearly different language.

I liked Java 1.4. Generics were a mess. And Java before generics was so wonderfully simple. Yes, you had to cast, but that wasn’t a big issue. My favourite language would be Java 1.4 with carefully redesigned standard library (because old standard library was not very nice).

Yeah, I miss the good and simple times when Java didn't have all this unnecessary bloat like generics and annotations. We generously peppered our code with casts from Object and explicit boxing and unboxing, and it was good. Our code was so clean and readable, and we neatly wired everything together by configuring class names in XML. We were happy and life was good.

In all seriousness, Java's implementation of generics was less than ideal, but I recently had to deal with a lot of pre-Java 1.5 codebases that haven't seen much upgrade in recent years. It wasn't fun.

Re: New language features since Java 8 to 17

#238
post #212

Am I the only one who's seeing "sealed" classes as an unfortunate development? I can't count how many times I had to resolve to using PowerMock and hacking bytecode just to mock something in one of the libraries I use because it's ingenious author "final"-ed the whole API surface of the library (and bits of the implementation usually). Now this gives even greater tool to people who love to lock everything up and thin…

Without sealed classes it's impossible to enforce most interesting invariants. If anything the other way is a mistake.

Re: New language features since Java 8 to 17

#239
post #215

I used to really love Java, it was my second "real" programming language after C/C++, and GC, type safety, and object orientation really changed the way I thought. I also learned almost all I knew about high-performance VMs (up to 2013) in the context of JVMs. But these days it seems like Java is engaged in one long apology for the "everything is an object" mindset it started out with. It both took it too far and not…

[deleted]

Re: New language features since Java 8 to 17

#240

Earlier quoted context omitted.

public class Main { public static void main(String[] args) { System.out.println("Hello, world!"); } } vs print("Hello, world!") Please comment again if you still cannot see the bloat/unnecessary verbosity.

Global scope is a terrible invention. The less implicitness there is, the better.

Global scope is not a terrible invention and if you look carefully then you will notice that the Java version uses it as well.

Or where is the import to get "System" into scope? It's imported globally everywhere (just like all everything from java.lang).

So the only question is: should "print" be burried under layers or not. I don't think the advantages of burrying are really worth it.

Post reply on HN