Live data from Hacker News

New language features since Java 8 to 17

advancedweb.hu

301–310 of 358 posts

Re: New language features since Java 8 to 17

#301
post #146

Earlier quoted context omitted.

how's javascript better than java in its design or elegance?

Well for one, it has a repl. As per single core performance, javascript is faster and has had first-class-functions from the beginning. and you don't need 10 lines of code to print hello something to the screen. and JavaScript(ES6) is actually multiparadigm. don't get me wrong, JS has its warts (and oh my god that is indeed the case.) but you can literally run it in any browser any where, which makes for an excellent…

> Well for one, it has a repl

Jshell

> As per single core performance, javascript is faster and has had first-class-functions from the beginning

Doubt. And no matter how I count, Java had first class functions for 8 years now, at the very least. Does it really matter when exactly did a language feature got implemented?

> and you don't need 10 lines of code to print hello something to the screen.

jshell: System.out.println(“hello world”)

> and JavaScript(ES6) is actually multiparadigm.

That hardly means anything. There are entirely FP libs available for Java.

Re: New language features since Java 8 to 17

#302
post #281

Earlier quoted context omitted.

Tbh I still crave Kotlins inline string interpolation.

A “superior” implementation is in the works with templated strings. It will look something like this: STR.”text with \\{variable}”, but anything implementing the TemplatedString interface can change the behavior of interpolation. There is not even a requirement to produce strings only!

Oh nice, do you have a link to the project?

Re: New language features since Java 8 to 17

#303
post #160

Earlier quoted context omitted.

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.

those feature are either horrible I speculate that most users of languages that have these features (Kotlin has all of them) would be unhappy if you took them away. algebraic data types and pattern-matching -- will lead to better development practices, rather than making it easier to work with inferior ones. I am not arguing against those features, but the ones I asked for seem easier to implement by comparison as th…

> I speculate that most users of languages that have these features (Kotlin has all of them) would be unhappy if you took them away.

Kotlin has very little impact over the ecosystem due to its small market share (compared to Java). Plus, it has no influence over the platform, or any of the other platforms it targets for that matter, with the possible exception of Android, although I guess that's up to Google. The best it can do on the Java platform is make current practices a little easier. Java, on the other hand, has the option of changing the platform and the ecosystem and moving it toward better practices.

> in other successful JVM languages

Just so that we're clear, for over a decade now, the portion of Java platform developers using all other "successful JVM languages" combined has been pretty much steady at 10%. That's not to say they're not popular in absolute terms, but Java is so stupendously popular, that it's in a completely different league.

> If these features are such bad ideas there should be plenty of stories of Kotlin/C# devs cursing the language for providing them with these footguns.

Those languages appeal to different people, and, in the case of Kotlin, at least, they're the best they can do given their clout. If I don't like something, there will be those who do. The question is, how many? When I said that the features are bad or superseded by better ones, I didn't mean they're necessarily bad for all people or all languages, just that they're either bad for Java or that Java can do better.

> has no reason to fear that Kotlin will lose steam

