NHacker Next
login
▲Public static void main(String[] args) is deadmccue.dev
146 points by charles_irl 3 hours ago | 140 comments
Loading comments...
crystal_revenge 2 hours ago [-]
One thing I'll miss about this was the way this arcane writing increasingly made sense over time as you became a better programmer.

I learned Java only after Python and I remember being not quite familiar with types so even the 'void' and 'String[]' where a bit mysterious. After learning basic types that part made sense. Then you start learning about Classes and objects, and you understood that main is a static method of this class Main that must be required somehow. As you dive deeper you start learning when this class is called. In a weird way what started as complete, unknowable boiler plate slowly evolved into something sensible as you began to understand the language better. I have no doubt that seasoned Java devs see a lot more in that invocation that I do.

Good riddance though!

bjackman 9 minutes ago [-]
I remember our "intro to programming course at university" started with this program and the tutor said "I'm mostly gonna try and explain all the code I show you, as I show it, but this is the exception, you just have to accept this nonsense bit for now".

And yeah, it was pretty cool looking back on it later and realising I knew what it all meant!

And yeah, good riddance nonetheless!

panza 2 hours ago [-]
Yeah, I agree with this sentiment. The boilerplate was oddly helpful when I was starting out.
boxed 54 minutes ago [-]
That's just Stockholm Syndrome. Think about it: what more crazy garbage could you add that is useless for the beginner but "will make sense later"?

The answer is: infinitely much. You could have to write each character in strings as separate characters for example. It would be absolute utter madness but it "would make sense later".

almogo 3 minutes ago [-]
I agree specifically, but disagree generally.

As we become more and more acquainted with programming, a lot of what we do why we do it is incoherent nonsense to a beginner, but important nonetheless.

The limit is actually your time and effort. But nobody likes to write optimal assembly by hand, the balance has to be struck somewhere.

rob74 1 hours ago [-]
Yup... if you're familiar with the old class-based approach, the new style raises more questions than it answers. Did they really turn "everything-is-an-object"-Java into a procedural language? What do you do if you do need command line arguments? Etc.

(I somehow mostly avoided learning Java, and my last passing contact with it was 20+ years ago, so these are honest questions).

js2 56 minutes ago [-]
The class is still there, implicitly.

The main function can be written with `String[] args` if you need it.

This is a decent summary of the changes:

https://www.happycoders.eu/java/main-method/

Further details:

https://openjdk.org/jeps/512

bilekas 53 minutes ago [-]
If it's anything like dotnets change the void params are still a valid input.
raverbashing 57 minutes ago [-]
Except a static class method is just a hand-wavy way of denying reality: that a program has a single entry point that has nothing to do with classes

As much as C++ has a lot of problems, them and other languages (python/ruby/etc) never denied that the procedural world existed, while Java wants to blindfold you and push you through a corridor until you get out of it and into the "perfect (not) OOP world"

pansa2 33 minutes ago [-]
> python/ruby/etc never denied that the procedural world existed

Interestingly, those two languages use very different mechanisms for top-level functions - although I’m not sure if there’s a significant difference in practice.

Python has true standalone functions, whereas in Ruby’s they’re really methods of a `main` object.

Yoric 29 minutes ago [-]
If you're speaking of `main()`, that's not true in Java: you can have many entry points and decide upon launch which one you're using.

If you're speaking of `__main()`-style entry point, though, you're right, and Java makes it... complicated.

mayoff 46 minutes ago [-]
But in Java, a program doesn't have a single static entry point. You can have as many different classes as you want, each with its own static void main, and choose which to use as the entry point when you start up your JVM.
Joel_Mckay 2 hours ago [-]
In general, Java made OO design trivial to implement, but due to a clear specification standard requirement a lot more planning/time is needed.

Thus, many sub-optimal project coordination approaches ended up fighting the design patterns. Java is a good student language, but there are so many better options now... with fewer footguns, and without Oracles farts. =3

vkazanov 1 hours ago [-]
None of the Java and OOP problems were created ar Oracle.

As much as I love hating Oracle, they pushed the language forward much more than Sun ever did.

Joel_Mckay 56 minutes ago [-]
Interesting opinion, but that is only applicable for enterprise clients. The public gets a NERF'd legacy option full of known problems, limitations, and legal submarines.

The only reason Java is still somewhat relevant is ironically Android/Kotlin, and SAP/heinous-dual-stack-blobs product lines.

Best regards, =3

vkazanov 36 minutes ago [-]
It is not "an interesting opinion". It is an opinion of a mid-level engineering manager who spent the last decade hiring and building teams across various parts of the industry.

