Live data from Hacker News

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

developers.redhat.com

21–30 of 188 posts

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

#21
post #6

Earlier quoted context omitted.

if you have built anything on web forms, then you really have no way forward other than rewriting all that. That alone will keep many an enterprise locked on .NET Framework for quite some time.

In our case not web forms but WCF

You may want to keep an eye on CoreWCF: https://github.com/CoreWCF/CoreWCF

Though as a heavy WCF user in the past, I'd suggest your best bet is simply to throw out all your binding configs, and build your own REST API or similar backend (gRPC support in .NET 5+ is something often also recommended if you want something more RPC-like and need/want a more binary-serializer like approach, though in 2021 I'd just use JSON and something REST-ish myself). The nice thing about the Interface-driven "contract" approach should be that implementing your own is just a matter of implementing all your contract interfaces and injecting the physical implementations yourself.

I realize that can be easier said than done as things accidentally got coupled to very specific styles of bindings over the years and not everyone followed best practices and used the Async contracts so you have to tear out a bunch of synchronous faking code and wire back in Task/ValueTask. But generally, overall, the process was implement the interfaces and remove the "magic" in the process and I often found you end up with something better anyway because it is simpler and prone to less "magic" failures.

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

#22
post #2

Unfortunately the new tricks can't be used when the codebase is still stuck on .net framework :(

We use C# 9 in our WebForms monolith and it works fine. Just add `latest` to your .csproj file. (This assumes you're using recent Visual Studio version and use a recent version of MSBuild as well)

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

#23

I have been programming with c# since 2000 i think. But I do not like where the languages is going. It is becoming way to loose in a sense and it seems that it wants more than it should. If you want to do functional programming, pick a fp language. If you want to do dynamic typed programming pick a dp language. Sure you can mix some things in, but c# is becoming way to scattered imo. And it's not pretty i think.

I think I'm going to get diabetes from all the syntax sugar...

On the more substantive changes, it feels a little like the language designers have been looting F#.

Combined with how fast Dotnet Core is moving and how many breaking changes there are there, it does feel like things are getting very fragmented.

Stasis isn't good either; just witness the decade or so of stagnation after Java 1.6 as the Sun -> Oracle transition happened. But you can go too far in the other direction.

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

#24
post #10

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…

I can't see var going anywhere, many times you aren't directly creating a new object, but getting a generated object from something ( like linq) which tends to have more complicated type signatures.

Agreed that `var` isn't going anywhere, but this feature's best use case is with complex generics/enumerables and things like anonymous tuple types. For example:

  // old:
  var x = new List>
  {
    new KeyValuePair("a", 1),
    new KeyValuePair("b", 2)
  };

  // new
  var x = new List>
  {
    new("a", 1),
    new("b", 2)
  };

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

#25
post #14

Earlier quoted context omitted.

Allegedly there's an upgrade path from .NET 4.8 to .NET 5.

The upgrade path is massive rewrites, something most business are wary of. For good reasons. MS really made a grave mistake by coupling the evolution of the C# language to the .NET version. This means all projects on the .NET framework is now also stuck with an obsolete language version for no good reason. It is becoming a a lot less fun to be a C# developer because you more often will have to work with obsolete tool…

At work we've been slowly pulling code out of our WebForms monolith. That's still on .NET Framework, and will be forever until we're done killing it, but we can use recent VS and MSBuild with it and we use C# 9 as well. Business code generally works copy and paste in .NET Core, so there's a really good path to migrate to newer stuff, especially with .Net Standard 2.0 being a thing.

gRPC is really fast and we have the WebForms monolith call into .NET Core services now so we can improve the back-end without dealing with so much ASPX crap.

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

#26

Earlier quoted context omitted.

In our case not web forms but WCF

You may want to keep an eye on CoreWCF: https://github.com/CoreWCF/CoreWCF Though as a heavy WCF user in the past, I'd suggest your best bet is simply to throw out all your binding configs, and build your own REST API or similar backend (gRPC support in .NET 5+ is something often also recommended if you want something more RPC-like and need/want a more binary-serializer like approach, though in 2021 I'd just use JSON…

Could you expand a little on that? How exactly does an REST API backed desktop/forms application look like in 2021, and how is the decoupling accomplished?

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

#27

I think that C# is underrated. Although TypeScript is my default language choice for most programming, C# / .NET is my choice for cases where: - high performance is important - or interop with native libraries is required (because C#'s DllImport attribute makes that super simple) Another benefit is that C# is syntactically similar to TypeScript (they were both designed by Anders Hejlsberg after all), so switching bet…

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.

Interop on Linux works well.

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

#28

I have been programming with c# since 2000 i think. But I do not like where the languages is going. It is becoming way to loose in a sense and it seems that it wants more than it should. If you want to do functional programming, pick a fp language. If you want to do dynamic typed programming pick a dp language. Sure you can mix some things in, but c# is becoming way to scattered imo. And it's not pretty i think.

People have been saying this all the way back to when Linq came out, and who could imagine C# without Linq today?

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

#29
post #2

Unfortunately the new tricks can't be used when the codebase is still stuck on .net framework :(

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 imagine how some of this would even be possible if we had to move back to a front-end client framework and invent a bunch of JSON APIs.

Also, the new Blazor Desktop stuff is extremely exciting:

https://medium.com/young-coder/blazor-desktop-the-electron-f...

> The first difference is that the WebWindow container doesn’t use WebAssembly at all. Yes, you can run more or less the same Blazor application in WebWindow as you would in a web page. But when you use a web page, it’s executed by a lightweight .NET runtime that’s powered by WebAssembly. When you use it in WebWindow, it will use the cross-platform .NET runtime directly.

There is a lot of really amazing stuff coming down the roadmap, so I can easily advocate for enduring some degree of pain to get on this wagon.

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

#30

I have been programming with c# since 2000 i think. But I do not like where the languages is going. It is becoming way to loose in a sense and it seems that it wants more than it should. If you want to do functional programming, pick a fp language. If you want to do dynamic typed programming pick a dp language. Sure you can mix some things in, but c# is becoming way to scattered imo. And it's not pretty i think.

I think I'm going to get diabetes from all the syntax sugar... On the more substantive changes, it feels a little like the language designers have been looting F#. Combined with how fast Dotnet Core is moving and how many breaking changes there are there, it does feel like things are getting very fragmented. Stasis isn't good either; just witness the decade or so of stagnation after Java 1.6 as the Sun -> Oracle tran…

I don’t think they’re just randomly throwing stuff at the wall. These are all things they’ve been talking about for years.
Post reply on HN