4 ms·
top level is mostly going to be nice when teaching new programmers. You can just get on with hello world and now have to type all this boiler plate and explain
by gameswithgo 6y ago
top level is mostly going to be nice when teaching new programmers. You can just get on with hello world and now have to type all this boiler plate and explain why you have to. But yeah, for "real" programs it is probably irrelevant. But who knows, maybe we will find a use for it.
I am mostly excited about the sort-of option type getting rid of nulls option.
- FridgeSeal 6y ago> top level is mostly going to be nice when teaching new programmers. You can just get on with hello world Yeah it seems like kind of a weird thing? “Here’s marginally less boilerplate once, if someone is going to learn to use the language, they may as well learn how it actually works instead of hiding stuff that they’ll soon see anyways...
- johnfn 6y agoYou should see how many new engineers are confused in CS101 when confronted with all of Java's boilerplate just to write a simple "hello world" program. It's a real issue.
- csmpltn 6y agoSo people with no programming experience are confused with Java. That doesn't sound like an issue at all. I don't think the solution should be to bend Java backwards so that it's easy for people with no progrmming experience to work with.
- BoorishBears 6y agoThis isn't a REPL but the benefits are almost identical Good for beginners, good for removing the overhead of "trying just one quick thing real quick"
- twodave 6y agoIf I want a REPL there's always the interactive window in VS.
- goto11 6y agoIt will benefit code examples and such. Say you want to post a code snippet on Stackoverflow - it is much simpler to provide minimal working code. It have always been a clear benefit of say Python that you can provide a two-line code snippet which can actually run. It is also step in the continuing process of removing boilerplate. C# started out like Java, but have over time removed boilerplate where possible. "public static void Main()" is also just boilerplate. I agree it won't matter for larger real-world program.
- SideburnsOfDoom 6y ago.NET was designed from the get-go for creating large programs. There is of course some overhead/boilerplate to this. So you could not do a Write("Hello world"); without wrapping it in a method. In a class. In a namespace. In an assembly. After all, why optimise the language for "Hello world" ? How important is that case? language designers rightly decided that supporting large programs was more important. In the code that your team has been working on for years, you'll be glad of all of those "overhead" things, that help you manage complexity and decompose the program. But yeah, show it to a c# newbie who is used to e.g. Python where "Hello world" is literally a one-liner and they might think "what a crapsack language, there's like 6 lines of overhead per 1 line of code, argh this is as bad as Java" - I've seen pretty much this reaction. Is it justified? From my POV, not at all. But I have seen that happen. Top-level statements (i.e. compiler-generated boilerplate instead of Visual Studio-generated boilerplate) does seem like an "on-ramp" feature that would be discarded as the program grows past a few lines though.
- emodendroket 6y agoWhy though? I can’t see any advantage to wrapping the startup code in a Main method from a maintainability standpoint.
- SideburnsOfDoom 6y agoConsistency, mostly. It's all methods on classes everywhere else, why make it different here? Even with "top level statements" the startup code is wrapped in a "main" method, it's just compiler-generated in this case. The CLR insists that code statements are always in method on classes, I believe. In cases where it appears otherwise (e.g. a lambda) the compiler is generating a wrapper class.
- emodendroket 6y agoBecause it’s just noise that doesn’t mean anything to me, so why keep it? Same as type inference, expression-bodied members, and other LOC savers.
- deleted 6y ago[deleted]
- dragonwriter 6y ago> But who knows, maybe we will find a use for it Outside of a project that deliberately has multiple entry points so that you can compile different executables from the same code base, or code where Main is, directly or indirectly, recursive, there's no additional utility from an explicit Main(), so i don't see why implicit wouldn't win for the normal case.