Java/JVM is literally everywhere. And let me get this clear: not a fan of both java-the-language and java-the-culture.

Joel_Mckay 7 minutes ago [-]
Interesting perspective, the exact same argument was made for COBOL and Fortran.

Most Enterprise level Java I saw was not clean OOP, but rather a heinous kludge sitting next to a half-baked design pattern. The 3.6B Android OS users in the world probably are more relevant in terms of development projects, and keeping your team staffed. Good luck =3

ludovicianul 50 minutes ago [-]
While Android/Kotlin keeps Java in the spotlight, Java also powers financial services, high--frequency trading systems, payment gateways, logistics platforms, and even modern microservice deployments. These are not all “legacy”,they’re mission-critical platforms handling billions of transactions daily.
Joel_Mckay 34 minutes ago [-]
The exact same argument could be said for COBOL and Fortran.

>high--frequency trading systems

Probably not the Java stack itself, given GC latency and precision timing skew would translate into millions of lost dollars a second. However, people do silly things in the wrong languages all the time. =3

npstr 19 minutes ago [-]
It looks like you're not up-to-date, ZGC has pauses on the microsecond dimension. Even since before ZGC was added, there are open source libs for HFT that optimize allocations to avoid GC: https://github.com/openhft =3
Yoric 27 minutes ago [-]
FWIW, I've seen job ads for Java developers in HFT.

It did look weird, of course, but they're also using Go (which iiuc has worse GC latency) or other garbage-collected languages (OCaml being a famous example).

mfru 1 hours ago [-]
So tell us what the better options are in your opinion?
Joel_Mckay 42 minutes ago [-]
A lot of folks prefer Scala or Kotlin even on a janky JVM.

Depends on the use-case, but I also like Elixir/Erlang, Julia, and Go.

Not all are very popular, yet each offer something uniquely beautiful. =3

znpy 1 hours ago [-]
Java is essentially open source enough that you can ignore oracle. All the development of java happen in openjdk, of which oracle is a contributor (along with red hat and many others). Oracle’s java is just an openjdk distribution, with some additional proprietary bits.

Pulling the oracle card when java is mentioned is a useless stunt.

Joel_Mckay 54 minutes ago [-]
The OpenJDK has come a long way, but is still less than ideal.

Do you actually use that option at enterprise scale? =3

fiddlerwoaroof 41 minutes ago [-]
Everywhere I’ve worked has used Eclipse Temurin or another open source release: the Oracle JVM isn’t used all that often because of license issues.
abhiyerra 2 hours ago [-]
I learned to read line as the following in Java 1.2 so the Scanner class is new to me. :p

  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  String input = in.readLine();
riffraff 2 hours ago [-]
Yep, same for me, it's been a long time since I did java and while the publicstaticvoidmain mantra felt familiar I was a bit confused by the Scanner thing and couldn't say why.
Frieren 2 hours ago [-]
My experience may be different from the rest of people at HN. But I am used to work in large projects that last decades. How main is written is totally irrelevant for my day to day work or my career.

How does it affect you this change day to day?

almogo 2 minutes ago [-]
Frieren working on projects that last decades. Ya don't say... ;)
kllrnohj 1 hours ago [-]
Or if you're an Android developer then main doesn't exist at all and never has

But yeah I don't understand why the author is so excited about this. How "ugly" a trivial "Hello, World!" does not really matter much and isn't a good indication of anything about the language's ability to handle more than "Hello, World!"

bawolff 58 minutes ago [-]
I think it does say something about what a language thinks is important.

Java (historically) is famous for going a bit too hard core into overly abstract & verboseobject oriented design patterns - create a factory to get another factory to get a different factory and whatnot. The hello world is where java shows that style of code is what historical java felt was the ideal.

antris 53 minutes ago [-]
>How "ugly" a trivial "Hello, World!" does not really matter much and isn't a good indication of anything about the language's ability to handle more than "Hello, World!"

Sure, but for beginner programmers who don't have the discipline down yet, it's unnecessarily hard. I bought a Java programming book as a kid and got stuck because of a typo that produced an error message I couldn't understand. This was the time before StackOverflow and Reddit. In retrospect, this delayed my programming journey by at least a year.

Longer Hello Worlds make frustration and getting stuck like this more likely.

ertian 1 hours ago [-]
Many of us took programming 101 in Java and so typed this dozens of times without having a clue what it meant.
tankenmate 1 hours ago [-]
I learnt C at Uni (after having taught myself BASIC, Z80 machine code (not assembly), and x86 assembly), when we were taught C it was explained to us what all that sort of thing meant. But having said that most of the class failed to understand.
mrkeen 1 hours ago [-]
Now we can type out the same semantics, and remain clueless about what it means, but with a new obfuscated syntax which stops us from asking about the semantics.
derefr 1 hours ago [-]
Still for the better, because each token you don’t have to type when first learning programming is a token you can’t mistype.

