Live data from Hacker News

C# 9 top-level programs and target-typed expressions

developers.redhat.com

81–90 of 188 posts

Re: C# 9 top-level programs and target-typed expressions

#81
post #43

Earlier quoted context omitted.

You could create tuples with `Tuple.Create("a", 1)` since at least .NET 4, if not 3. Since C# 7 you can also create tuples using just `("a", 1)`. But tuples are not KeyValuePairs. So the new "new" syntax will be very helpful in a lot of cases.

I really don't understand why they haven't added implicit conversion operators between the modern ValueTuple and the legacy value-types like KeyValuePair, Tuple, and Pair, grumble. It's a non-breaking change!

Adding that is potentially a source breaking change. Admittedly an easy enough one to address, and they are more willing to make such changes in CoreFx, then they historically were, so it is not impossible that they could decide to do it.

For an example of this being a breaking change. Let's say that B is some other type implicitly convertable to A.

The following two method overloads exists:

    void Method(A a, ValueTuple vt);
    void Method(B b, Tuple t);
Right now `Method(SomeB, (4,5))` compiles fine, but if your proposed conversions were added, it would suddenly yield `CS0121: The call is ambiguous between the following methods or properties:...`.

Re: C# 9 top-level programs and target-typed expressions

#82
post #29

Earlier quoted context omitted.

There are many paths out of hell. Check out the windows compatibility pack for all things active directory, WCF & System.Drawing: https://docs.microsoft.com/en-us/dotnet/core/porting/windows... Winforms is probably a no-go on migration, but you should definitely check out Blazor if you want to develop any new business apps. We have constructed some incredibly complex business dashboards using this framework and cant…

I'm pretty sure WinForms is being migrated. I've built dotnet 5 WinForms apps, anyway. At least on Windows - I wouldn't bet on a Linux Gtk/Qt port any time soon. WPF is probably dead though.

WPF is quite alive. I had a pretty big audio processing project using WPF a while back, and when I migrated the codebase from .NET Framework to .NET Core 3.1 (and now .NET 5), there were surprisingly noticeable responsiveness improvements. I think they also have some more improvements planned for .NET 6 as well.

Self plug: A while back, I split off my own WPF MVVM framework from that larger project. It's designed for building simple touch-style interfaces, like you would see on a phone/tablet: https://tinyurl.com/upbeatui

Re: C# 9 top-level programs and target-typed expressions

#83
post #73

Earlier quoted context omitted.

They were created by the same person. https://en.m.wikipedia.org/wiki/Anders_Hejlsberg All the hate C# gets is because of balmer and gates, not for technical reasons

Are you sure? My personal reluctance to C# has been that it's not handy for the stuff I do that needs to run on Windows, Mac, and Linux, which is everything.

Relative to what? Assembly?

Re: C# 9 top-level programs and target-typed expressions

#84

Earlier quoted context omitted.

It is super easy with dotnet core. The new CLI is pretty simple, you use it as a package manager and compiler. Visual Studio also uses the CLI to run and debug dotnet core projects. https://docs.microsoft.com/en-us/dotnet/core/tools/

But I want it to produce a single EXE and that's it... like the C# compiler has always been capable of doing. Sorry I neglected to mention that part (kind of assumed it was a given). Also, the whole thing is still a stateful operation revolving a .csproj file, which (again) is XML I have to create (sure, it's just one command) and manage/deal with every time. Even to compile a tiny C# file from my editor now I need t…

You can still just invoke csc.exe, no project file required - I'm not sure what you are getting at? But it's probably going to be easier to just dotnet new console and get the project file for free. They tried migrating away from csproj but there is just too much ecosystem around it. The XML sounds bad, but in reality they added file globbing and other things to make it so you rarely even have to change it. That and to be honest it just works and is quite readable even though it's the "evil" XML.

Re: C# 9 top-level programs and target-typed expressions

#85

Earlier quoted context omitted.

But I want it to produce a single EXE and that's it... like the C# compiler has always been capable of doing. Sorry I neglected to mention that part (kind of assumed it was a given). Also, the whole thing is still a stateful operation revolving a .csproj file, which (again) is XML I have to create (sure, it's just one command) and manage/deal with every time. Even to compile a tiny C# file from my editor now I need t…

You can still just invoke csc.exe, no project file required - I'm not sure what you are getting at? But it's probably going to be easier to just dotnet new console and get the project file for free. They tried migrating away from csproj but there is just too much ecosystem around it. The XML sounds bad, but in reality they added file globbing and other things to make it so you rarely even have to change it. That and…

csc.exe doesn't compile to native?

Re: C# 9 top-level programs and target-typed expressions

#86

Earlier quoted context omitted.

C# is my goto for Windows, for sure. Is the native interop good in Linux as well? I've never even considered anything like that, would probably gravitate to C++ since that's what I'm familiar with but would seriously consider Go or Java in non-Windows situations.

How do you think they built the Linux-version of the .NET standard library? ;)

Lots of wine?

Re: C# 9 top-level programs and target-typed expressions

#87

Earlier quoted context omitted.

You can still just invoke csc.exe, no project file required - I'm not sure what you are getting at? But it's probably going to be easier to just dotnet new console and get the project file for free. They tried migrating away from csproj but there is just too much ecosystem around it. The XML sounds bad, but in reality they added file globbing and other things to make it so you rarely even have to change it. That and…

csc.exe doesn't compile to native?

No, it's always compiled to MSIL. You've always had to use a separate tool (such as NGen or dotnet publish) to do AOT compilation. But there are tradeoffs and AOT doesn't always mean faster performance.

But again, if you use the dotnet CLI you can just dotnet publish to create a AOT version of your exe. Just remember it still has the runtime and GC. You are just reducing the work of the JIT. Also AOT does not guarantee you will not JIT and still contains the MSIL. It's just a performance optimization where pre-compiled code will be used when possible.

Re: C# 9 top-level programs and target-typed expressions

#89

Earlier quoted context omitted.

csc.exe doesn't compile to native?

No, it's always compiled to MSIL. You've always had to use a separate tool (such as NGen or dotnet publish) to do AOT compilation. But there are tradeoffs and AOT doesn't always mean faster performance. But again, if you use the dotnet CLI you can just dotnet publish to create a AOT version of your exe. Just remember it still has the runtime and GC. You are just reducing the work of the JIT. Also AOT does not guarant…

Yes, I'm already aware of all this? I'm confused why you're explaining all this background—I'm well-aware of all this and my previous comments were already in response to these.

Re: C# 9 top-level programs and target-typed expressions

#90

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#: public class MyClass { private readonly MyDependency _myDependency = new(); public void MyMethodThatDoesWork() { MyVariable variable = new(); } } As oppos…

https://ericlippert.com/2009/01/26/why-no-var-on-fields/

Eric Lippert blogged about that like 12 years ago (when var just came out) interestingly there's a c#9 epilogue now at the bottom of the post.

Post reply on HN