[HN Gopher] .NET 5.0 - New APIs ___________________________________________________________________ .NET 5.0 - New APIs Author : todsacerdoti Score : 109 points Date : 2020-09-22 17:17 UTC (5 hours ago) (HTM) web link (blog.ndepend.com) (TXT) w3m dump (blog.ndepend.com) | SparksAndQuarks wrote: | I'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. | bob1029 wrote: | This 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. | mads_ravn wrote: | Sounds really interesting. Do you have samples, benchmarks or | other resources you can share? | bob1029 wrote: | Out 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 wrote: | I'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 wrote: | Shame 'with' will not apply to structs - all the ingredients | are already there. Through it might be in the plan for some | future release. | eropple wrote: | As I understand it, making structs implement the record | stuff would potentially be...weird. But you're right, it'd | be nice. | csharptwdec19 wrote: | > 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 wrote: | Pity that `void` is so special in .net, instead of being a | proper unit type (would have avoided the Func/Action | duplication as well) | recursive wrote: | DBNull 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. | GordonS wrote: | > 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 wrote: | The 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. | ocdtrekkie wrote: | I 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. | resoluteteeth wrote: | Isn't there a WinRT API that you can use from .net 5? | ocdtrekkie wrote: | Plausible, though https://docs.microsoft.com/en- | us/uwp/api/windows.media.speec... looks significantly | simplified from https://docs.microsoft.com/en- | us/dotnet/api/system.speech.sy... | | I'm not confident all the same functionality I've tapped into | can be replicated with this. | jahewson wrote: | It's possible that that System.Speech is using technology and | patents licensed to Microsoft for use in Windows but not | something they can sub-license. | gameswithgo wrote: | no third party libraries that fit the bill? | ocdtrekkie wrote: | I 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 wrote: | > 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/dotnetNewWorkerWindowsServic | e... https://www.reillywood.com/blog/dotnet-linux | ocdtrekkie wrote: | It might be somewhat simple, but their paid Visual Studio | IDE demonstrates no way to get there, and it probably | should. The only project types tagged as services are | .NET Framework templates to make a Windows service. | | I have to apparently read blog posts about how to get | there myself with .NET Core. Suffice to say, Microsoft's | move to the open source/Linux mindset may have come at | the cost of being similarly confusing to get started | with. | | Note that your blogs happily tell me to add a single | NuGet package for Windows or Linux, but doesn't bother to | tell me how to assemble a project that will work on both. | csharptwdec19 wrote: | > Microsoft refuses to port System.Speech for text-to-speech | and speech recognition. | | I think it's more complicated than just 'porting'... Something | tells me that System.Speech is a nice wrapper for a very | windows specific API. Similar to how Microsoft isn't bringing | over WCF Hosting (Because too many parts of it are dependent on | Windows itself.) | | Now, ideally, it would be nice if Microsoft would expose the | existing System.Speech source code, so that somebody could | begin the efforts of making it into an OSS Project that could | eventually _become_ multiplatform. | ocdtrekkie wrote: | Windows Forms and WPF are also both Windows API wrappers, and | they've been brought over for when you are targeting Windows- | based platforms. | | System.Speech is no longer available on Windows in .NET 5, | even if you're using Windows Forms or WPF, which are Windows- | only frameworks. | | In theory, if Microsoft was at least holding up compatibility | for such things on Windows, I could move my target towards | .NET Core/.NET 5, then gradually replace Windows-specific | code with cross-platform code. But as per usual, I'm getting | the impression it'd be easier to start over than migrate. | | I agree it'd be really nice if they open sourced the code | necessary to look at porting System.Speech, but I imagine | it'd be unpleasant as a business decision: It'd erode their | ability to bill people for the Azure "replacement". | CodesInChaos wrote: | Being windows dependent shouldn't prevent offering | System.Speech as a library that targets only windows. | worble wrote: | .NET Core/Standard already has windows specific API's, and | .NET 5 is going to make them safer to use going forward with | static analysis[0], so I doubt the Windows specificness is | the reason why. | | 0: https://devblogs.microsoft.com/dotnet/the-future-of-net- | stan... | systemvoltage wrote: | Can 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. | wenc wrote: | A really handwavy description would be that it's kinda like a | "runtime". | | It's very roughly analogous to the Java Runtime Environment | (JRE). .NET binaries are very roughly like JAR files. | | (I realize the analogy is rough, but I think it would connect | with folks who've never worked with a Microsoft stack) | pizza234 wrote: | I suppose that it's very similar in spirit as Java, with the | difference that Microsoft presented in a more encompassing way | (assuming that the definition of "software framework" was given | by MS). | | Often in fact Java is described as a language, while, at a | minimum, a Java distribution includes the JVM and the standard | library. | | Describing as a software framework is therefore (in this sense) | more exact, as the .NET framework includes the CLR and its | standard library (and possibly, other components). | | The difference with the Windows API is that they are lower | level. The simplest possible component one may think of is | probably LINQ - querying functionalities are intuitively higher | level than system APIs. | Inception wrote: | This is a pretty good explanation video about the .NET | ecosystem in general: | https://www.youtube.com/watch?v=bEfBfBQq7EE | josteink wrote: | > 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 wrote: | Are 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. | ablekh wrote: | Has 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! | retendo wrote: | I'm using .NET Core/F# for the backend of my bootstrapped | "startup". I mostly have an iOS dev background so take my | experiences with a grain of salt. | | So far everything has gone pretty smooth. ASP.NET Core is | running under the hood which seems to be pretty mature. F# and | the libraries that I work with all provide a functional | development experience. I interface with a Postgres database, | so there's libraries for that as well. | | You mentioned Domain-Driven Design. I would recommend reading | Scott Wlaschins book Domain Modeling Made Functional [1]. | | If you are interested in playing around with F#, a quick way to | start would be to try SAFE stack [2]. | | From what I have read during the last couple of months, MS | seems to be interested in pushing F# as one of their go-to | languages for machine learning. At least they have an F# | example online [3], which can not be said for most other areas | where F# would also be a good fit in my opinion. | | [1] https://fsharpforfunandprofit.com/books/ [2] https://safe- | stack.github.io [3] | https://dotnet.microsoft.com/apps/machinelearning-ai/ml-dotn... | ablekh wrote: | Much appreciate your feedback and advice. I was considering | using F# instead C# for my potential .NET-based solution. But | not because of Microsoft's ML push for F# (which seems to be | just a move to achieve feature parity with C# within ML.NET | framework, which, by the way, is not as comprehensive as | relevant Python ecosystem), but rather because of F#'s meta- | programming features. However, the advantages of F# still do | not overweight its IMO two main disadvantages: a much more | limited (vs. C#) pool of available developers and limited | support by tools beyond Microsoft ecosystem (e.g., by | JetBrains products). | atraac wrote: | I 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. | ablekh wrote: | I appreciate your prompt feedback with interesting details. | Re: Blazor - while it's definitely a promising technology, | I'm not sure how suitable it is for building SPAs. One | potential issue that I can see is quite limited (and IMO very | expensive, e.g.: | https://www.syncfusion.com/sales/products/blazor) UI | components ecosystem, when compared to the React/Vue/Angular | one (I plan on using Vue). | sunnyP wrote: | You might qualify for the Syncfusion Community License: | https://www.syncfusion.com/products/communitylicense | | Radzen also has a component library available: | https://blazor.radzen.com/ | | https://abp.io/ recently added Blazor to their framework | that you might want to check out. | cutler wrote: | I don't quite get the hype around Blazor. Great idea but the | implementation is a non-starter considering it has to send a | whole runtime over the wire. | bob1029 wrote: | We use it in server-side mode (no WASM assembly to | deliver). SSB is incredible for apps where you are | expecting a well-bounded number of concurrent users. | | We use it for internal business dashboards and devops | management tools. The ability to inject & use existing .NET | services is pretty incredible in terms of productivity. We | now maintain a monorepository because of this reuse | potential. | | https://docs.microsoft.com/en- | us/aspnet/core/blazor/hosting-... | GordonS wrote: | > Has anyone here used (or are familiar with relevant cases of | using) .NET for developing startup products, including MVPs? | | Yes, I have. I've been programming with C# since it was first | released, so we're very well acquainted, and I can build MVPs | quickly. As always though, it depends what you are used to. | | > I'm seeing .NET as predominantly an enterprise-focused | technology | | I didn't see it as any more enterprise-focused than Java, andid | say less so since dotnet core brought multi-platform support. | ablekh wrote: | Thank you for your feedback. When I said _" predominantly an | enterprise-focused technology"_, I meant overall popularity | for building in-house enterprise products versus developing | startup products. Anyway, should I decide to use .NET, I | would most likely use a high-quality boilerplate solution as | a foundation. Specifically, I'm a big fan of (and have | already played with) ASP.NET Boilerplate and its next-gen | version called ABP Framework. They also have relevant | attractive commercial versions. | bargl wrote: | I've worked at a startup that did this. | | I don't know if this was the program we used, but you can get a | LOT of free stuff from Microsoft as a startup. | https://azure.microsoft.com/en-us/overview/startups/ | | >Between Python and .NET ecosystems, I'm more familiar with the | former and, under equal conditions, would choose it over .NET. | | I think one thing you need to do when creating a startup is, go | with what you know (as you said). You want to decrease the risk | that you're product is going to be blocked by encountering an | edge case in a framework/language you don't know and you get | stuck there for a long time. I am way more familiar with .NET | than Python, but I use Python in my spare time and on side | projects to build up those muscles. | | If you're doing a startup and you want to go .NET, I don't | think there's anything holding you back anymore. It's open | source now, runs on Linux, and you don't have to pay a dime to | develop with it. Microsoft will get you in that, it's WAY | easier to pay a little bit to get Visual Studio Enterprise and | to then hook that into Azure and all of a sudden you're paying | them a ton of money. Yes, that's their master plan. But, no one | is making you do that. | | Where to stay away from .NET core: Lambdas. The startup time | for Lambdas just isn't where it is for other languages, when I | last looked at this. If someone has newer data to prove me | wrong I'll freaking LOVE YOU FOREVER! | | Anyway, depending on what and how you're building your startup, | .NET maybe a great pick for you depending on your background. I | wouldn't force myself to pick up a new ecosystem and do a | startup if I was focused on delivering a product I wanted to | deliver and not learning something new and cool. ___________________________________________________________________ (page generated 2020-09-22 23:00 UTC)