(Though the ultimate conclusion of this line of thinking is that programming 101 courses should be taught in as concise and syntax-light a language as possible, giving the learner as few opportunities to screw up the input as possible. I’m a fan of teaching programming in Ruby, personally. Not theory of programming, mind you; just programming as an iterative human process.)

Frieren 54 minutes ago [-]
> programming 101 courses should be taught in as concise and syntax-light a language as possible

100% this. To make Java be the all-language makes it a mess without a defined goal. It is better to start learning with a language better suited for it. And then the learner can specialize and expand to other languages. This also helps to create awareness that different languages have different use cases.

Yoric 24 minutes ago [-]
Probably not in the least for developers, but it does affect beginners a lot.

I used to teach Java, and the total sum of magic incantations you needed before starting to actually "Hello, world" were an instant turn off for many students.

brap 1 hours ago [-]
I think it’s been at least 5 years since I saw a main in the codebase.

Now that I think of it I rarely even write a truly new class from scratch, usually you just implement/extend some framework-specific thing.

procaryote 46 minutes ago [-]
Java sometimes has a culture of "the proper way to do this is to take all these little pieces and put them together in a specific way" which probably makes sense for an object oriented purist but is a bit of a drag day to day.

The scanner class is one such thing, but you also have things like wrapping a Reader in a BufferedReader to add buffering, and building a Pattern object to build a Matcher object which has a few different methods you can call to actually do anything useful

It is very OO, but it's also a bit annoying, and more modern java libs tend to give you a more comfortable API. Sadly modern java also tends to come with springboot and people who can't do anything, unless they use springboot

signal11 10 minutes ago [-]
> Sadly modern java also tends to come with springboot and people who can't do anything, unless they use springboot

Spring Boot (and Spring generally) is more of a “Java culture” issue — someone on this thread used the term “framework fetishism” and it’s spot on.

Thankfully there are teams, typically in mobile or polyglot microservices environments, who are moving away from this. But yeah — still far too common.

samlinnfer 2 hours ago [-]
JEP 445: Unnamed Classes and Instance Main Methods

Released in Java 21

https://openjdk.org/jeps/445

rerdavies 2 hours ago [-]
:-) So not even remotely dead.
rottc0dd 2 hours ago [-]
From my previous comment in hn:

As a java guy and think python is weird, I don't think this sucks.

But, I also agree that can serve as terrible intro to programming if you start programming right away without understanding the basics of abstractions. But, often when we have tools either designed for a purpose in mind or a dominant paridigm or reaction to existing set of tooling, this can result in understandable yet extreme abstractions.

Java is designed with OOP in mind and it kind of makes sense to have the user to think in terms of lego blocks of interfaces. Every method or class needs to have clear understanding of its users.

public - software handle is for all users

protected - software handle for current and extending classes

default - software is exposed to current package

private - software is restricted to be used in current class alone and nowhere else

So, the beginning of java programming starts with interface exposed to the user or other programmers. Is it weird and extreme. Yes. At least, it is consistent.

veltas 1 hours ago [-]
I agree, this is the whole point of "Hello world", which is to show the boilerplate required to start a program capable of outputting text, as well as the actual code that outputs that text. It's also the chance to get the build tools setup, people forget that some of the 'boilerplate' is the actions required to build, which often are much more involved for newer tools and frameworks.

You can just say initially e.g. when I learned C++ that "#include <iostream>" can be "mostly ignored for now, but just know iostream stands for Input / Output stream, and this line is necessary to e.g. output with std::cout"; and there are no scars left from this.

procaryote 39 minutes ago [-]
Some scars... as cout << was always a bad idea, and taught people early on in their C++ development that being overly clever with operator overloading was expected
gedy 1 minutes ago [-]
Reminds me when Google Translate came out about 20? years ago, I pasted in "public static void main (String[] args)"

and out came in Spanish:

"Secuencia pública de la cañería del vacío de los parásitos atmosféricos"

(Public Sequence of the Vacuum Pipe of Atmospheric Parasites)

adgjlsfhk1 2 hours ago [-]
It's amazing that ~30 years on, Java is finally becoming a not horrible programming language.
willvarfar 2 hours ago [-]
I'm someone who wrote a lot of 'raw' Java and C++ without frameworks, which meant there was a lot less boilerplate and indirection etc. And for me, the big usability boon came about 10 years ago, around the same time for both Java and C++, when they started supporting lambda functions. I started passing code into algorithms and, although it sounds quite complicated, it simplified my programs substantially. Before that syntactic sugar gave the affordance I hadn't been organising my programs that way.

