16 ms·
Welcome to C# 9.0
- 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.
- benbristow 6y agoThat "Init-only properties" feature is huge. I spend so long at work when working on tests making stubs of objects with private setters etc (e.g. DTOs). That work is essentially gone now, awesome!
- 0xcoffee 6y agoIt also drove me mad with JSON deserialization. Hopefully this will work nicely with newtonsoft.
- jrimbault 6y agoI think they said it was only a compiler error, it's still a normal setter underneath, so newtonsoft would not see any difference.
- benbristow 6y agoNewtonsoft (and the new Microsoft .NET framework JSON (de)serializer) only uses the setters once too to set the properties after processing the JSON, I can't see it causing an issue.
- iscg 6y agoAre you me? That's exactly the same reason why this feature has me so excited. Will save me so much time when testing.
- Parazitull 6y agoThis seems similar to the joke where after Brexit, the Germans are angry that english is still the official EU language and they change the english language until it sounds a lot like german. In a few years, C# 20.0 will have only one release note: Changed the name from C# to F#
- corysama 6y agoC# is Microsoft Research's 20-year-long con to turn Java programmers into OCaml programmers so slowly that they don't notice.
- rad_gruchalski 6y agoWith Kotlin and Scala in existence, that ain’t going to happen. C# is as verbose as it was years ago. After years of Scala collections, eithers, options, why would anybody consider C#. Just look at plumbing with init, data records and with. That is what a case class with val properties in Scala gives. But congratulations to the team on shipping v9.
- couchcombinator 6y agoBecause Scala takes mind-boggingly long to compile. Because Scala has so many features that anything has at least 3 different ways to implement it. Because it’s very easy to write unreadable code in scala, not so much in C#. Because Scala uses JVM, while C# has access to .NET (yes this is an advantage for many developers).
- whycombagator 6y ago> Because Scala has so many features that anything has at least 3 different ways to implement it. Thankfully that problem doesn't exist with C# /s
- The_rationalist 6y agoAll your points except the last one do not apply to Kotlin
- dzonga 6y agotaking all the best features of F# and putting them on their golden child C#. c# is looking elegant.
- tsomctl 6y agoWell, we're getting closer to F#. Still waiting on discriminated unions and expression blocks. (Yes, I know, discriminated unions in F# are just implemented in the class hierarchy. But it's awfully nice syntactic sugar.) > Point p = new (3, 5); At first glance, not impressive, since you could just do: > var p = new Point(3,5); However, it would clean up code like: > graphics.DrawRectangle(RedBrush, new(3, 5, 2, 2))
- woodrowbarlow 6y ago> graphics.DrawRectangle(RedBrush, new(3, 5, 2, 2)) > graphics.DrawRectangle(RedBrush, new Point(3, 5, 2, 2)) what's the advantage of the first example? i prefer the second, because i don't have to look at the definition of DrawRectangle in order to know that the second argument is a 'Point' object.
- maxton 6y agoThe second argument is a Rectangle, which means you'd be repeating 'Rectangle' twice in one line with the second style.
- surye 6y agoI think this clarification proves his point, and I tend to agree that I prefer the more explicit, verbose style.
- Infinitesimus 6y agoThat's not obvious from the function name though. The function definition could easily be `DrawRectangle(SolidColor, CornerRadii, Point)` and you wouldn't know by seeing a bunch of `DrawRectangle(RedBrush, new(1,2,4,5), Point(4,5,2,2))` would you? It's still nice to have the option in cases where it improves readability (maybe with named args or sth)
- deleted 6y ago[deleted]
- yread 6y ago
- Koshkin 6y agoHow does the .NET ecosystem fare these days compared to Java's? Whatever the differences between the languages, on the surface of things it looks like one must be insane not to use Java: https://projects.apache.org/projects.html?language https://projects.apache.org/projects.html?language
- loic-sharma 6y agoApache is somewhat Java centric. I wouldn't use that as a measure of a language's ecosystem. For example, JavaScript has an enormous ecosystem but only 17 Apache projects.
- The_Colonel 6y agoApache is Java centric, but as a developer in both Java and .NET it's impossible to not notice that Java ecosystem has much more independently developed projects while .NET world is still largely defined what MS provides as libraries.
- Someone1234 6y agoYou'd be insane because a major Java project maintainer contains a lot of Java..? That's like pointing at Microsoft's github repo and saying you'd be insane to use anything but C# and TypeScript. Personally I think this is a better source: https://octoverse.github.com#top-languages https://octoverse.github.com#top-languages Or this: https://insights.stackoverflow.com/survey/2019#technology https://insights.stackoverflow.com/survey/2019#technology
- The_rationalist 6y agoThe number of repository is not the important metric that apache has. What matter is to have at least one industry grade™ open source library for anything™ Most of apache libs are each ~20000 commits This amount of human resources is unmatched in any other platform.
- shanemhansen 6y ago.NET ecosystem is large, but still windows-centric. If I was choosing between java and C# for a startup, I'd definitely consider C# because it does seem to be a better java (properties and LINQ are the first 2 things that come to mind). But realistically if you're not doing .NET on windows, you're still an early adopter who's going to run into weird issues that you won't have to deal with on java.
- polskibus 6y agowhich visual studio version will support c# 9?
- u7u7h 6y agoNow you can test C# 9 with Visual Studio Preview and .NET 5.0 preview https://visualstudio.microsoft.com/vs/preview/ https://visualstudio.microsoft.com/vs/preview/ https://dotnet.microsoft.com/download/dotnet/5.0 https://dotnet.microsoft.com/download/dotnet/5.0
- phillipcarter 6y agoNote: you can't use C# 9 with .NET 5 preview 4; you'll have to wait until .NET 5 preview 5 is released. You can use it with the latest VS preview, though.
- polskibus 6y agoyes but when it comes out in full, will VS 2019 still support c# 9 or will I have to buy new VS?
- tarasmatsyk 6y agoI still think C# is one of, if not the best of designed languages exist. Even it moves in much smaller steps than it was before I think it's for good. I left .NET land at 6.0 and .NET 4.x versions mostly because of Windows eco-system (small open source community, almost no alternatives to out of the MS things, bad linux support). Since that I've been working with Java, Swift,JS, Python, Golang and I still think that C# is one of the best-designed languages. Very few of them keep evolving through the decades, hopefully it can become the language of the year at some point, always liked to see how new features got implemented under the hood and what kind of features get into next release. Well done C# team It's amazing how the language advances over years
- The_rationalist 6y agoTo me C# is the second best designed language, the first being IMHO Kotlin. I'm very interested in what you think would make C# more well designed than the latter :}
- bulldoa 6y agoMay I ask why do you think kotlin is best designed?
- djanogo 6y agoI think kotlin is ugly hack, if you take away the superficial syntax (?) it will start showing ugly side. I think it only gotten popular because of Googles push due to Oracle Java lawsuit.
- monocasa 6y agoI don't think Kotlin is being pushed because of the Oracle lawsuit. Most of Oracle's complaints were at the VM and standard library level, which Kotlin doesn't help with.
- eggsnbacon1 6y ago
- daeken 6y agoDamn, this is fantastic. One big syntactical thing I should really put in a proposal for is null-conditional returns. Turning if(foo != null) return foo; Into return? foo; It fits perfectly with the existing null coalescing operators and such, while really cleaning up a lot of code.
- mgamache 6y agoI am surprised that hasn't been done already.
- u7u7h 6y agoBetter not.
- dullgiulio 6y agoPerl# basically.
- kungato 6y agoThis look so very prone to cause bugs. Why would you even "return if not null"? I don't think I've been in this situation before. What I do see is if x is null then return something else, but this never
- bradford 6y agoI'm confused. In the first code block, what value is returned if foo is equal to null? If it returns null, what's the difference between: >return foo; and >return? foo; ?
- topkai22 6y agoI think return is too important a keyword to make optional like that. However, I could totally get behind a shortening like if(?foo){return null}
- Koshkin 6y agoAn interesting idea; it could be extended to other constructs - assignments, method calls... Also, imagine having something like this: while (!return? foo) { foo = get_foo(); }
- thoraway1010 6y agoWhat is the winforms simple (ie, drag and drop form designer, click through for code) current windows development recommendation. I've seriously lost all track of how to just get up and going. I've tried UWP/WPF etc - they felt like a bit of nightmare for quick and go, but the tooling now seems to have dropped winforms? I couldn't get the form designer to actually show up even on a WinForms project?
- hnrodey 6y agoI'm no longer close to .NET desktop GUI development but even today, if I had to do something I'd start a new WinForms project.
- mgamache 6y agoFor simple utility apps, it's lighting fast and easy. Now with .net core high and DPI support it's even better.
- Traubenfuchs 6y agoIt seems to be alive and well: https://devblogs.microsoft.com/dotnet/windows-forms-designer-for-net-core-released/ https://devblogs.microsoft.com/dotnet/windows-forms-designer... Sadly only in Visual Studio and not Visual Studio Code. And yes, there is probably no one who used winforms that wouldn't be shocked by WPFs steep learning curve.
- thoraway1010 6y agoWow - GREAT news. This was EXACTLY my issue, no forms designer. I'm mostly developing server on linux so I'm not enough of designer to even begin to wrap my head around XAML / MVVM / WPF / UPF (?) new world order on windows. SO glad they are going to allow for some simpler approaches - and no, I don't want to build skinnable apps for business - I actually LIKED that all the apps looked / worked basically the same in the old world even though that's no longer cool. We now have some silverlight apps, some IE only apps, some WPF / UPF apps. But the old winforms apps still get lots of use and still work. I've found the "better" WPF / UPF stuff to kind of lag and stutter even sometimes - I've got no idea why. The winforms apps on new machines are snappy.
- seemslegit 6y agoPositional records are a terrible idea, one of the best things about C# is readability var (f, l) = person; is so much worse than var (f, l) = (person.FirstName, person.LastName); I don't want to have to refer to documentation or class implementation to understand what a destructuring expression does.
- jonesetc 6y agoI think that it's unfortunate they stuck with that example instead of the classic point class example for positional args. In general the positional destructuring is not great, but there are some cases where it is nice and readable. Because of that I'm glad it's not the default that all record classes get it. var (f, l) = person; is gross and hard to understand. var (x, y) = point; is simple and readable.
- andybak 6y agoYour example would seem a lot less bad without the one character variable names. var (first, last) = person; didn't seem too bad to me.
- Jtsummers 6y agoI disagree. Automatic destructuring like this can be fantastic. Sure, if you're just destructuring a variable there's not much gain. But this is much smoother: var (f, l) = SomeMethodReturningAPerson(); than: var person = SomeMethodReturningAPerson(); var (f, l) = (person.FirstName, person.LastName); or: foreach(var (f, l) in enumerationOfPersons) { ... } compared to: foreach(var person in enumerationOfPersons) { var (f, l) = (person.FirstName, person.LastName); ... } When you know what you want to compute, but have to throw in extra temporary variables it becomes tedious and error prone. Cut straight to the thing you want (the names themselves in this case), eliminate middlemen.
- moogly 6y agoWhat I really want is nominal destructuring, not positional. It's really fantastic in ES6/TypeScript.
- 6y ago
- topkai22 6y agoI'm VERY excited for Record types. Automatically having automatically deep equality in data types is going to really help maintainability- no more "developer adds a field to the type but not to the equals function" type errors.
- myu701 6y agoLook - I don't have anything deep to say here. I can only say that between 'records' and 'with-expressions' now in C#, I as a hobbyist F# developer feel like I'm being shaken down by the mafia. C# designers: "Hey, nice language features you have there. I'll just borrow them for a bit ok, it'll be fine..." Later, C# programmers: "why would I learn F#, C# does all the same stuff!" (even though it doesn't) Edit: I admit being both glad that C# is gradually migrating to the ML-style coding which will make F# more mainstream, and nervous that C# will get close enough to kill F# adoption yet too far away to actually get all the benefits of F#. Some examples of this include the Hindley-Milner type system, partial application, discriminated unions, and all of the compile-time goodness the F# compiler gives and the C# compiler ignores.
- kungato 6y agoWell F# obviosly never gained enough momentum and C# has to grow somewhere so why not in this direction. All "big" languages are gaining more and more functional and declarative features each version. I always remember this chat by Simon PJ, the "father" of Haskell about convergence of languages in features https://m.youtube.com/watch?v=iSmkqocn0oQ https://m.youtube.com/watch?v=iSmkqocn0oQ
- myu701 6y ago> Well F# obviosly never gained enough momentum As a member of the F# Evangelism Strike Force (to use an n-gate ism), I want to argue this point but there is not enough info to determine what 'enough momentum' means. I can produce, without leaving F#: libraries, cli apps, windows services, windows desktop apps, websites (asp.net core + giraffe), web apps, SPAs (SAFE stack), and more. If I target .NET Core, I can run my F# in windows land, linux land, and anywhere else .net core has been ported. What features does C# offer that F# doesn't, aside from being more familiar to lots of MS devs? Even I started my dev journey with C# on Windows Mobile 5 via .Net Compact Framework. Cons: The F# tooling is just worse than C# tooling. Compare the 20-year old language with support since Visual Studio 2003 .NET to the one that has for some reason focused on the VSCode + Ionide plugins rather than the tooling that VS users run into and even I can't really argue that C# has better tooling. Biggest weakness of F# is all the wonkiness when it comes to common tasks like making, running, building, publishing codebases. The use case of something common like 'make me a new blank app, I want it to use paket for dependencies and to spit out an alpine docker image with .net core sdk at the end' should be 1 command, then triggerable from the VS Debug/F5 button. It just isn't that yet. > C# has to grow somewhere why not this direction I'd rather C# lean more FP than lean more OOP, sure, but _does_ C# have to grow somewhere? Can't a language spec be declared good enough / maintenance mode at some point so the programmers can focus their learnings on fuller understanding of the spec itself, as well as improving the implementations and tooling around a language?
- archgoon 6y agoIt seems using toplevel programs could make it harder to find the entry point to a program. Is there an easy way, given a built assembly, to know which source file the entry point is?
- jeffdavis 6y agoWhat is an example of a really good codebase written in modern C#? There are quite a few appealing things about the language, but I'm having trouble shaking the feeling that it's kind of like Java. I know both languages have evolved a lot, but some codebases might get stuck in some old patterns.
- _-david-_ 6y agoMy understanding is that the dotnet runtime and powershell are both decent codebases. https://github.com/dotnet/runtime https://github.com/dotnet/runtime https://github.com/PowerShell/PowerShell https://github.com/PowerShell/PowerShell
- jeffdavis 6y agoLooking at a random file in Powershell, the first thing I see is: private string _typeName; /// <summary> /// Add new type name to the specified object for TypeNameSet. /// </summary> [Parameter(Mandatory = true, ParameterSetName = "TypeNameSet")] [Parameter(ParameterSetName = "MemberSet")] [Parameter(ParameterSetName = NotePropertySingleMemberSet)] [Parameter(ParameterSetName = NotePropertyMultiMemberSet)] [ValidateNotNullOrEmpty] public string TypeName { set { _typeName = value; } get { return _typeName; } } -- https://github.com/PowerShell/PowerShell/blob/15c2245af9748659643626db863540aed4d4f72e/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddMember.cs#L93 https://github.com/PowerShell/PowerShell/blob/15c2245af97486... Honestly it seems like just a lot of code and very little meaning. I can't help but think that there's a better way of expressing the solution. I could have picked the wrong file, but I was poking around in lots of directories before I found any significant C# code at all. It seems like there's a whole 'nother level of boilerplate in the directory structure.
- LandR 6y agoMost C# is boilerplate code!
- joshschreuder 6y ago
- bob1029 6y agoThis is like reading through a list of Christmas presents I didn't even know I wanted. Relational/Logical patterns are going to revolutionize our ability to make high-level business logic even more accessible to non-wizards. The switch expressions introduced in 8.0 were already very nice for building out our complex in-line mapping code. This takes things to a completely different dimension. I will say that I am a little confused on the role of Record vs Class vs Struct. Do we not already have the ability to declare immutable value types with structs? How does the Record improve on the struct which already exists in the language? > Structs override this to have “value-based equality”, comparing each field of the struct by calling Equals on them recursively. Records do the same. Seems like we might be splitting hairs here?
- OkGoDoIt 6y agoI’m also confused on the relationship between records and structs. I’m guessing in practice it has some of the properties of classes and some of the properties of structures, but I worry it’s just going to complicate things. It’s not like all the old structs in the BCL will just go away.
- mmcconnell1618 6y agoWouldn't a Struct be passed by value and Record (as a class) be passed by reference. Kind of strange to pair immutability with pass by reference.
- dgritsko 6y agoIsn't a big distinction of structs the fact that they are value types (and thus allocated on the stack) rather than reference types allocated on the heap?
- joshschreuder 6y agoI asked the .NET Core team this yesterday during one of the Build talks, appearently data records can be defined as either class or struct and take on the same heap/stack allocation semantics as a regular class or struct. My understanding is that structs are not always a good choice depending on the size of the data contained within because they are put on the stack, so having an immutable class record does not necessarily overlap with the use cases for structs. It seems like records are more of a syntactic sugar which gives you a number of pre-defined behaviours such as value comparison and immutability by default (vs. regular classes).
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]
- herogreen 6y agoI would like to know what is the future of Mono now that dotnet core is crossplatform and Microsoft bought Xamarin. Mono remains the best (only?) solution to call C# from C++ in a crossplatform way using embedding.
- oaiey 6y agoWell, Mono is now one of the two .NET runtimes shipped with .NET 5+. Like you mentioned, it is better for embedded and porting. That the reason they I integrate it. Mono as a project is a dead man walking. And honestly, that is good. Unity as the major other user is surely heading for .NET 5. I would suggest to learn to embed .NET Core 3.1 and later .NET 5. Surely possible (see Unity, interop with WinRT etc, ..).
- kqr 6y agoHow is that a good thing? Isn't it reminiscent of embrace, extend, extinguish?
- oaiey 6y agoMono was never usable for server workloads. Its niche was the same as it is today: being portable and embeddable. .NET 5 gains that by integrating Mono. The benefits for that use case is the better tooling and ecosystem of .NET 5. With Xamarin, .NET Core and Unity doing one agenda every. NET dev wins. Mono and the .NET Framework are dead. .NET 5 is MIT licensed and even gets attention for source focused builds (like needed by Linux distros). Redhat officially ships is own version. Summary: that is exactly not EEE.
- ThinkBeat 6y agoI have worked with C# since the early beginning I have used it daily since then. I do know the ins and outs of the different up until C# 8 (latest released) and now .Net core. because I work with it every day. This probably an unpopular opinion but I wish they would make fewer changes to the language. A codebase from C# 2 will look entirely different than something written in C# 9. If you get a developer who has great experience writing 2.0 and bring him into a project in 9 it will look to him or her like a completely different language. I pretty much wish they created a new .net language D#? (or just put all the effort into changing F# (which I also like). I also do not like the terseness. Yes I get to type a few less charcters but it makes the language much harder to read: Pretty much all examples here make some sense if you come from earlier versions or other classical languages including javascript https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/switch https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...
- oaiey 6y agoI would not want to miss the many things in between. My argument is more: I am extremely happy I am bound to a language which actively evolves, taking me along the ride.
- thelazydogsback 6y agoAs much as I love F#, C# now has enough of F#'s core features that I'll probably use F# less due to the better tooling for C# code. (Resharper, Ozcode, etc.) C# still needs DU's though... Meta-programming support is kinda better if F#, but isn't great in either language unfortunately - you could argue the as C# is based on Rosyln that it is actually better.
- kqr 6y agoI'm viewing it exactly the other way around: if my co-workers have to learn this stuff anyway, I can just as well just use F#, which implements these things in more convenient ways.
- pragmatic 6y agoThis is great and all but I can't help but feel c# is finished and they are adding more complexity for minimal convenience.
- jinushaun 6y agoEvery new version of C# seems to change what it means to write "colloquial C#". I love it. These are all good changes.
- mindfulplay 6y agoAs usual a beautiful, beautiful language. As expected, they start with something simple and build layers upon layers all connected via simple concepts. Add init to a property, make its class a data class, and boom you have immutable beautiful class. Kudos to these designers. (This is similar to AutoValue in Java / data class in Kotlin, but it feels a lot more elegant and connected and simple than what these other languages offer)