20 ms·
.NET 5.0 – New APIs
- bob1029 6y agoOut of everything in the new 5.0 release, I am looking forward most to the non-generic TaskCompletionSource. This is a primitive that has been bothering me for some time WRT tasks that return nothing. I've been resorting to using bool as the generic type argument and discarding the value in these cases. Also, C# 9.0 is really cool. Will be abusing the new pattern matching stuff once we get a chance to upgrade. Looking like 3.1=>5.0 is going to be a non-event for us based on the current migration guides.
- eropple 6y agoI'm most excited for records and `with`. This is a feature in C# I've been wanting for years and will really help make the use of immutable data throughout a system easier with a ton, and I mean a ton, less boilerplate.
- SparksAndQuarks 6y agoShame 'with' will not apply to structs - all the ingredients are already there. Through it might be in the plan for some future release.
- eropple 6y agoAs I understand it, making structs implement the record stuff would potentially be...weird. But you're right, it'd be nice.
- capableweb 6y agoSpeaking about the new records, it bothers me that the keyword in the class declaration is "data" but they call it "record". Why not just name it record? Or "value-data" or something more descriptive? Considering it's one of the biggest languages today, I'm assuming they have ton of people working on it, so I'm clearly missing something here. And why still call it a "class" in the code? Could just have been have keyword instead... So many questions
- oaiey 6y agoIs it data? It bothers me as well, but was not the latest blog post with the terminology record?
- Metasyntactic 6y ago> it bothers me that the keyword in the class declaration is "data" The keyword is the declaration is `record`. So you would write your record: record Person(string FirstName, string LastName); Source: I am one of the language designers on C# :)
- capableweb 6y agoHuh, reading from https://devblogs.microsoft.com/dotnet/welcome-to-c-9-0/ https://devblogs.microsoft.com/dotnet/welcome-to-c-9-0/ which was the first hit on Google shows the following example: public data class Person(string FirstName, string LastName); It seems https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9 https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csh... is saying what you wrote above though. Seems my previous comment was based on outdated/wrong information, I'm sorry and thanks for clarifying :) Edit: Seems the post I wrote was published 20th May (probably written before) and that was the same date someone said the same thing as my comment here in the discussion about the "records" feature https://github.com/dotnet/csharplang/issues/39#issuecomment-631572976 https://github.com/dotnet/csharplang/issues/39#issuecomment-...
- runfaster2000 6y agoHere is a more recent update on records with the new syntax. https://devblogs.microsoft.com/dotnet/announcing-net-5-0-rc-1/#c-9-records https://devblogs.microsoft.com/dotnet/announcing-net-5-0-rc-...
- eropple 6y agoHa, I don't know if you worked on this but I had hopes when I saw you'd gone back that maybe we'd finally see records. I'd been seeing your name on record proposals forever.
- melolife 6y agoRecords are good, although in typical Microsoft style they've elected to call the new constructor syntax "positional" instead of "primary", and then subsequently failed to generalize the feature to normal classes. With is just building on the anti-pattern where .NET programmers are too lazy to implement constructors.
- manigandham 6y ago> "With is just building on the anti-pattern where .NET programmers are too lazy to implement constructors." What? And aren't records just a lazy way to make classes then?
- melolife 6y agoThe new with-expressions are a concession to the existence of initializers, which are themselves literally "stuff that should have been in the constructor" and are incompatible with immutability (hence the new init property hack). The correct path would have been to require primary constructors for records as the only point of entry for data, declare initializers incompatible with primary constructors, and then just synthesize a method for creating copies - but hey, then you might as well just use Scala.
- aliswe 6y agoYou seem to not appreciate the prqcticality of immutability in a large system.
- melolife 6y agoQuite the opposite. My language of choice is Scala, which probably explains my frustration at Microsoft's consistent inability to do the right thing.
- GordonS 6y ago> I am looking forward most to the non-generic TaskCompletionSource That has always seemed like a strange omission, but I can't say it's really caused me distress :) Personally, I'm looking forward to the `half` type, the extra GC diagnostic info, improved app trimming, improved ASN and certificate handling, and of course the improved performance and increased reach of Span. But I think most of all, I'm looking forward to a long term plan and no more .NET Standard/Core mismatch.
- lostmsu 6y agoThe half type is going to be obsolete instantly. There are quite a few other new floating types becoming popular recently: bfloat16, TF32, etc I wish they made C# support a notion of generic alrgebras.
- csharptwdec19 6y ago> I've been resorting to using bool as the generic type argument and discarding the value in these cases. After seeing other libraries do so, I've fallen into the habit of using a singleton 'Unit' or 'Empty' Type. (This technically also falls in line with the .NET conventions of DbNull.Value and Missing.Value) Actually, typing that out, I wonder if we all should have been using Missing.Value all along? :)
- CodesInChaos 6y agoPity that `void` is so special in .net, instead of being a proper unit type (would have avoided the Func/Action duplication as well)
- recursive 6y agoDBNull is my least favorite part of any version of any .net thing I've ever seen. I hate it with a fiery passion. It forces otherwise sensibly typed variables to be `object`, among a host of other sins.
- 737maxtw 6y agoidk. Null in an object versus null from the database could mean something different so DBNull makes sense. Also, I don't see how you could say DBNull is responsible for forcing object on us. They could have just as easily made it a struct and i dont see what it would solve.
- recursive 6y ago> Null in an object versus null from the database could mean something different so DBNull makes sense. Fortunately, it's super easy to tell the difference. `DatabaseQuery()` vs `SomeOtherFunction()`. See? > Also, I don't see how you could say DBNull is responsible for forcing object on us. They could have just as easily made it a struct and i dont see what it would solve. Doesn't matter. Even if it was a struct, the only way to store both kinds of value in one variable is to declare it an `object`, even if it was a struct. `null` is a perfectly legal value for a `string` variable, but as soon as the possibility for some other null object (or struct) is raised, the target variable must be `object`. C# doesn't do unions (as a first class language feature anyway).
- ocdtrekkie 6y agoI was kinda looking at migrating my project over to .NET Core/.NET 5 lately... turns out that despite bringing over Windows Forms and WPF support, Microsoft refuses to port System.Speech for text-to-speech and speech recognition. Turns out the reason why is that since the Speech team moved under Azure, the Speech team considers System.Speech "replaced" by Azure's cloud-based speech services. Kinda takes any idea I had of moving to Microsoft's modern platform off the table for me, because local-only functionality is a must-have in my book. And there's no reason my Windows machine shouldn't be able to do the same local-based speech capability PCs have had for the past couple decades without the cloud.
- gameswithgo 6y agono third party libraries that fit the bill?
- ocdtrekkie 6y agoI investigated a little bit, but most of the speech libraries on NuGet are either wrappers for Google/Microsoft/Amazon/IBM cloud services, or are dependent on System.Speech anyways. It's plausible if I really wanted to, I could run a separate service/application from some non-.NET-based alternative, but the integration is likely to be a lot messier. Right now, I'm not sure .NET 5 offers a compelling reason to drop .NET Framework, which Microsoft will presumably continue to support for at least the next decade. Microsoft still lacks a cross-platform desktop UI framework, they have no project template in Visual Studio that would let you write a service that can run as a service on both Windows and Linux, and .NET 5 is missing lots of Windows integration functionality like System.Speech as well. I'd really like to make my project both run as a service, and run cross-platform, but there doesn't appear to be a good path to do either one with .NET 5 yet, and it'd likely take substantial rewriting just to get my project to .NET 5 on Windows.
- ripley12 6y ago> they have no project template in Visual Studio that would let you write a service that can run as a service on both Windows and Linux I have lots of complaints about the state of the .NET ecosystem, but thankfully this one is pretty easy IMO. Basically just use the `dotnet new worker` .NET Core template; it scaffolds a project using the ASP.NET Core generic host, which can easily (a NuGet package and 1 line of code) be adapted to run as either a Windows Service or a systemd service on Linux. https://www.hanselman.com/blog/dotnetNewWorkerWindowsServicesOrLinuxSystemdServicesInNETCore.aspx https://www.hanselman.com/blog/dotnetNewWorkerWindowsService... https://www.reillywood.com/blog/dotnet-linux https://www.reillywood.com/blog/dotnet-linux
- SparksAndQuarks 6y agoI'm excited about new native interop api (function pointers, UnmanagedCallersOnlyAttribute, etc.). It removes "managed code tax" for calling into dynamically loaded OpenGL/Vulkan methods from c#. I'm playing around with GLFW via PInvoke, which meant marshalling openGL function pointers into managed delegates. In net5.0 preview, I can simply cast IntPtr into a function pointer, and boy, a call to your average openGL method is literally an order of magnitude faster. Similar optimizations might have been technically possible before, but it required some icky bytecode tinkering.
- mads_ravn 6y agoSounds really interesting. Do you have samples, benchmarks or other resources you can share?
- bob1029 6y agoThis sounds very interesting. I didn't realize there was that much of a difference using the new APIs. I have been playing around with interop against LibJpegTurbo Encode() and I am now curious if I've been leaving a ton of performance on the table.
- Const-me 6y ago> It removes "managed code tax" for calling into dynamically loaded OpenGL/Vulkan methods Interesting, never heard of that. Do you have a source? I haven’t noticed much overhead when I measured, take a look: https://github.com/Const-me/ComLightInterop#how-it-works https://github.com/Const-me/ComLightInterop#how-it-works That library compiles and runs with .NET Core 2.1. Update: also there https://docs.microsoft.com/en-us/cpp/dotnet/calling-native-functions-from-managed-code?view=vs-2019#performance-considerations https://docs.microsoft.com/en-us/cpp/dotnet/calling-native-f... they wrote “PInvoke has an overhead of between 10 and 30 x86 instructions per call” It roughly corresponds to my observation, and I find it fast enough for all practical applications, including GLES rendering on ARM Linux: https://github.com/Const-me/Vrmac/ https://github.com/Const-me/Vrmac/
- systemvoltage 6y agoCan someone please explain what .NET framework is? Everytime I come across it, it seems like a mysterious microsoft thing and Wikipedia's explanation is even more confusing: > .NET Framework (pronounced as "dot net") is a software framework developed by Microsoft that runs primarily on Microsoft Windows. It includes a large class library called Framework Class Library (FCL) and provides language interoperability (each language can use code written in other languages) across several programming languages. What is .NET framework really? Elsewhere, it is described as "A framework to build applications in Windows", but I thought that's what the Windows API helps with. Any help with clarification would be great, thank you.
- josteink 6y ago> What is .NET framework really? At its core: It’s what Microsoft made to compete with Java back in 2002. It’s a development platform, with associated tooling, compilers and a runtime. It has a common standard-library independent of language used by the developer (which aids cross-language interop), but realistically speaking most people just use C#. You can use it to create network services, console applications, web assembly programs or desktop GUI applications. It’s quite versatile. And .NET 5 will seemingly be the first version to officially supersede the previously Windows-only “.Net Framework” with a modern, open-source, cross-platform version instead. As a Linux desktop-user, I’m loving it.
- scruple 6y agoAre you building and/or using any .NET desktop GUI applications _on_ linux? I'd love to poke around some open-source projects to see how these are being made today.
- ZeroClickOk 6y agocheck https://github.com/AvaloniaUI/Avalonia https://github.com/AvaloniaUI/Avalonia
- pknopf 6y agoI've built this: https://GitHub.com/qmlnet/qmlnet https://GitHub.com/qmlnet/qmlnet I used it in medical devices within some of the larger medical device companies.
- ablekh 6y agoHas anyone here used (or are familiar with relevant cases of using) .NET for developing startup products, including MVPs? With some exceptions, I'm seeing .NET as predominantly an enterprise-focused technology. Strategizing about development of my MVP (B2B enterprise platform), as a CTO, I'm torn between a) Python and its great ecosystem (I plan to use FastAPI instead of more traditional Flask and Django), b) C# and .NET ecosystem and - to a lesser degree, for the reasons explained below - c) Julia and its emerging ecosystem. As much as I'm excited about Julia, I think that both the language and the ecosystem have not yet reached enough maturity and critical mass of developers as well as comprehensive and stable general-purpose libraries and tools to be a safe choice for a startup, which is already a highly risky venture. I have to reduce risks, not add ones. Between Python and .NET ecosystems, I'm more familiar with the former and, under equal conditions, would choose it over .NET. Additional argument in favor of this decision is that most of advanced ML/AI development is focused on Python high-level interfaces (and ML/AI is certainly a significant part of my future platform's value proposition). However, based on my research and recent .NET experience, I recognize its advantages versus the Python stack in some areas, including native type system support (though pydantic might be good enough for the Python stack; plus, it is used by FastAPI), rich set of native APIs, much better performance, much better support for domain-driven design (DDD), WebAssembly support, and, finally, much better support for developing multi-tenant applications. The last item is especially important in my case, since multi-tenancy and other relevant features (e.g., auditability) are strict requirements and Python ecosystem pales in comparison with .NET in this regard (the only decent project that I ran across is django-tenants, but a) it would force me to use Django and b) it only supports PostgreSQL schema-based multi-tenancy approach). Would love to hear your opinions and thoughts on the above. Thank you in advance!
- atraac 6y agoI worked for two consultancies that basically created apps for multiple startups and we used .NET Core in almost all projects. I don't really have comparison because besides simple, personal Django projects I never had much experience with Python but I find .NET Core actually enjoyable(I come from Android Java/Kotlin world). I don't like the community which is, mostly still stuck in the enterprise(though that's changing alowly) and often feels like an MS cult, but otherwise, there's nothing bad I could really say about .NET. Especially when paired with Azure ecosystem, it's really easy do develop and deploy, it's really fast, easy to work with thanks to Entity Framework and stuff like LINQ, there's a lot of choice in libraries. Some are still stuck in .NET Framework(Windows) world, but most of Nugets already implement at least netstandard2.0 which allows you to use them with Core. In overall, especially now with Blazor becoming a thing, I'd recommend at least trying it out.