Live data from Hacker News

Welcome to C# 9.0

devblogs.microsoft.com

121–130 of 196 posts

Re: Welcome to C# 9.0

#121

Earlier quoted context omitted.

My understanding is that the dotnet runtime and powershell are both decent codebases. https://github.com/dotnet/runtime https://github.com/PowerShell/PowerShell

Looking at a random file in Powershell, the first thing I see is: private string _typeName; /// /// Add new type name to the specified object for TypeNameSet. /// [Parameter(Mandatory = true, ParameterSetName = "TypeNameSet")] [Parameter(ParameterSetName = "MemberSet")] [Parameter(ParameterSetName = NotePropertySingleMemberSet)] [Parameter(ParameterSetName = NotePropertyMultiMemberSet)] [ValidateNotNullOrEmpty] publi…

Most C# is boilerplate code!

Re: Welcome to C# 9.0

#122
post #27

Damn, 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.

I'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;

?

Re: Welcome to C# 9.0

#123
post #54

Earlier quoted context omitted.

The point of C# being a better Java is nowadays mostly obscolete because of Kotlin being THE better Java. As for LINQ see https://github.com/mythz/kotlin-linq-examples/blob/master/RE...

Why don't people understand that LINQ isn't just a C#-ish way to write SQL-like statements? So many people are comparing their libraries to LINQ without understanding what it actually does. LINQ brought System.Linq.Expressions and IQueryable to .NET which allows so much more than just filtering and grouping data. You can write entire data providers with LINQ and parse arbitrary expression trees in any way you like. E…

And the Mongo Linq library is often. For $reasons I worked on an implementation that had to support Sql Server and Mongo. The models and the Linq expressions worked across both and were translated appropriately. We just passed around a bunch of

  Expression>

Re: Welcome to C# 9.0

#124
post #27

Damn, 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.

I 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}

Re: Welcome to C# 9.0

#125

> " 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?

I 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!'

Re: Welcome to C# 9.0

#126

> " 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?

In 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…

You can do

    using Console = System.Console;

Re: Welcome to C# 9.0

#127
post #25

which visual studio version will support c# 9?

Now you can test C# 9 with Visual Studio Preview and .NET 5.0 preview https://visualstudio.microsoft.com/vs/preview/ https://dotnet.microsoft.com/download/dotnet/5.0

Note: 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.

Re: Welcome to C# 9.0

#128

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

I 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…

You are aproaching this from the mindset of the code author, but consider a new contributor to a project reading for the first time, with positional destructuring

foreach(var (f, l) in enumerationOfPersons) { ... }

tells him absolutely nothing about what's going or even that there are names involved

foreach(var (firstName, lastName) in enumerationOfPersons) { ... }

is better but doesn't give him an object to inspect to see where they come from and what else is available.

Re: Welcome to C# 9.0

#129
post #120
post #61

Look - 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…

C# takes the nice features of F# and implements in a slightly worse way.

Well obviously '#' in C# and F# stands for two different things.

Re: Welcome to C# 9.0

#130
post #27

Damn, 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.

An interesting idea; it could be extended to other constructs - assignments, method calls... Also, imagine having something like this:

  while (!return? foo) {
    foo = get_foo();
  }
Post reply on HN