14 ms·
I haven't written Java in a million years.. so I'm trying to understand better. But what does this code even mean..? Isn't Java's whole simplifying model that
by geokon 2y ago
I haven't written Java in a million years.. so I'm trying to understand better.
But what does this code even mean..? Isn't Java's whole simplifying model that everything lives in "Objects"? This seems to break that fundamental paradigm and makes the language more complicated. If you needed something like global functions then in vanilla Java as I remember you'd stick it into static final Objects that acts as a namespace of sorts. So you don't need to worry about functions floating around in a global namespace soup.
If you're gunna just have free floating functions in your file.. then why not just cut to the chase and have a
println("Hello world");
floating in your file..? (I mean... you don't have REPL so maybe that wouldn't be too meaningful...)
- int_19h 2y agoIt's implicitly still a class, you just don't need to write all the scaffolding to indicate that. The functions are still methods of that class etc. But, yes, with static imports, you can just write "println" like that and have it work.
- almostgotcaught 2y ago> It's implicitly still a class, you just don't need to write all the scaffolding to indicate that. did you know that every function in a python script is actually an attribute of that module (which is basically a class). so my point is: who cares.
- imtringued 2y agogeokon's point still stands. This is meaningless syntax sugar that does not change anything fundamental about Java except add one more special rule into the language aka it is one more thing to learn. Rather than being helpful, it just becomes friction when an old developer uses the old method and a new developer uses the new method. You still need to know what a main class is, so that you can reference it in your build.gradle file.
- losvedir 2y agoIf you're using a build.gradle file then you probably won't see any benefit to this implicit class, yes. But it's useful for little one-off scripts, where you just go `$ java foo.java` from the command line.
- semiquaver 2y ago> you don't have REPL (ahem) https://docs.oracle.com/en/java/javase/23/jshell/introduction-jshell.html https://docs.oracle.com/en/java/javase/23/jshell/introductio...
- spullara 2y agoonly since 2017 :) people basically judge java based on what you learn in AP CS which is basically (a dumbed down version of) java 6 (released 2006).
- vips7L 2y agoIt’s honestly the only programming language that will get its 1996 version compared to a new 2025 version of another language. And the only language that will be criticized by someone who last used it in 2006.
- homebrewer 2y agoPHP gets the same treatment all the time.
- AmpsterMan 2y agoPHP and Laravel are amazing.
- mey 2y agoI have been developing Java for a long time and my brain tends to stay stuck in Java 8 mode a lot of the time.
- james_promoted 2y agoDefinitely not the only language. Other long-lived languages like C++ get this treatment too.
- motorest 2y ago> And the only language that will be criticized by someone who last used it in 2006. You don't sound like you work with Java. I know for a fact that even some FANGs, with their army of software engineers, still use Java8 for most of their Java projects.
- Quekid5 2y agoI'm having such a hard time figuring out whether this is satirical. (My guess: It is.)
- Joker_vD 2y agoI know, right? > So you don't need to worry about functions floating around in a global namespace soup. Because having classes floating around in a global namespace soup is fundamentally different and should give no worries to anyone. Yet this was argument made in earnest back when arguments about Java's strengths and weaknesses were much more popular.
- deleted 2y ago[deleted]
- gf000 2y agoAs others mentioned, there is an implicit class here in play. Basically, imagine a `class Temporary4738 {` and `}` written above and below the .java file's content, that's roughly how it will behave. It not having a fixed name is deliberate, so if you decide to build a bigger system you won't use this mechanism in a hard to maintain way, and also it needed a good semantic model for "top-level" variables/fields. But with this implicit class model, top-level definitions are just fields of the class.
- motorest 2y ago> As others mentioned, there is an implicit class here in play. The same strategy is also followed by C# with their top-level statements. And yes, it's syntactic sugar. https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/top-level-statements https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals...
- winrid 2y agoBecause this is the entrypoint? Having code exec out of an explicitly defined entry point that's an entire file sucks.
- dkarl 2y ago> This seems to break that fundamental paradigm and makes the language more complicated Welcome to the last 10+ years of Java. They're trying to play catch-up to other languages that made fundamentally different and better choices, making Java more and more complicated in the process. They are so deeply entrenched in the enterprise back end space that programmers put up with it, nay, even feel grateful for it. People who are stuck using Java for the rest of their careers are happy to see it grow to accommodate 21st century programming techniques, even if it means that it becomes so complicated and crufty that no beginner will touch it ever again.
- x0x0 2y agoIn java's defense -- and I share your criticisms -- it offers some very nice things that no other language has. eg want to run code for 6 months at a go managing hundreds of gigs of data, tens of thousands of threads, at high load, with sustained gigs a second of garbage generation? the jvm will just silently tick away doing just that while being nearly bulletproof. As much as I love ruby and python, you ain't doing that with them. With hot code loading, introspection, etc. All the stuff that makes developing super-robust long-lived systems way easier. And the flip side of the clunky language is your code from 20 years ago still works.
- woooooo 2y agoAlso, conservative feature adoption works in the long term. Scala mainstreamed a bunch of concepts that java was slow to adopt, but the end result was java only took the good ideas and didn't take the bad ideas.
- dkarl 2y agoFortunately, you don't have to use Java to use the JVM. There's Kotlin, Scala, Clojure, etc., all of which are simpler languages.
- NBJack 2y agoIt doesn't surprise me; that sounds exactly like how C++ has progressed (sans the enterprise beans, hopefully). 10+ years ago I considered myself proficient at C++. It made sense, I didn't mind the pointers, and while the std library still felt clunky, it was fine. But I tabled these skills, and they indeed rusted a bit, but surely I could bring them out when needed again, right? Smart pointers with multiple variants, judicious use of macros, rampant use of double colons to ensure proper namespace resolution (which IMHO makes the code an absolute eyesore), to name a few. I won't argue these changes aren't necessary, but it isn't pretty.
- paulddraper 2y ago> Global namespace soup Packages still exist. It’s just not necessary to add an additional level of namespacing. Statics never were some pure OOP anyway.