I mean, top-level programs are nice, I guess? IMO it's more of a means of attracting non-.NET developers into the fold. I work in a .NET shop and we probably won't use this in our production code.<p>The benefit of target-typed expressions IMO is that it changes property syntax from:<p>public List<Foo> Foos = new List<Foo>();<p>to simply:<p>public List<Foo> Foos = new();<p>It may seem subtle, but if you write C# you see this pattern constantly.<p>Honestly, these are the features in C#9 I'm least excited about. I'm much more excited about record types, init-only setters, not to mention the improved pattern-matching and type inference (no more casting nulls inside of ternary operators!).<p>Immutability in C# has classically been pretty cumbersome. I work on a payroll platform where we've managed to work around a lot of that, but we're excited to introduce record types and init-only setters in particular to help with some of the maintenance pain-points surrounding the elimination of side-effects from things like pay calculations.
To me, the benefit of "Target-typed new expressions" is more with bringing consistency to class-scope member declarations and method-scope member declarations, so these two can look the same, and a programmer only has to read one way of declaring new members in C#:<p><pre><code> public class MyClass {
private readonly MyDependency _myDependency = new();
public void MyMethodThatDoesWork() {
MyVariable variable = new();
}
}
</code></pre>
As opposed to the (now old, IMO) var syntax/Java-like syntax mixture:<p><pre><code> public class MyClass {
private readonly MyDependency _myDependency = new MyDependency();
public void MyMethodThatDoesWork() {
var variable = new MyVariable();
}
}
</code></pre>
Edited for HN formatting.
Who would have believed a decade ago that there would be a RedHat developer blog entry on C# today?<p>If someone had told you that then you would have thought the world would have collapsed in the meantime.
I think that C# is underrated. Although TypeScript is my default language choice for most programming, C# / .NET is my choice for cases where:<p>- high performance is important
- or interop with native libraries is required (because C#'s DllImport attribute makes that super simple)<p>Another benefit is that C# is syntactically similar to TypeScript (they were both designed by Anders Hejlsberg after all), so switching between the two languages feels easy. Java and Go are both similar to C# in terms of performance, but interfacing with native code isn't as simple with those languages, and they're also not as similar to TypeScript as C# is (especially Go, which is quite different).
The article states that the benefit of target-typed new-expressions is that "the type declarations are nicely aligned" compared the use of "var".<p>I think a better justification is that fields and properties does not support type inference, so this can avoid some redundant type expressions for initializes, just like "var" can avoid redundant type expressions for local variables.<p>Of course it would be more elegant if fields/properties supported type inference like "var", but that is a can of worms since you can have recursive dependencies.
Can anyone comment on cross-platform GUI for .net? Last time I seriously investigated it, Gtk# seemed to be the primary option. Some quick googling found avalonia, but no clue if that's a reasonable GUI to use. I'm guessing MS isn't planning on porting WPF to linux (though I suppose linking with wine might work)...
> Top-level programs allow you to write the main method of your application without having to add a class with a static Main method<p>Riveting stuff happening in .Net land! Sarcasm aside, this seems like such a small, oddly-specific, once-off feature that its like...why bother? Any C# devs want to enlighten me here?
Can I just create a single .cs file somewhere, and execute it by typing its name? No Visual Studio solution/project shenanigans? That’s my dream. Top-level programs to eliminate boilerplate is a nice related step.
Wow, a full-screen cookie pop-up with a “X” dismiss button in the upper right corner that just causes the full-screen pop-up to re-display. Can it get more obnoxious?<p>This is the second one on the HN front page today [1]. HN tries to avoid paywalled articles, maybe we should also discourage articles that start out by deliberately hiding the content.<p>1: <a href="https://news.ycombinator.com/item?id=26639722" rel="nofollow">https://news.ycombinator.com/item?id=26639722</a>
I really love c# - one of my favrorite languages, but can any one explain the benefit of this new syntax?<p><pre><code> Person p1 = new();
Person p2 = new("Tom");
Person p3 = new() { FirstName = "Tom" };</code></pre>
I'm very cautious of anything from RedHat regarding .NET - some of the worst C# I've ever seen comes from some of the devs working at RedHat in the form of commits to public repositories.
I have been programming with c# since 2000 i think. But I do not like where the languages is going.<p>It is becoming way to loose in a sense and it seems that it wants more than it should.<p>If you want to do functional programming, pick a fp language.<p>If you want to do dynamic typed programming pick a dp language.<p>Sure you can mix some things in, but c# is becoming way to scattered imo. And it's not pretty i think.