Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



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.


> 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.


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()); }```


I feel the same way about C/C++ having default return of 0 in main() only.


I really hated that change when I came out. I'm still not a big fan, but I made my peace with it understand that it benefits the poor users who have to deal with programs whose termination statuses are pseudo-random. Especially users doing scripting.

I write "return 0" at the end of main in all my programs if that end is reachable.


I write "return EXIT_SUCCESS;" maybe that constant might change... :-)


0 is guaranteed to mean 'success', although not guaranteed that it's equal to EXIT_SUCCESS, so you can always use 0.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: