Unfortunately it looks like Java is going to evolve enough to take the wind out of the sails of Kotlin and Scala for most dev shops. I guess the positive take is that those improvements might not have happened without the efforts to develop better JVM languages.
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 think that they know better than me what I need.
Yeah - personally I think languages should allow a lot of constraints like sealed classes (it makes your intent clear, and can allow extra optimizations, that's good!), but highly-risky "escape hatches" need to exist because they solve real problems.
"Fork and modify" is a very capable alternative, but it's far, far, far more costly than "monkey-patch this one time issue that'll be fixed next week". And some languages make it extremely painful to achieve, often requiring significant code rewriting, and which sometimes make contributing back to the source-library significantly harder. And when such hacks hang around longer for a week... well, sometimes that's fine, sometimes it's not, and the library author is not the one who should be making that decision. It's my program, it should do what I tell it to do.
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.
I just want to add that while this is a really nice post in its own right, I found this blog because its author created this: https://github.com/dodie/vim-fibo-indent
I imagine there's a reason it's necessary, but it's weird that "sealed" is basically "final" with the ability to do "permits" instead of just adding "permits" as a keyword that can be put on "final" classes
Does java have a decent story on value types now e.g can I make an ArrayList<long> and trust that it’s one array of longs on the heap and not an array of pointers to Longs?
This was what made me ragequit Java 10 years ago.
Not yet. You can track Project Valhalla [0], the incubator for value/inline types in OpenJDK. But I don't get the sense it's landing particularly soon.
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 far enough. Erased generics were the start of the problem. Parametric types! You were the chosen one! You were supposed to unify the primitive types and the object types! And never adding syntax for function types, just single-method interfaces...just ugly and clunky IMHO.
C# did generics right. Well, almost. "void" isn't a real type, so you can't be generic over it.
It is really important in language design that generics can range over any type. It allows the full combinatorial space. I worked really hard to make the Virgil compiler support arbitrary combinations of tuples, arrays, function types, and all of those work together seemlessly in the polymorphic type system. Everything else is a unfortunate shortcut, IMHO.
Whenever we read about new improvement in Java,it is always inevitably followed by concerns for viability of Kotlin or Scala. However these concerns are never applicable for Closure. I am glad I went all in on Clojure.
It would sure be helpful if they took some effort to focus less on adding crazy new stuff every 2 days and instead on maintaining older versions for a change.
Maintaining a python dependant system these days is an absolute nightmare, at least with C++ you know that new compilers will be backwards compatible, gah.
The “keep readability in mind” tip exposes more Java/OOP icebergs.
var date = LocalDate.parse("2019-08-13");
var dayOfWeek = date.getDayOfWeek();
var dayOfMonth = date.getDayOfMonth();
> The first one is pretty intuitive, the parse method returns a LocalDate object. However, for the next two, you should be a little bit more familiar with the API: dayOfWeek returns a java.time.DayOfWeek, while dayOfMonth simply returns an int.
Java.time.dayOfWeek takes a TextStyle and a Locale, both of which have a list of properties and methods I have to read all about before using. dayOfMonth returns an int, and I can see if it’s 0- or 1-indexed then do what I want with it from there. Why does DayOfWeek have a class instead of being a function that I can throw a number at like dayOfMonth?
I’m also skeptical about Java.LocalDate being “pretty intuitive,” having worked on local vs server vs data-store timestamps, as most of us have. At least LocalDate doesn’t have mutable setter methods like other Java dates…
I’m stuck on 8 and 11 in my current projects, so I haven’t seen much of these in the field other than the new record feature. What I am really surprised about is the var construct. Honestly, this leaves me a little conflicted since it seems to be antithetical to the principles of a strongly-typed language. So does this now reclassify Java as a weakly- or dynamically-typed language? I would perhaps argue against it being dynamically-typed since by definition type inference happens at runtime, but it certainly leaves Java in a sort of limbo. I don’t personally care, but I know at some point the topic will come up amongst my dev peers, at which point there will sure to be a (mostly friendly) debate.
Please don't take HN threads on boring generic tangents (by making grand shallow claims), and especially please don't take HN threads into tedious programming language flamewar.
Also, you broke the site guideline asking people not to go on about downvotes in the comments. Would you mind reviewing https://news.ycombinator.com/newsguidelines.html and sticking to them in the future? We'd be grateful.
Counterpoint: it's become a fairly multi-paradigm language at this point, and a multi-paradigm language is exactly what should be the defacto language in curriculums
Whether or not Java is the best one for this purpose is up for debate, but I think it's no longer a bad one
Being verbose is a plus. I really really really hate the terseness of Kotlin and how it's basically unreadable without an IDE.
Languages should be dumb. Standard libraries should be smart. Not the other way around. The number of syntax constructs that generate standard library calls when compiled should be minimized as much as possible.
Edit: one more thing, operator overloading is extremely harmful for readability.
Java is being used everywhere. And you get to learn the basic as well as the huge ecosystem behind it. Apart from possibly Python, are there any language that get you both in terms of market and learning?
And Java have make huge improvement in every part of the ecosystem, from languages, standard library, VMs. While I still dont like the language much, but I have gotten off the so called busy and verbose code view as I age. As they do serve some purpose. We need better balance, right now languages design are binary and polarised options.
I agree with everything here except the "should stop being taught as the defacto language in computer science curriculums". Realitically, a CS curriculum needs to at least vaguely prep a student for life in the industry, and Java is not only massively popular, but is also a great way of showing how OO is used in practice i.e. kinda badly. No point teaching everyone about beautifully architected Smalltalk programs just to have them work on hacky Java monoliths from 2003 (not to mention BusinessObjectTpyeFactoryGenerator.java).
There is still a huge market demand for Java. Moreover the recent releases are doing a great job adding features following recent trends. If thought using JDK 16+ a student will be able to move to Kotlin, Swift, Scala, ... much more easily than few years ago.
IMO it's more about updating the curricula than dropping Java.
Java sucking could be a good reason to teach it, no? It's instructive to know what bad choices have been made. Much like your first job, it can be unfortunate to work in a place where everything functions properly, because you won't know what makes it work.
Java is also a good base for looking at other JVM languages, and for looking at the JVM itself. That's gotta be part of a good curriculum too, doesn't it?
strictly from a pedagogical perspective, sure, there are better choices. but java is at least decent for most of the core cs curriculum, and it's widely used in industry. when you're trying to get your first internship with no work experience, it's nice to be familiar with the language you'll be using at work.
Regardless of OO 'quality' of a language, if you consider that most university degrees are an avenue to successful employment then it's easily one of the best ones to learn due to the current market alone.
[+] [-] cageface|4 years ago|reply
[+] [-] p2t2p|4 years ago|reply
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 think that they know better than me what I need.
[+] [-] Jweb_Guru|4 years ago|reply
[+] [-] Groxx|4 years ago|reply
"Fork and modify" is a very capable alternative, but it's far, far, far more costly than "monkey-patch this one time issue that'll be fixed next week". And some languages make it extremely painful to achieve, often requiring significant code rewriting, and which sometimes make contributing back to the source-library significantly harder. And when such hacks hang around longer for a week... well, sometimes that's fine, sometimes it's not, and the library author is not the one who should be making that decision. It's my program, it should do what I tell it to do.
[+] [-] goto11|4 years ago|reply
You wouldn't mock en enum either (hopefully).
[+] [-] xxs|4 years ago|reply
[+] [-] lmm|4 years ago|reply
[+] [-] pulse7|4 years ago|reply
[+] [-] AlphaSite|4 years ago|reply
[+] [-] unknown|4 years ago|reply
[deleted]
[+] [-] pharmakom|4 years ago|reply
- ~Exhaustive pattern matching~ it’s here!
- Algebraic data types
- Tail call optimisation
- Do notation
- Operator overload
Why not use another language? Well, the name “Java” guarantees buy-in at this point. Maybe it will eventually be a Trojan horse for ML :)
[+] [-] bobthedino|4 years ago|reply
[+] [-] dmitryminkovsky|4 years ago|reply
[+] [-] bobbyi|4 years ago|reply
[+] [-] alkonaut|4 years ago|reply
[+] [-] Twisol|4 years ago|reply
https://openjdk.java.net/projects/valhalla/
[+] [-] bradleyjg|4 years ago|reply
[+] [-] silvestrov|4 years ago|reply
[+] [-] titzer|4 years ago|reply
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 far enough. Erased generics were the start of the problem. Parametric types! You were the chosen one! You were supposed to unify the primitive types and the object types! And never adding syntax for function types, just single-method interfaces...just ugly and clunky IMHO.
C# did generics right. Well, almost. "void" isn't a real type, so you can't be generic over it.
It is really important in language design that generics can range over any type. It allows the full combinatorial space. I worked really hard to make the Virgil compiler support arbitrary combinations of tuples, arrays, function types, and all of those work together seemlessly in the polymorphic type system. Everything else is a unfortunate shortcut, IMHO.
[+] [-] manishsharan|4 years ago|reply
[+] [-] The_Colonel|4 years ago|reply
[+] [-] Thaxll|4 years ago|reply
[+] [-] sgt|4 years ago|reply
[+] [-] rdpintqogeogsaa|4 years ago|reply
[+] [-] tomcam|4 years ago|reply
[+] [-] pjmlp|4 years ago|reply
[+] [-] r0f1|4 years ago|reply
[+] [-] bradbeattie|4 years ago|reply
[+] [-] moffkalast|4 years ago|reply
Maintaining a python dependant system these days is an absolute nightmare, at least with C++ you know that new compilers will be backwards compatible, gah.
[+] [-] JulianMorrison|4 years ago|reply
[+] [-] filoeleven|4 years ago|reply
Java.time.dayOfWeek takes a TextStyle and a Locale, both of which have a list of properties and methods I have to read all about before using. dayOfMonth returns an int, and I can see if it’s 0- or 1-indexed then do what I want with it from there. Why does DayOfWeek have a class instead of being a function that I can throw a number at like dayOfMonth?
I’m also skeptical about Java.LocalDate being “pretty intuitive,” having worked on local vs server vs data-store timestamps, as most of us have. At least LocalDate doesn’t have mutable setter methods like other Java dates…
[+] [-] temporallobe|4 years ago|reply
[+] [-] sushsjsuauahab|4 years ago|reply
[+] [-] nooorofe|4 years ago|reply
> Available since: JDK 11 (Without lambda support in JDK 10)
TOC is missed up, there is no java-10 at all.
[+] [-] teh_klev|4 years ago|reply
https://advancedweb.hu/new-language-features-since-java-8-to...
[+] [-] didip|4 years ago|reply
Just like Javascript.
[+] [-] InsaneOstrich|4 years ago|reply
[+] [-] weatherlight|4 years ago|reply
[deleted]
[+] [-] dang|4 years ago|reply
Also, you broke the site guideline asking people not to go on about downvotes in the comments. Would you mind reviewing https://news.ycombinator.com/newsguidelines.html and sticking to them in the future? We'd be grateful.
[+] [-] brundolf|4 years ago|reply
Whether or not Java is the best one for this purpose is up for debate, but I think it's no longer a bad one
[+] [-] grishka|4 years ago|reply
Languages should be dumb. Standard libraries should be smart. Not the other way around. The number of syntax constructs that generate standard library calls when compiled should be minimized as much as possible.
Edit: one more thing, operator overloading is extremely harmful for readability.
[+] [-] ksec|4 years ago|reply
Is it really the point to teach OO though?
Java is being used everywhere. And you get to learn the basic as well as the huge ecosystem behind it. Apart from possibly Python, are there any language that get you both in terms of market and learning?
And Java have make huge improvement in every part of the ecosystem, from languages, standard library, VMs. While I still dont like the language much, but I have gotten off the so called busy and verbose code view as I age. As they do serve some purpose. We need better balance, right now languages design are binary and polarised options.
[+] [-] dukeyukey|4 years ago|reply
[+] [-] vletal|4 years ago|reply
[+] [-] imheretolearn|4 years ago|reply
[+] [-] lordnacho|4 years ago|reply
Java is also a good base for looking at other JVM languages, and for looking at the JVM itself. That's gotta be part of a good curriculum too, doesn't it?
[+] [-] leetcrew|4 years ago|reply
[+] [-] unknown|4 years ago|reply
[deleted]
[+] [-] ptstomp|4 years ago|reply
[+] [-] popotamonga|4 years ago|reply