4 ms·
.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");
by 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.
- SideburnsOfDoom 6y agoSo you're going to go with a top-level entry point even with a substantial program? OK, I can see that happening. I guess the point is that your substantial program will also have plenty of classes and methods elsewhere, so the idea that "you can do a one-liner without having to first learn about declaring classes and methods and namespaces" isn't relevant to you. You save a few LOC 1 time over in your top-level entry point though. OK.
- emodendroket 6y agoYeah, true. I don’t find the “for beginners” thing too compelling but I do like the idea of removing boilerplate.
- SideburnsOfDoom 6y agoI think that MS is at this point fairly concerned with the "long game" for .NET, i.e. get the next generation onboard now, reap benefits for decades to come. Or equivalently they noticed that .NET wasn't "cool with the kids" and set out to fix that.
- csmpltn 6y ago> 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. I don't understand why we keep optimising for this audience in the first place. These are people that lack basic understanding, but also have no patience whatsoever, or any intentions to RTFM. Why are we bending the ecosystem for this audience?
- SideburnsOfDoom 6y ago> don't understand why we keep optimising for this audience in the first place. I wouldn't say "optimise for them". I would say "get them in the door", get them used to how things work in C#, and then drop the training wheels. I take the point, it seems a marginal case though. IDK.