4 ms·
> "Top-level programs" I'm not usually one for causal dismissals but that made me cringe. What on earth is the use case for getting rid of that tiny bit of bo
by ThrowawayR2 6y ago
> "Top-level programs"
I'm not usually one for causal dismissals but that made me cringe. What on earth is the use case for getting rid of that tiny bit of boilerplate, relative to the complexity it adds to the language definition, that makes it worthwhile?
- mwindow 6y agoI agree. The only advantage I can think of is smaller hello world programs. And that seems to be important from a marketing perspective: people new to the language won't perceive it as a verbose language.
- benbristow 6y agoDoes seem a bit of a pointless feature, especially as that very minimal boilerplate is auto-generated by any decent IDE anyway. And I used to primarily work in scripting languages like Ruby where you'd get this 'feature' out of the box (although usually ended up writing a 'Program' class and a constructor/main method anyway for the scoping)
- SirIntruder 6y agoThere is already a scripting dialect of c#, that seems mostly used in some web apps and for learning purposes. So they want to "streamline" this aspect, because currently this dialect requires a lot of custom handling. https://github.com/dotnet/csharplang/issues/2765 https://github.com/dotnet/csharplang/issues/2765
- giulianob 6y agoI'm actually a strong proponent of .NET core nowadays but I do agree some of the features being added don't seem to justify additional complexity OR just seem to overlap something you can already do in the language. I would prefer if they were a bit more cautious adding some of the features that are purely sugar.
- redstripe 6y agoMy guess it's to counter those popular code-golf language comparisons that make c# look verbose for short apps.
- thoraway1010 6y agoI like it. Can you open a text editor and get going with C#? Now you easily can. iPython and python notebooks gained lots of traction from just this type of simplicity. If you were to write a "script" using the language, doing some things just top level is simple. Very pragmatic. I ALSO like that it's an error to call to any top level functions outside of this, so it keeps this from exploding complexity everywhere.
- jrimbault 6y agoIn C# I'd like to able to : - declare a namespace for the file (no indentation) - declare that the file is a class and can only contain one (top level) class (still no indentation) - `using` statements that don't import every symbol into my namespace : using System.Console; ... Console.WriteLine(); instead of : using Sytem; ... Console.WriteLine(); // where does "Console" come from ? god/IDE only knows But yes, no to top-level programs. But alreay with these few changes, I've saved 10% of the 80 columns width. I've made it easy to read a file without an IDE. You can start to write actual code at indentation level 0. I've made it easy to have one class per file and hard to have two class per file, in the spirit of making good pratice easy and bad practice hard.
- daeken 6y agoTotally agreed on all these, though I've personally gotten around the last one by making use of `using static System.Console;` -- then you can just do `WriteLine(...);` It doesn't solve the fundamental issue, but it definitely makes things clearer for me.
- Mindless2112 6y agoYou can do using Console = System.Console;
- jrimbault 6y agoThe point is : the C# namespaces, default behaviors and general usage, are only half of a good idea. Effectively importing every symbol in a namespace into the local namespace by default is so obviously bad. Yes you can do `using Whatever = System.Console;`, fantastic, that's not the common idiom and it is harder to do (longer to write) than the usual idiom.
- kqr 6y agoIsn't this basically stuff F# nearly defaults too?
- Stevvo 6y agoI don't think there is much of a use case, it's more of a marketing thing: 'Functional programming is trendy! Now you don't need that pesky class in your program!'
- bbatha 6y agoThere’s basically no downside to adding the feature. But it really helps for playpens and notebooks and teaching. Playpens and notebooks want to focus on the example code in question and it’s good to hide the boilerplate. Teaching is vastly improved because the `main` boilerplate in hello world contains about four lessons worth of material (functions, classes, arrays, and namespaces) that needs to be handwaved to a class of beginners and if they screw up the magic incantations they get scarey error messages.
- oaiey 6y agoThere is some benefits for the Lambda scenarios. You pick a library and then have a 3 line integration code which can be hacked on a management portal. Personally, also not in favor of this, but heck, there is worse.