Remix.run Logo
kazinator a day 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.

drewnoakes a day ago | parent | next [-]

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.

veltas a day ago | parent | prev | next [-]

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

kazinator a day ago | parent [-]

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.

1718627440 a day ago | parent [-]

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

veltas a day ago | parent [-]

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

boxed a day ago | parent | prev [-]

> 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 a day ago | parent [-]

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