For the longest time Java had been very keen to be explicit, to the point of needing a log of cruft where it just felt like the compiler was checking you spelt every letter of the incantation correctly because both the compiler and you knew unambiguously what simple thing you were trying to achieve. But this tone changed in Java around the time the new entrants like Kotlin started taking over as what you develop in in a way that scala and clojure never managed. And suddenly all the get-out-of-your-way of lambdas saving you typing out classes and anonymous classes arrived and Java became a much nicer experience imo.

Yoric 19 minutes ago [-]
Yeah, as someone with a background in FP, I found anonymous Runnable classes quite awkward.
Nursie 2 hours ago [-]
Now if we could just wean some more of the ecosystem away from the framework fetishism... there's no reason java programs have to be so huge, unwieldy and slow to start.

No reason apart from the framework epidemic that's supposed to make things easier for developers, but in the end hamstrings them and weighs everything down.

(to the downvoters - I am a java developer and this is very real to me at the moment!)

bigstrat2003 2 hours ago [-]
Java was never a horrible programming language. The hate is wildly overblown.
userbinator 2 hours ago [-]
The culture of insane overengineering around it is the problem, not the language itself.
pjmlp 2 hours ago [-]
In fact, it was welcomed in open arms even being originally interpreted, because writing portable C or C++ code in 1996 was still a mess, even across UNIX flavours.

On my university no one got Sun's marketing money in 1998, yet the distributed systems, compilers design, and graphics programming, all adopted Java as the language for new teaching materials, as it sorted out several problem with the assignments.

Yoric 18 minutes ago [-]
Yeah, migrating from C++ was such a breath of fresh air!

Both awt and then Swing were pretty bad for anything beyond toy programs, though.

2 hours ago [-]
echohack5 2 hours ago [-]
In 2012 managing the JVM was a nightmare. Java is fine now.
TZubiri 2 hours ago [-]
Only bad experience I remember from Java was the int/Integer primitive/object issue and boxing.

Also of course the misuse and overuse of classes when designing systems, but the complexity at design time is also the counterpart of the ease of use of well designed APIs. I remember using an IDE to write some code and it skipped the whole documentation and run/compile error phase, I could just cast mismatching types as needed.

Probably C# and Swift/Objective C would only be above Java as top languages, being actually funded by paying customers instead of used by companies that depend on volunteer developed open source software and end-users that equate paying for software with evilness.

voidfunc 2 hours ago [-]
Being forced to use anonymous classes to simulate lambdas prior to 8 was the biggest source of annoying boiler plate IMO and was genuinely a bad experience in sufficiently complex or large code bases.

Everything beyond 8 has been nice to have but 8 was the big one.

kelnos 1 hours ago [-]
Agree, for the most part, but I think records and pattern matching are essential. I started using Scala (2.x) in 2014 or so, and case classes and pattern matching completely blew my mind. if/else trees and switch statements felt so archaic, limited, and verbose after that. I used to joke that Java would eventually adopt enough of Scala to be a pleasant language to work in, and I don't think I was that far off.

(I'll ignore Kotlin... I don't get why people like it.)

tetha 2 hours ago [-]
> Only bad experience I remember from Java was the int/Integer primitive/object issue and boxing.

Heh, I once had to work in a code base that used an `Integer premiumDefenseLevel`. It contained the level of premium defense a player had purchased, or null if the player didn't have any levels of premium defense purchased in the recent times.

This was in fact annoying to remove, because a 0 after a 1 was treated differently than a null some time for advertisement reasons: Someone who had bought premium defense in the past is more likely to re-buy than someone who didn't, so they are pestered with ads. But it eventually turned into a neat little domain object.

nananana9 2 hours ago [-]
> the int/Integer primitive/object issue and boxing.

That's a deal-breaker. If you can't tie together a few values in a record/struct without being forced to box them/heap allocate them, the language will never be used anywhere where you even remotely care about performance.

This is not a difficult problem to solve - C# did it in a very elegant way with structs, and as a direct result, probably for half of all videogames written today, the gameplay portion is written in C#.