The way this works is that the alternative languages on the Java platform fight for market share with each other. Kotlin will not disappear because of Java, but it will eventually lose its market to some other alternative language, just as Scala has lost to Kotlin. 10% of people just prefer other languages, and I am very happy that the platform can accommodate them. We'll continue working to make sure that the platform is a good target for different languages that appeal to different people. Other languages don't take away from the Java language, but make the platform more appealing to people who prefer less mainstream languages, and so we all win. Java's 9/1 ratio of Java language vs. others is a pretty good one, and we're trying to preserve it (we would be even happier with 85/15 or 8/2, as it probably means a larger market share for the platform overall rather than a smaller market share for the language. Remember that OpenJDK is funded by people buying support; they're not buying support for the language, but for the platform). If the non-Java-language market has shifted from Groovy and Scala to Kotlin, as that's what most of those in that group prefer -- so be it (although I do wish more people use Clojure; it is, IMO, the most interesting and best design alternative Java platform language out there, and one of the most interesting and best designed languages around in general).

The strategy that keeps the VM is innovative and the language is conservative has worked very well for Java, and because it's expected to remain very popular for a couple of more decades at least, we are very careful about adding features. The goal is to avoid new features as much as possible, and the way to do that is to add fewer, but more powerful features.

Re: New language features since Java 8 to 17

#304

Earlier quoted context omitted.

Could you please support your statement with reasons?

Not sure about the person above but the following are my opinion on why I don't like Java: 1. no unsigned integers 2. no freestanding functions 3. pom files are a huge pain 4. the com.blah.blah.blah ridiculously long package path precedent makes it awful to work with if you don't have an ide 5. you can't actually use javac to compile your code. everything is so big and complicated you have to use ant, gradle, maven,…

For beginners, you can literally write Java the same way you would write python.

Write class Hello { public static void main(String[] args) { … }} into a Hello.java file and issue java Hello.java and it will compile and run your code. It hardly gets easier than that.

Also, it’s a bit unfair mixing in build tools for beginner courses - I doubt beginners start with python virtual envs either. And then don’t get me started on the multi giga node folder hell that you get from a simple Js project.

Re: New language features since Java 8 to 17

#305

Earlier quoted context omitted.

Could you please support your statement with reasons?

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.

But that verbosity doesn’t scale with code size, so it is largely meaningless.

Re: New language features since Java 8 to 17

#306
post #160

Earlier quoted context omitted.

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 exc…

> I personally like the idea of checked exceptions, but there is no doubt they failed to deliver on Java.

Why is there no doubt? I agree that their interaction with lambdas leaves much to be desired, but those problems can be fixed.

> Explicit nullability is unarguably a good feature.

It is. It wasn't on the list, which asked for a "null safe navigation operator"; that is not a good feature, as it makes it even harder to see where the nulls are.

> But Java's Optional is not that solution

I didn't say it was. Nullability types for Java are being studied.

> But even if Java does all of that, just lack of extension methods and top-level functions make using Java a nightmare for me.

Extension methods make a language a nightmare for me, though. Java doesn't try to appeal to all people, and no language ever will. It just tries to appeal to most. As for top-level functions -- stay tuned.

Re: New language features since Java 8 to 17

#307

Earlier quoted context omitted.

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.

OP meant the public static void main part (that is you define what happens encapsulated in a class) Of course implicit imports are needed, like what else would you have without?

Re: New language features since Java 8 to 17

#308
post #298

Earlier quoted context omitted.

> will lead to better development practices, rather than making it easier to work with inferior ones. C# has these "inferior practices" and is a much better language overall. Why Java doesn't adopt the low and not-so-low hanging fruit from C# is really baffling. Anything from yes, properties, to object initialization shortcuts and a sane IEnumerable/Collection interface that doesn't require stream/toList everywhere.

> C# has these "inferior practices" and is a much better language overall. Why Java doesn't adopt the low and not-so-low hanging fruit from C# is really baffling. Because Java is doing a lot better than C#, and obviously we feel Java is a much better language overall.

Java has had quite a head start (.net core came out only 5 years ago).

Now the "doing a lot better" is dwindling. And dragging feet on QoL isn't helping.

Re: New language features since Java 8 to 17

#309
post #288
post #286

Earlier quoted context omitted.

I think what op meant is that dependency injection is type safe, in that in case of going through a constructor, they have to indeed type check with the dynamically provided instances.

(I got lucky and spotted this reply instantly; I promise I wasn't lurking waiting for a reply.) Don't dynamic DI frameworks like Spring use runtime reflection to invoke such constructors? If a bug existed in Spring causing a value of the wrong type to be provided, I expect it would go undetected until runtime, at which point Java will throw an exception. My understanding of "type safe" is that the code is statically…

Yeah of course it depends on your definition — and in case of such a widely used framework I would usually use type safe with regards to user code, but you are entirely right!

But another point I had in mind is regarding the JVM is that it is strongly typed so such an error will be at least visibly and fail with a proper error message.

Re: New language features since Java 8 to 17

#310
post #281

Earlier quoted context omitted.

A “superior” implementation is in the works with templated strings. It will look something like this: STR.”text with \\{variable}”, but anything implementing the TemplatedString interface can change the behavior of interpolation. There is not even a requirement to produce strings only!

Oh nice, do you have a link to the project?

https://openjdk.java.net/jeps/8273943
Post reply on HN