18 ms·
Java 21 makes me like Java again
- kaashif 3y agoNice article as someone familiar with sum types but not sum types in Java. I don't know if sum types alone are enough to get me to like Java, pervasive nullability is still around and even rears its head multiple times in this article.
- pharmakom 3y agoIt's also not expression orientated yet.
- kaba0 3y agoFortunately switch has now an expression variant. But I would die for an if-else expression (very subjective, but I would prefer a more verbose if-else to ternaries), and especially a try-catch expression!
- leapis 3y agoNullable is a huge issue in Java, but annotation-based nullability frameworks are both effective and pervasive in the ecosystem (and almost mandatory, IMO). I'm really excited about https://jspecify.dev/ https://jspecify.dev/, which is an effort by Google, Meta, Microsoft, etc to standardize annotations, starting with @Nullable.
- mrkeen 3y agoI was just writing about nullability annotations! https://news.ycombinator.com/item?id=37534184 https://news.ycombinator.com/item?id=37534184
- wayfinder 3y agoI hope they succeed. So many people have tried.
- mrkeen 3y agoNot having nulls is easy. Persuading Java devs not to use nulls is hard.
- kaashif 3y agoThis can never be as effective as changing the default reference type to be not nullable, which would break backwards compatibility, so you can never really relax. I know Kotlin is basically supposed to be that, it has a lot of other stuff though, and I haven't used it much.
- martindevans 3y agoThat's basically what c# has done. But it's implemented as a warning which can be upgraded to an error. I think it might even be an error by default in new projects now.
- kaashif 3y agoHoly shit, how didn't I know they'd taken it this far? This is great! https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references#nullable-contexts https://learn.microsoft.com/en-us/dotnet/csharp/nullable-ref... They actually fixed the billion dollar mistake...
- 5e92cb50239222b 3y agoThey didn't. A proper fix would require getting rid of null altogether in favor of ADTs or something similar. I work with C# daily and nulls can still slip through the cracks, although it's definitely better than @NotNull and friends. I haven't worked with Kotlin in a while, but IIRC their non-nullable references actually do include runtime checks, so you cannot simply assign null to a non-nullable and have it pass at runtime like you can (easily) do in C#.
- foolfoolz 3y agothey won’t change the default reference type to non null. might take a few years but you can see their planned syntax here: https://openjdk.org/jeps/401 https://openjdk.org/jeps/401
- netheril96 3y agoNullable annotations don’t work with well with generics, or at least those tools I use.
- wscp-dev 3y agoWith valhalla, we will have explicit nullability as well, so that problem will also be handled.
- acheron 3y agoIn other news, we have an upgrade path at work to go from Java 8 to Java 11 pretty soon.
- hmottestad 3y agoGoing from 11 to 21 is a lot easier.
- leapis 3y agoDepends- one of the hardest parts of the 11-20 upgrade for us was that cms gc was removed. If you run a bunch of different microservices with distinct allocation profiles, all with high allocation pressure and performance constraints, and you've accomplished this w/ the help of a very fine-tuned CMS setup, migrating that over to G1/ZGC is non-trivial
- hmottestad 3y agoIs that what happened at your company?
- leapis 3y agoYup. We've clearly benefitted- G1 and generational ZGC have large advantages over CMS- but it's a lot of experimentation and trial-and-error to get there, whereas other deprecations/removals are usually easier to resolve.
- kaba0 3y agoIsn't the default config correct for pretty much all workloads, unless you have very special requirements? Like, at most one should just change the target max pause time in case of G1, depending on whether they prefer better throughput at the price of worse latency, or the reverse.
- xxs 3y agoJava sort of suck for microservices (microservices suck on their own) as it has relatively high bootstrap cost. High allocation rate feels weird with micro services - I suppose that depends a lot on the coding style. G1GC is meant for generally large setups, with several cores at least. E.g. the default setup of 2048 areas on 2GB heap means, allocations over 1MB require special care.
- Horffupolde 3y agoCan you convince me to use Java? I’ve never used it (only C++, Python, CL) but it feels bloated and dirty.
- justrealist 3y agoHow could you possibly like C++ but feel that Java is bloated? Like I academically understand disliking Java but this just makes no sense.
- jjnoakes 3y agoI think of Java as more bloated than C++ at runtime - with C++ I can make smaller executables that start up faster, use less memory, etc. But if you are talking about the source code itself, then things are quite different.
- Jensson 3y agoC++ allows for much more terse code than java when you do small projects. It is popular in competitive programming for that reason, not just because it runs fast but also because it is really fast to write algorithms in it.
- loxias 3y ago??? I'll answer your question with a question: Have you seen https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris... ? :) I'm guess that to those of us who remember when Java came out, "FizzBuzz: EE" is what we think of when we think of Java. :P In Java I have to type a bazillion characters to get anything done! And make all these useless directories and files and InterfaceClassFactoryProtocolStreamingSerializer BS. And worry about how that executes. C++? No bloat*, just speed *Yes, there's some _optional_ bloat. But compared to Java? no contest.
- deleted 3y ago[deleted]
- 3y ago
- xyst 3y agoBig firms I have worked at still using Java 8. Dead.
- avbanks 3y agoA lot of Apache projects still use Java 8 :(
- bombcar 3y agoAt least you can now run Minecraft 1.7.10 on Java 17 - https://github.com/GTNewHorizons/lwjgl3ify https://github.com/GTNewHorizons/lwjgl3ify
- wscp-dev 3y agoWhat a marvel of engineering.
- Phelinofist 3y agoWe have an app that also needs to be able to run on Android, so we are held back by the shitty Java Google implements for Android.
- guideamigo_com 3y agoYou can use [limited] Java 17 with Google's Android. The compiler converts Java 17 -> Java 8 bytecode.
- tleilaxu 3y agoI agree that many companies are “stuck” (through their own choice really)… but at least Java is moving now. In many ways Java’s boringness is a feature that keeps it easily maintainable, at a low - easily recruitable - skill level.
- deleted 3y ago[deleted]
- insanitybit 3y agoThe problems with Java can't be fixed by adding new things, you can't undo decades of ecosystem development, training, and ideology built on top of the idea that inheritance is really good idea and belongs everywhere. edit: I will say that as a Java developer I am grateful every day for the improvements to the language. Java is a very impressive language and I have a lot of respect for the people working on it.
- matsemann 3y agoI rarely see inheritance used in practice in java code bases. Except where I would use a union type or sealed class in other languages anyways. I don't feel what youre describing is a real issue.
- insanitybit 3y ago> I rarely see inheritance used in practice in java code bases. That seems absurd to me and I have a hard time understanding it, honestly.
- wayfinder 3y agoIf you type everything with interfaces in your codebase, you are much less tied to inheritance. In fact, everyone could be written to be composed. However Java doesn’t support type union so you can get into some ugly and verbose situations but the JVM doesn’t really check type so this is more a compile-time issue and could be fixed in a future Java language revision.
- logicchains 3y ago>However Java doesn’t support type union so you can get into some ugly and verbose situations Isn't the "sealed interface" described in the OP blog post a type union? Or you mean anonymous unions?
- wayfinder 3y ago
- KillenBoek 3y agoThe problem with Java is not Java. It is Oracle and no amount of new features is going to fix that.
- kaba0 3y agoCan this fkin FUD finally die? Java is pretty much the safest bet on a longevity, stability, risk aversion spectrum. Also, Oracle just has a particularly bad PR, but it is not at all worse than any other similarly sized company.
- wscp-dev 3y agoOracle has definjtely done bad things; mismanagement of java is not one of them. They got a pile of crap and turned it into something competent.
- ant6n 3y agoBut, you know, Java too.
- riku_iki 3y agoI am wondering if Oracle is really playing significant role in Java evolution, they have some open process with many other companies contributing.
- kaba0 3y agoThey are responsible for like 95+% of all OpenJDK commits.
- northern-lights 3y agoThe biggest feature in Java 21 is the release of Virtual Threads: https://openjdk.org/jeps/444 https://openjdk.org/jeps/444 For some reason, this is missing from the article. If there was any feature that would sway existing Golang developers to switch to Java, it would be this. It would perhaps also convince the haters of the reactive-style concurrency patterns.
- imetatroll 3y agoNo thank you. There is limited time in the day and go fills my needs. Go, Rust, Ruby. These three cover all cases.
- quickthrower2 3y agoAdd Python to that list (for the ecosystem) and JS (for front end web dev)
- belfthrow 3y ago[flagged]
- mongol 3y agoI wonder what will happen with these patterns now. They seem to have been invented to work around the problems with regular threads. Will new patterns emerge, or will the reactive patterns be ported to run on virtual threads?
- bberrry 3y agoThe reactive patterns are now obsolete and will die. And good riddens I say.
- insanitybit 3y ago`Executor.newVirtualThreadPerTaskExecutor` versus `go` really gets to the heart of why I think that Go developers aren't going to be switching. edit: Sorry, it's actually: try (var executor = Executors.newVirtualThreadPerTaskExecutor()) { executor.submit(...) ) instead of `go`
- bedobi 3y ago[flagged]
- bberrry 3y agoAs a Kotlin dev you should still be excited by virtual threads in Java 21. You'll never have to use coroutines again.
- ledauphin 3y agoI'm very curious to see how this works out in the Kotlin ecosystem, given the amount of async code out there (and the associated function coloring issues).
- mike_hearn 3y agoYou can easily combine the two, just use a virtual thread and when you hit a `suspend` function use `runBlocking` to get rid of the suspension.
- 1n3nt0r 3y agoLet's not forget that the JVM still does not have reasonable generics & value types. The .NET CLR introduced this in 2005, bettering the JVM. Java was in a sleepy slow release mode back then. We've been waiting 18 years for value types and proper generics - Valhalla has been just about ready for a very long time. Some of us moved on a long time ago. Agree that Kotlin is a bright spot in terms JVM languages. For my taste has adopted some of the best concept of Scala, but without the burgeoning complexity.
- bedobi 3y agoC# def brought a lot to the table vs Java but I feel like it has also kind of stagnated and not realized the potential of F#. Scala likewise is very powerful but def overly complicated and difficult. Kotlin + Arrow hits the sweet spot, at least for me.
- wayfinder 3y ago
- gabereiser 3y ago[flagged]
- cmrdporcupine 3y agoThis ... is how you make engineering choices?
- gabereiser 3y agoAt work, I have a different context. What is the common denominator of what people know. Personally, the “write once, run everywhere” notion of Java has been replicated with much more productive languages.
- cmrdporcupine 3y agoSounds like you're talking about a pop band, not a tool.
- riku_iki 3y agoso, which lang would you use personally? > you still have threadpools and os threads. why this is a bad thing exactly?
- gabereiser 3y agoGolang or Rust. If it’s a web service or microservice: Golang hands down. If it’s a desktop software or game engine, rust. If you just want to typescript your way to success, deno and vite. If you’re too introverted for Rust, Zig. Java, whether it be spring, micronauts, jee, whatever, is wasting CPU and Memory in the cloud costing you and/or your enterprise money.
- riku_iki 3y ago> Golang golang is probably a good contender for business logic code where Java is widely used, but I feel ecosystem (libs, integrations) is not comparable to Java, so you take some risks while choosing golang.
- logicchains 3y agoI can't wait 'til Project Valhalla is complete and Java finally gets value types. Then with sum types, value types and goroutines it'll be one of the nicest languages out there.
- mathisfun123 3y agoany advice on a book/tut to learn "modern" java?
- Tomte 3y agoCore Java for the Impatient by Horstmann.
- msgilligan 3y agoManning's Modern Java in Action is outstanding. It assumes you already know basic Java. https://www.manning.com/books/modern-java-in-action https://www.manning.com/books/modern-java-in-action
- mathisfun123 3y agoboth suggestions here are for books that cover java 8. how is it possible that java 8 is modern relative to java 21?
- Tomte 3y agoCore Java for the Impatient (3rd) is less than a year old and updated for Java 17.
- mathisfun123 3y agoexcellent - thanks
- msgilligan 3y agoModern Java in Action (the 2nd edition of Java 9 in Action) covers Java 11 and contains a final chapter that talks about "future Java" features -- many of which are now implemented. It's a great book for Java programmers who want to make the jump to functional-style programming. If that's the transition one is hoping to make, then I would definitely recommend the book.
- 3y ago
- aranchelk 3y ago> Why do we call them product types anyway? Answer in the piece is not wrong, but put more intuitively and succinctly: the total number of possible value (inhabitants) in a product type is the product of the quantity of inhabitants of the constituent types. Replace the “product”s with “sum”s and it works too. Interestingly, the total number of unique functions (judged only in terms of input and output) from a -> b can be found by exponentiation, (inhabitants of b) ^ (inhabitants of a).
- wscp-dev 3y agoIll add that in, somehow forgot about that golden bit of info
- trenchgun 3y ago>Answer in the piece is not wrong, but put more intuitively and succinctly: the total number of possible value (inhabitants) in a product type is the product of the quantity of inhabitants of the constituent types. More intuitively and succintly: product type is equivalent to a cartesian product of sets
- tubthumper8 3y agoMaps (and lists) are other examples of exponential types. Intuitively this should make sense that these are the same as functions because any pure function could be (theoretically) replaced with a map lookup of pre-computed values. In this context, list is a special map where the keys are integers. Writing it out mathematically, given a List of Bool, the left-hand side is the number of elements and the right-hand side is the total possibilities. - 0 : 1 - 1 : 2 - 2 : 4 - 3 : 8 - 4 : 16 - 5 : 32 and so on
- jjtheblunt 3y agoIs there an Ocaml vatiant for the JVM (similar to F# for dotnet)?
- satvikpendem 3y agoI know of Scala for an FP variant but nothing that's ML-like specifically.
- trenchgun 3y agoWell, one could argue thay Scala is a ML for JVM with Java syntax
- iddan 3y agoYou could say Kotlin to some extent..
- Tmpod 3y agoYeah, it has nice funcional capabilities and libraries (like Arrow[0]). [0]: https://arrow-kt.io https://arrow-kt.io
- jjtheblunt 3y agoI just found this: https://flix.dev/ https://flix.dev/
- neonsunset 3y agoSad this gets to front page while a blog post which documents that .NET 8 has 200 A4 pages worth of performance improvements gets absolutely ignored. C# keeps being the language people are looking for but don't know about.
- romanovcode 3y ago> C# keeps being the language people are looking for but don't know about. Every time I point out about C# most programmers are saying about evil Microsoft and being locked in the ecosystem. Most programmers I've met do not even know that .NET Core is MIT open-source and runs on any device. I really wish C# would be more widely used because it is amazing, and for sure 10 times better then Java.
- mu53 3y agoIts a good language, but the corporate sponsor and community is suspect. Microsoft has a long history of user hostile actions. The types of companies that use C# often treat SWE as second class. Learning and using C# limits career options to low salary, high stress jobs.
- neonsunset 3y agoI'm going to vouch for this comment but not because it is correct but rather it presents good opportunity to address the concern. C# and .NET are most heavily invested in by Microsoft which owns and steers its development, that is true. It is also true that JVM world sees investment from multiple MSFT-sized corporations. And yet, despite the above, it keeps moving forward and outperforming Java on user experience, performance and features despite being worked on by much smaller teams. I think it stands on its own as a measure of a well-made technology. In addition, you can look at source code and contribute yourself, 90% of what makes .NET run is below. Almost all development happens in the open: https://github.com/dotnet/runtime https://github.com/dotnet/installer https://github.com/dotnet/roslyn https://github.com/dotnet/aspnetcore Could Microsoft do a better job at making it even more community-facing and attempting to make the .NET foundation as a sole owner and steering committee of the language itself? Sure. But it's not that bad either today. Quick reminder - Oracle is not exactly a saint, perhaps even worse (MSFT has never gotten into any litigation even remotely related to .NET or C#). As for career opportunities, as other commenters would note, this is highly specific to a region and does not translate globally. Again, we are discussing the "how good the language/platform is" first and foremost. I don't see startups adopting Go because of the market or trusting Google not to rug pull them...so perhaps we can do a better job so the next language of choice they pick is C#, which has much higher ROI in the hands of the good developers (for example, it can be very easy to adopt as a second language if you are well versed in Rust).
- slotrans 3y ago> This set of changes allows Java to express one of the foundations of functional programming that the language never could before - Algebraic data types, along with idiomatic ways of using them. And here I thought the foundation of functional programming was functions, which Java still doesn't have. Seriously, functional programming is about functions, not types.
- chii 3y ago> functional programming is about functions different people mean different things when referring to functional programming. Some people believe that functional programming are using higher-order functions like `map`, `reduce`, `forEach`, etc, which takes a function as a parameter, instead of doing imperative loops. Some people, in addition to above, believe that functional programming is about creating functions that take a certain 'shaped' parameters, to allow for automatic checking. And lastly, the "real" functional programmers are people who believe in referential transparency in your functional program.
- deleted 3y ago[deleted]
- kaba0 3y agoHow is Math::sqrt not a function in Java? Sure, it’s called a static method and it lives in a class - but is it meaningfully different from the same being a function in a Math namespace in say, C++? You can static import it even and use it as a function. This is just needless hair splitting imo.
- mrkeen 3y ago> And here I thought the foundation of functional programming was functions, which Java still doesn't have. > Seriously, functional programming is about functions, not types. Well it does have methods and it does have "Functions" (not to mention "Bifunctions", whatever those are). And there's certainly nonsense around exceptions and referring to outer variables. And no currying. But if I understand you correctly, you real complaint is about not having effect-free functions, right? But then it becomes about the type system again, because that would be the mechanism to prevent effects.
- billfruit 3y agoDoes it add value types?
- wscp-dev 3y agoThatll probably come in about a year or so going by the pace of valhalla's completion.
- ArandomAccount2 3y agoHas anyone used virtual threads? I tried to migrate my app over to VT's and kept experiencing random deadlocks and I couldn't figure out what was causing them. I tried moving all the synchronized blocks to reentrant locks, but that didn't work. I also tried turning on the TV debugging system properties, but none of them printed the problem.
- marsven_422 3y ago[dead]
- adrianmsmith 3y agoThe "Sealed classes" feature, as described here, just feels all wrong to me. They are saying that if you have a (normal) interface, anyone can create a new class implementing it. So if you do if (x instanceof Foo) { ... } else if (x instanceof Bar) { ... } ... then your code will break at runtime if someone adds a new class, as that code won't expect it. So the article is saying the solution is to use the new "sealed" interfaces feature, so nobody can create any new classes implementing that interface, and your "if" statement will not break. Surely object-oriented programming already thought about that and already solved that? (I know object-oriented programming is out of vogue at the moment, but Java is an object-oriented language.) The solution there is to add a method to the interface, and all your classes implement that. Then rather than having a massive if/switch statement with all the options, you call the method. That is better than preventing people from extending your code, it allows them to extend your code. They just have to implement the method. And the compiler will force them to do that, so they can't even accidentally forget. The example given of color spaces (RGB, CMYK etc.) is a great example. I can absolutely imagine writing code which uses color spaces, but then some user or client having a need to use a weird obscure color space I haven't thought of. I wouldn't want to restrict my code to saying "these are the color spaces I support, due to this massive if/switch statement listing them all, the code is written in such a way that you can't extend it".
- nine_k 3y agoThere are valid use cases for that. Consider a security interface of some sort, e.g. such that validates a security token. With a normal interface, it is easy to implement it and ignore the token (allow all), siphon off the token, add a backdoor, etc. If a class doing that is somehow injected where a security check is done, it can compromise security. Now with a sealed interface, there cannot be new, unanointed implementations. If you get an object that claims to implement that interface, it's guaranteed to be one if the a real, vetted implementation that does the actual security check, not anything else. You've just got rid from a whole class of security bugs and exploits.
- pkolaczk 3y agoThe solution with sealed classes also allows anyone to extend the code, but in a different dimension than the solution with an interface method. The solution with interface method and virtual call is very inflexible when you want to add new operations instead of adding new classes. If you want to just add one new operation, then you have to go to all the implementations and add new methods. And you possibly break the implementations you don't have access to. And all those methods must be defined in a single class, even if they are unrelated to each other. This seriously degrades code readability (and performance as well - those vcalls are not free either). The sealed class extends much better in this case. You just add a new switch in one place and done. No breaking of backwards compatibility. This is the famous expression problem. https://pkolaczk.github.io/in-defense-of-switch/ https://pkolaczk.github.io/in-defense-of-switch/
- valenterry 3y agoFinally Java catching up with some basic features that Scala has for 10 years or so. Hoping that more good stuff from Scala will get into Java soon, maybe at some point I can try to use Java again. :-)
- deleted 3y ago[deleted]
- pregnenolone 3y ago[flagged]
- lakomen 3y agoThe biggest problem with Java is... the walled garden, the snob society, the elitist, exclusive culture. Go isn't like that, or at least wasn't when G+ was still around. Nowadays I don't get in touch much with people, but when I create issues Go people are usually not as unfriendly as Java/JVM people.
- boxed 3y agoRudeness scales mostly with the size of the community. If you go to something like Nim you will immediately find them way more nice than Go, just from this.
- raincole 3y agoJava? Elitist...? Maybe it's true for Haskell or Rust. But Java?
- bsdnoob 3y agoImo problem with Java is... JVM because it's quite a resource intensive application itself, memory usage is orders of time magnitude worse than most of the language I've used.
- sz4kerto 3y agoInteresting. A Spring Boot webapp (with the runtime dependency injection framework, etc. etc.) serving some static content and exposing some REST endpoints works fine with 32 MB RAM. Is it really orders of magnitude more than other languages, e.g. will a Go-based webapp consume less than 300 kBytes of RAM?
- wscp-dev 3y agoI do believe that number will go down in the coming releases; things like valhalla will allow us to pack data representations much more efficiently after all. the only things that really benefit from object identity are behaviors, not data.
- belfthrow 3y ago
- ahurmazda 3y agoMy favorite go feature (not exclusive to go) is `implicit` interface. Once I drank from that cup there is no going back!
- deleted 3y ago[deleted]
- andrea76 3y agoI hate Java because the docker containers based on it take too much RAM. The smallest Spring JAR takes about 70-120 MB for a single container!
- jiehong 3y agoHate spring instead ;)
- pharmakom 3y agothe argument for Java seems to be that it's gradually gaining features we already have in Scala, Kotlin, OCAML, F#, etc... so why not use the languages that have those features today?
- msgilligan 3y agoOne thing about "gradually gaining features" is that the Java language architects do a very good job with backward-compatibility. This means that your application/library will be easier to migrate to newer versions of the language and you will continue to have a large number of 3rd-party libraries available. The Scala community is currently migrating to Scala 3 and many libraries have not been ported (Scala experts correct me if I'm wrong.) Kotlin also seems to be less stable at the API level than Java (but I may be wrong here, Kotlin experts please correct me.) This backward-compatibility does comes with costs (e.g. non-reified generics) Also, if you're a library developer and you want to create a JVM library that can be used by Scala, Kotlin, etc. developing in Java is often the best choice. For one thing it avoids any dependencies on the standard libraries of those other languages. Disclaimer: I like Kotlin and Scala, but mostly use Java.
- agrounds 3y agoInertia. There are still a ton of Java shops out there, and many of them will not switch even partially to another language anytime soon. The hope is that these orgs might find it easier to upgrade to Java 21+ than to learn and start using Kotlin/Scala/etc. I fully expect I might find myself working at such an org again, and when I do I’ll be grateful for newer Java features. Signed, a dev who would never willingly choose Java over Kotlin for anything ever again.
- MagicMoonlight 3y agoBecause Java will still exist in 5 years
- truth_seeker 3y agoGolang is simple, smart and opinionated subset of Java/C#. Everything moves slowly in corporate world. It will take another at least 2-3 years for large community of Java ecosystem and average devs to adopt Java 21 and capabilities.
- kaba0 3y agoGo is just a dumb subset hyped up as simple, but it is useless and slowly it will have to introduce all the remaining pieces in some ugly way as they didn’t plan with them ahead of time - see generics.
- truth_seeker 3y agoThat is exactly what I used to think when I started with it. But I changed my opinion after 6 months with Go and eco-system. It's not ugly, it's different and much more concise.
- kaba0 3y agoIt is more verbose than java by all objective counts.
- philosopher1234 3y agoI think there may be a “Penny wise but pound foolish” thing going on in your analysis.
- msgilligan 3y agoThe title of the blog post is IMO a poor choice. The (hidden) subtitle of the post is "Algebraic data types in Java" which is much more descriptive of the content. A better title would have been "Algebraic data types in Java 21". Perhaps because of the title, many/most of the comments here are off-topic. I was hoping to see more discussion about algebraic data types, strengths and weaknesses of the Java implementation, technical comparisons to other languages, etc.
- fatfingerd 3y agoYes, I'm also not really sure I want to see algebraic types in Java even though I would prefer if a language that focused on algebraic types was more popular. All the existing Java code doesn't go away, so is it really going to be nicer to have code like this mixed randomly into that?
- owlstuffing 3y agoOf all the features most Java devs (and ex-Java devs) desire, algebraic types are near the bottom. How about intersection and union types? (NO, sealed classes are not a substitute for unions). But, yeah, in my view JDK 21 is a a disappointment. I rarely want pattern matching, but I would like properties please and records are nice, but actual tuples are more useful. Etc.
- smrtinsert 3y agoI would love a union type in Java, but I still enjoy the language, community and especially development experience. I wouldn't recommend it for everything, but it's sturdy by design and enjoyable for when it fits.
- mu53 3y ago[dead]
- mx_02 3y agoI'd love if interfaces worked as in typescript. As long as the object signature matches the interface as parameter then you can use it.
- earthboundkid 3y ago道生一,一生二,二生三,三生萬物。萬物負陰而抱陽,沖氣以為和。 The Function gives birth to the Unit type. The Unit type gives birth to the Boolean. The Boolean gives birth to the Value type. The Value type gives birth to the Top type. Each Top type contains 0s and 1s, thereby bringing harmony to the computation.
- dzonga 3y agojava was never really a bad language. the people were. if not massive over-engineering. too many abstract concepts that make it hard to grasp a codebase. code voodoo - in the form of reverse GOTO statement i.e annotations DI frameworks . what needs fixing is not the language but the ecosystem. there needs to be a "reformation" movement within the java ecosystem. yeah people migrating to kotlin or clojure or scala isn't enough.
- _gabe_ 3y ago100% agree. You can create a HammerFactoryFactory to churn out HammerFactories in any language. But the ecosystem in Java (and C# is similar imo) promotes and encourages this type of problem solving. The one thing Java really does need is free standing (or namespaced) functions though. Sometimes I don’t want a class, what’s wrong with a function in a module or namespace in that case?
- MagicMoonlight 3y agoA class is a module/namespace. You can make a class just to have functions in it.
- _gabe_ 3y agoIt’s not though. In lots of languages a namespace can span multiple files, whereas a class must be declared in a single file[0][1]. Modules can usually contain a collection of functions and classes. And namespaces can also contain multiple classes/structure/functions and sometimes modules depending on the language[2]. [0]: https://www.typescriptlang.org/docs/handbook/namespaces-and-modules.html https://www.typescriptlang.org/docs/handbook/namespaces-and-... [1]: https://learn.microsoft.com/en-us/cpp/cpp/namespaces-cpp?view=msvc-170 https://learn.microsoft.com/en-us/cpp/cpp/namespaces-cpp?vie... [2]: https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/namespaces https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...
- jjtheblunt 3y agoIs there any widespread concern over lack of unsigned int native types?
- kaba0 3y agoNot really. With valhalla they can be user-implemented efficiently, although without syntactic sugar like +.
- jjtheblunt 3y agoDoes that mean addition would look like Uint32 a,b,c; c = a.plus(b); in what you describe, once project valhalla is complete?
- kaba0 3y agoWell, that will be available as a basically zero-cost abstraction. But I haven’t seen more specific mention of it in the mailing lists/design proposals - they definitely didn’t want to add a new primitive type, but perhaps if they manage to heal this rift between objects and primitives and it will only be add syntax-level complexity, they might go for it.
- YetAnotherNick 3y agoJava was always a great language. It's the enterprisy ecosystem that make me want to throw up. To implement a line of logic, I have seen dozen classes and interfaces.
- michaelcampbell 3y agoWhat a weird title change.
- wscp-dev 3y agodid that to make it a bit clearer what I was really optimistic about, but I unfortunately can't edit the hn post itself.
- fooyc 3y agoThe author cites this to justify the need for Records: > Most Java objects set every field to be private and make all fields accessible only through accessor methods for reading and writing. > Unfortunately, there are no language enforced conventions for defining accessors; you could give the getter for foo the name getBar, and it’ll still work fine, except for the fact that it would confuse anybody trying to access bar and not `foo'. Scala supports pattern matching on objects implementing the `unapply` method. Is this considered harmful? Why didn’t Java follow this route?
- wscp-dev 3y agoit's a matter of standardisation again. Java's standard is like C++; ponderous. The record pattern jep indicates in final footnotes that something like unapply may be in the works, so all hope is not lost.