adgjlsfhk1 2 hours ago [-]
imo it's worse than that. of they'd just hid the boxing in the runtime, Java would be a kind of slow language that didn't feel awful. by exposing the unboxed primitives to the user, they created a horrible duality of incompatible types.
brabel 1 hours ago [-]
You Guys haven’t used Java since the 90’s right? Boxed types convert to primitive values automatically, you never need an explicit cast! What horrible duality are you talking about?
brabel 2 hours ago [-]
What are you criticizing exactly? You can have primitive integers in Java records or classes just fine. If you have many you can use an int[] like in C, no one forces you to use generic containers.
huhlig 2 hours ago [-]
Uhh. Most big data platforms are jdk based. Java handles scalable long running applications incredibly well for a fraction of the cognitive load.
troupo 1 hours ago [-]
It's not a terrible language, but it's not too good either.

For a very long time it completely stagnated and all the features we see added now should've been there 10 years ago, at least, and a bunch of other improvements on top. All because "our goal isn't to adopt the strategy of less successful products, but to forge our own" which now turned into busily adopting all the features that the "less successful products" have had for years: https://news.ycombinator.com/item?id=28985688

voidfunc 2 hours ago [-]
Meanwhile some languages like Python still suck 30 years later.
vincnetas 2 hours ago [-]
Most likely you have not seen horrible languages or your bar for being not horrible is quite high.
mrkeen 2 hours ago [-]
Or they've seen enough good languages to push Java down.
adgjlsfhk1 2 hours ago [-]
this one. Java is far from the worst out there. I've used MuMPS and know of the horrors of TCL, but Java is once of those languages where everything takes 5x more more code than it should, and the result always feels ugly.

part of my dislike is probably that I'm a math person, and the lack of operator overloading really makes any math not using the built-in types dreadful to read.

guidedlight 2 hours ago [-]
Even so. It has amazing backwards compatibility and package management.
adgjlsfhk1 2 hours ago [-]
I really hope you mean this as it has (amazing backwards compatibility) and (package management), because describing the package management in Java as anything more than "I guess it's better than C" feels overly generous
flowerthoughts 1 hours ago [-]
The unnamed class approach to global variables sounds nice. You can do hot-reload, but still have unencumbered syntax.

OTOH, since Java files are named after their public class, it would have made more sense to just say the `public class X { }` wrapper is optional and only needed for attributes and inheritance. I don't quite understand why they need an anonymous class.

> The Java compiler will compile that file to the launchable class file HelloWorld.class. In this case the compiler chooses HelloWorld for the class name as an implementation detail, but that name still cannot be used directly in Java source code.

https://openjdk.org/jeps/445

kazinator 2 hours ago [-]
If it is just syntactic sugar that has to create a class under the hood, it's just lipstick on a pig's turd.

If you can't have other top-level functions in Java, then it's a special case, which is ugly.

veltas 38 minutes ago [-]
I feel the same way about C/C++ having default return of 0 in main() only.
kazinator 5 minutes ago [-]
[delayed]
drewnoakes 1 hours ago [-]
C# has had top level statements since version 9.0 (Nov 2020), and it's still just a compiler trick that produces a static method behind the scenes. Top level functions work too, but in a similar way.

Decompiled example: https://lab.razor.fyi/#41rAyMUVUJSfXpSYq5dcLDSRsbQ4My9dIbiyu...

> lipstick on a pig's turd

There are several valuable compiler transformations that happen under the hood in languages like this. Closures as types, iterator/generator functions, async state machines. This is just another example.

boxed 52 minutes ago [-]
> If you can't have other top-level functions in Java, then it's a special case, which is ugly.

I assumed this meant that you could have free functions, but you're saying you can ONLY have `main` as a free function? Ok, then I agree this is also garbage.

tslater2006 21 minutes ago [-]
Foesn't this show other top level functions besides main? From the JEP

```Top-level members are interpreted as members of the unnamed class, so we can also write the program as:

String greeting() { return "Hello, World!"; }

void main() { System.out.println(greeting()); }```

Peteragain 2 hours ago [-]
What we seem to have forgotten is just how c like java was compared to other programming languages being advocated at the time. Objects made sense (remember Ada?) but c++ was a mess. Java was a breath of fresh air with lots of c legacy.
vkazanov 2 hours ago [-]
Oh, I do remember the narrative: OOP is amazing but Cpp is not pure OOP let's make the OOPiest language possible.

I also remember casts all over the place in Java because polymorphism wasn't OOP enough.

And then lambdas and functions were not OOP enough to be first class values and that's why we needed numerous "verb-classes" everywhere.

And of course printf() is not OOP enough...

cies 31 minutes ago [-]
Exactly. All wrong assumptions, and all needed to be tagged on to Java in later versions.

I dont find Java's first versions well designed. The JVM was quite well designed, but the language not.

And changing a popular language is hard. I think Java's dev do it very well (the process of changing it IS "well designed"). But still the language itself suffers a lot from the bad choices in the beginning.

