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