I like Kotlin: an OO language with as much FP in there as makes sense for an OO language.

sylens 1 hours ago [-]
Learning Java in high school, I loved how the very first lesson (focused on Hello World) had you type this out, only for the teacher to say “This will make sense later on but for now just type it in”.
yohannesk 2 hours ago [-]
Why not abstract away the public static void main(String[] args) method with a top-level statement paradigm, similar to C#'s entry point simplification, to reduce boilerplate and enhance code conciseness?
BinaryRage 2 hours ago [-]
See Brian's article "Paving the on-ramp": https://openjdk.org/projects/amber/design-notes/on-ramp
mhh__ 2 hours ago [-]
Why should the entry point be a random special case? You're already admitting at this point that OOP is flawed so you might as well just have the balls to design a proper alternative (rather than a kludge)
fhd2 38 minutes ago [-]
This pattern isn't OOP, there is no objects here. And Java generally isn't a good example of an OO language to me. It's more like Class Oriented Programming. That is mighty flawed but was for some reason quite fashionable.

I wouldn't consider OO the way Ruby and other actually well designed languages do it flawed.

cies 28 minutes ago [-]
And Ruby is basically Smalltalk with a friendly syntax and lots of FP-goodness where it makes sense.

Or, Ruby is a cute (mostly subset of) Perl.

And after some Kotlin I must say: Kotlin is an acceptable "Ruby with static types".

textlapse 2 hours ago [-]
A special static class that cannot be instantiated is not OOP already.

C# does this well by letting you OOPfy your other code but doesn’t require you to use OOP for this monstrosity.

39 minutes ago [-]
jayd16 2 hours ago [-]
It always was and is a random special case.
another_twist 2 hours ago [-]
This is not a prank right ? Is it really gone ?
rhdunn 25 minutes ago [-]
It's not gone per se -- you can still write out the long form version if you want (this is required for backward compatibility).

What's now permitted is:

1. a simpler way of declaring a main method on a class -- you don't need the public or static, and the args is optional, so you can declare a `void main() { ... }` method on a constructable class;

2. declaring a main function (and other variables/functions) outside of a class -- here, the startup code will handle calling the main function, although I don't think the ability to call anonymous functions currently extends outside of the main function/file.

bonzini 2 hours ago [-]
It is, and it will be back soon just like Python's "if __name__ == '__main__'"...
garbagepatch 2 hours ago [-]
It makes sense to still have a main function. It doesn't make sense to have a class only to wrap that main function.
nromiun 2 hours ago [-]
What? When did that go away? What is the alternative?
rhdunn 15 minutes ago [-]
In a pyproject.toml file you can create/define scripts that reference an entry function. E.g.:

    # myapp/app.py
    def main():
        print('Hello!')
and in the pyproject.toml:

    [project.scripts]
    app = "myapp.app:main"
You can still use the __name__ check at the end of the file, e.g.:

    if __name__ == '__main__':
        main()
That way it works both as a standalone and when installed via pip/uv. -- Note: The scripts created by the installer are slightly more complicated versions of that __name__ check that handle the application argument (arg 0) and the exit code as the return value from main().
zuInnp 57 minutes ago [-]
I don't get the hate ... yes, it is a lot of boilerplate, but at the same time it is very explicit and doesn't hide complexity.
boxed 53 minutes ago [-]
It ADDS complexity that doesn't actually exist. There's no "class" in the C entrypoint of a program. That's just nonsense.
ahoka 16 minutes ago [-]
But there are no classes in C?
derefr 1 hours ago [-]
What’s with Java devs and not including `import` lines in example code? Even here, when intending to demonstrate how dumb Java’s boilerplate is. But I notice it everywhere.
TrianguloY 1 hours ago [-]
Because usually you have an ide that manages imports for you automatically. So unless you are using a library that has multiple imports, usually you know the import to include, and in almost all cases it is automatically included.

Btw: in the compact example! The IO class is implicitly imported, so that example truly works without any import at all!

andrewflnr 1 hours ago [-]
Among other things, I think a lot of Java IDEs automatically manage imports anyway.
derefr 1 hours ago [-]
I mean, the IDE can totally write out the import statements for you as you type and choose resolutions for identifiers; but if you paste in a random code snippet that references ambiguous identifiers from a third-party lib, no IDE can magically generate the import statements required to discriminate the correct resolutions. You have to go through and resolve the symbols yourself (or advance through them as error sites to get the class to compile.)

Or, to put that another way: import statements aren’t pure boilerplate that should be thrown away; they encode real information (ambiguous symbol resolutions); and so, by eliding them from code examples, you’re discarding that information and forcing the learner to re-derive it.

Which is especially bad when your code examples are referencing ambiguous undocumented static inner classes nested deep inside your library’s package namespace, where all the potential resolutions differ only by the particular package they exist in (since they’re all e.g. essentially batteries-included extensions of the base library implementing the same interface.) And where all this structure is as ugly as it is precisely because you didn’t expect the end-user of the library to need to understand it / interact with it. Yet your own [usually “advanced” or “feature demonstrating”] code examples force exactly that.

giveita 2 hours ago [-]
Looks like C# to me
Yoric 32 minutes ago [-]
Eh. I used to teach Java as a first programming language and this always went "Just ignore the incantations for the time being, you'll learn more about them as time goes."

This (and IO) was also one of the reasons for which my students tended to like OCaml much better than Java.

macspoofing 1 hours ago [-]
We're solving real problems now.
blobbers 1 hours ago [-]
It looks more like C++ or C now. Never really became a java programmer. Hopefully never will have to.
fhd2 56 minutes ago [-]
Back in 2005 or so, Java felt like "C++, but we know better" to me. I had no choice but to use it, but boy did they omit some stuff that was actually useful. The boilerplate back then (driven by both the limitations of the language and a surge in architecture astronauts) was absolutely insane. Don't even get me started on anything labelled "Java Enterprise" in the 2000s, bloat, slowness and bugs everywhere. IBM, Oracle and friends were running quite the circus. Creating working, performant software in that environment was a brutal challenge. I think Java, the language, is only partly to blame, but it was limited enough to spawn pretty complex code generators and frameworks.

Took the industy a decade or two to arrive at typed languages that were an actually good subset of C++ features. Java, in my opinion, wasn't one.

keithasaurus 2 hours ago [-]
could java please also learn that stand-alone functions are cleaner than static methods? even if it's just syntax sugar...
fhd2 36 minutes ago [-]
C++ calls them free functions, and I always found them rather elegant. A common pattern, at least a few years ago, was to use free functions for anything that'd be a method in Java, but doesn't actually require access to anything non-public.
furyofantares 2 hours ago [-]
We got there just after we got the ability to legitimately create useful small programs without understanding any of the thousands of lines of code.
winrid 2 hours ago [-]
Did it slow down compile times at all to support two different file structures?
1 hours ago [-]
Panzerschrek 2 hours ago [-]
So, Java now supports free functions (not associated with some class). Or not really yet?
happymellon 2 hours ago [-]
They are associated with a class, but the class is basically the file. There are limitations by doing it this way but it is out of preview and officially supported as of Java 25.

https://openjdk.org/jeps/512

ninjin 2 hours ago [-]
If so, are we observing a move towards Universal Suffrage in the Kingdom of the Nouns? [1]

[1]: https://steve-yegge.blogspot.com/2006/03/execution-in-kingdo...

BinaryRage 2 hours ago [-]
No, these are just default imports. Module import declarations are in for JDK 25 to make this kind of thing even easier: https://openjdk.org/jeps/511
naruhodo 2 hours ago [-]
Nope. It's just sugar. [1]

It's somewhat implicit in the JVM spec, but functions are always bound to classes as methods. [2] The only kinds of heap objects you can have a reference to are class instances and arrays. [3]

The lack of free functions is really only a minor inconvenience for language implementers. Clojure, for instance, just compiles new classes to hold functions as methods.

From a programmer's perspective, you can write lambdas, but again, it's just syntactic sugar over an inner class.

[1] https://www.happycoders.eu/java/main-method/ [2] https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-4.h... [3] https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-2.h...

vincnetas 2 hours ago [-]
I think all functions are associated with some class. But these classes sometimes are hidden from you and you don't need to know about them. Does that help you? What for would you use true free functions?
throwaway47461 2 hours ago [-]
> What for would you use true free functions?

The same things people use free functions for in any other programming language.

rerdavies 2 hours ago [-]
Cluttering up global namespaces? ;-P
TZubiri 2 hours ago [-]
Presumably these exist in a Main.java file and the java class is implied. Similarly the string params are also implied, and the non param main() function is just an alias or a wrapper for main(String).

It's just syntactic sugar.

raverbashing 1 hours ago [-]
Funny how shaming and competition worked wonders for Java, instead of that bureaucratic mess that was first versions
TZubiri 2 hours ago [-]
Ugly? Sure. But isn't this the identity of Java? Taken away for almost no gain, there's literally no real issue stemming from requiring a verbose incantation to write a main routine, this is something you learn like day 1 on learning java, and it's something you write once in a blue moon, like 0.001% of the code you are going to write.

It reminds me of the attempt at removing Richard Stallman from the FSF, yeah, you could do that and fix a problem, but then what you are left with isn't really the same thing as it was before, it's now actually the same soulless thing as the rest of the competing things.

Saving grace is that obviously, you can still recite the incantation, it's not like public static void main(String[] args) is gone, just that you can skip it.

yallpendantools 2 hours ago [-]
> this is something you learn like day 1 on learning java, and it's something you write once in a blue moon, like 0.001% of the code you are going to write.

I think this is the exact audience for this change: for newbies in day 1 of 10 years in their programming journey. Less boilerplate to just swallow, less time spent debugging an otherwise-fine lab exercise if not for the wrong instantiation of Scanner, more time actually focusing on the basics they should be focusing on.

Granted, I still think Java is a horrible first language to learn from or teach with but this is a step in the right direction. Might revisit this opinion in a few years, who knows.

Oh also, we use Java in production so we also have a bunch of ad-hoc "scripts" written in Java for mostly one-off interactions. Nonetheless, these scripts can get unwieldy fast. You'd think I'm exaggerating the benefit here but I, for one, welcome one less level of indentation in these scripts.

beginnings 2 hours ago [-]
but I need my public static void main arg arg arg
throwmeaway222 2 hours ago [-]
Might come back to Java
The_Fox 2 hours ago [-]
I distinctly recall early in my first university programming courses the instructor saying something to the effect of "Just wait until you learn 'public static void main'". I think we had only used BlueJ until that point in the course.
charcircuit 2 hours ago [-]
It hasn't been for over 20 years with Java 5.

public static void main(String... args)

DeathArrow 2 hours ago [-]
What I would like to see deprecated is over using objects and design patterns and SOLID and Uncle Bob principles, so we see less FizzBuzz Enterprise Edition and Java feels less as the Kingdom of Nouns.
DeathArrow 2 hours ago [-]
C# has top level statements since 4 years ago. Not only you don't need a class, but you don't even need a Main() method.
cynicalsecurity 2 hours ago [-]
Why did it suck exactly?
riffraff 2 hours ago [-]
The goal is go make java easier to learn for people new to programming.

When they start with the old style there is an overload of concepts where the teacher just have to say "ignore all this", which is not ideal. With new style they grasp fewer concepts at first.

I'm not truly convinced this is such a big deal, but I lived through my university switching from Pascal to Java in the first programming class, and I can confirm people did get much more confused during the first few classes (to be fair they got way less confused later not having to deal with pointers tho).

olalonde 2 hours ago [-]
Excessive boilerplate code.
hdjrudni 2 hours ago [-]
That's what I wanted to know too, but all we get is this one line:

> 1: When I was a Freshman in High School I asked a Junior what it meant. He had no clue.

OK... so it's confusing for juniors. A lot of stuff is. I probably didn't know what it all meant when I started either, but so what? You copy and paste it and move on. Eventually it makes sense. Not a big deal.

_moof 2 hours ago [-]
I don't understand how anyone ever didn't know what this meant. You have a class. It has a static method. The runtime starts your program by calling the method, passing it an array of command-line arguments. What's mysterious about this?
hmry 2 hours ago [-]
The fact that you have to explain what classes are, and what static methods are, a huge load of information, for a hello world program. And what's worse, it will leave students rightly confused about what the point of the class is, if it only has static members... Making it more likely they don't retain any of the information. Or alternatively, just say "type it exactly like this, don't think about what the magic words mean" which is a great way to ruin programming for people
maxlybbert 2 hours ago [-]
The first book I read on Java managed to explain "public static void main(String[] args)" by the end of the first chapter. It wasn't a long chapter, either.

I don't like Java, and the excessive boilerplate is a big part of that opinion. But it was never nearly as arcane as some people here are making it.

antonvs 2 hours ago [-]
When you first learn programming, you don't know what a class is, or a method, let alone a static method.

But if you teach people using Java, you have to teach them to write this:

    public class Main {
      public static void main(String[] args) {
        System.out.println("Hello world");
      }
    }
...instead of just:

    print "Hello world"
The latter is easy for a student to understand. With the former, you just have to tell them to use it without understanding it, and that they'll understand it later.
GaggiX 2 hours ago [-]
Why there is a class in the first place
_b0t 2 hours ago [-]
Not understanding why having a well-defined function declaration "sucked", but alright, I guess!

I mean even this part:

``` var name = IO.readln("What is your name? "); IO.println("Hello, " + name); ```

is _worse_. `IO.readln` doesn't tell you whether that's file I/O or stdin/out. The more explicit the better, if you ask me.