152 points · by kryptiskt · 3y ago · 132 comments
Eventually, I moved to other platforms and programming languages and had an epiphany that to function as a programmer of Windows software, I needed to know a lot of details about the platform. The literature was overflowing with articles about how you could utilize the platform more efficiently if only you knew some details under the hood. Moving away from Windows programming freed up a lot of mental resources.
When I started programming in Java on top of all libraries and frameworks, I noticed that I was never really encouraged to look beyond the API. On the other hand, there were usually multiple implementations of those APIs, so if I wasn't satisfied with one, I could choose another.
Of course, building GUIs in Java was (and still is) a real mess, so I didn't do that. Since then, I have programmed quite a bit in C# with the classic Forms-based platform on .NET, and this was a totally different experience from C++ and MFC. It was a delight.
Reading this article was like traveling back in time to the olden days, where you are promised better performance if only you look under the hood. My honest suggestion is: don't do that, don't lock up resources on needing to understand how things are implemented under the hood or how the compiler handles these particular constructs. If these details cannot be hidden from you, and you need to build a large knowledge base around stuff that does not directly contribute to implementing your program, then choose another platform.
I have managed to accumulate a growing understanding of how to solve problems, many times transferable between platforms and languages, but collecting all that insight into MFC minutiae was completely worthless.
Digging deep into the core libs also makes you a better programmer by renforcing idiomatic patterns and exposing you to new techniques. Just the other day I dug into how ArgumentNullException.ThrowIfNull works, and discovered the newish (C# 10) attribute [CallerArgumentExpression("argument")] which gives you a string with the expression used to pass that parameter (i.e. in most cases, just the original variable name.) This has now entered my mental toolbox for stuff like validation code. The docs for this are actually quite good (https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...), but one has to know it's there. Often, reading other code is the best way to discover new features/techniques, and what better code to read than core .NET itself.
I had the same experience. And then I learned win32, the C predecessor of MFC, and it all started to make sense.
MFC is basically a horrible attempt to put an Object Oriented layer on top of win32. But they failed miserably at it. The API was so bad that I preferred just writing it in win32.
And no, this was not a failure of OO, this was a failure of understanding and applying OO.
Also the template support in the compiler was limited at the time. Later on there were other libraries that used templates like ATL and WTL.
You did get a lot for free from MFC when implementing document editing applications for OLE support, but that was an increasingly small portion of development.
I think Borland went a different way with compiler extensions for producing a Win32 application with their OWL library.
I agree that this particular combination of features was not as useful in practice as the higher-level and more free-form approach offered by e.g. Delphi. But that's a different story.
For the reverse of your example, consider Java and .NET GCs. Most people don't need to tune Java GC and can just copy some config off stack overflow, however Java GC (GC-s, actually) tuning for perf and reading its verbose log is a whole dark art and there are tons of really long and verbose articles and example stories online. .NET GC is much more opaque in my experience, and that is really annoying when it doesn't "just work".
async await makes writing async code stupid easy most of the time... much easier than in Java, although I haven't used Java in a few years, it could have improved. However when it doesn't quite work you need to look under the hood.
I also found that startups (my preferred work env) tend to filter you out when you have too much of that on your resume which is super shitty IMO but it's a thing. I'd love to see that change. Until then I guess I'll stick with Kotlin and TypeScript.
In my observation, more and more startups have been taking off with C# and .NET. It’s very productive and efficient. It truly shines in many popular benchmarks. With .NET, many potential choices have already been made for you, it’s a true framework. You get a great setup out of the box which you can tune to your liking. It’s like Angular. Java is like React - there’s a core library and the rest is on you, Spring to the rescue, or Quarkus, or Micronaut, or… a hundred other frameworks. Very flexible but also quite fragile. The CLR has much fewer knobs than HotSpot or OpenJ9. I like that actually. It’s just more efficient in most cases. Can’t speak to multi-terabyte heaps with CLR though, haven’t been there.
The GUI story with .NET is amazing. Other than MSFT’s libraries, you have Avalonia and Uno as popular alternatives. Avalonia is very snappy. Uno has a great potential. Both are multiplatform (handheld and desktop devices, with the same codebase). Then there’s Blazor for the web in various incarnations and MAUI on Xamarin. Kotlin’s (Jetpack) Compose Multiplattform is still a couple years behind Avalonia and perhaps Xamarin. And JavaFX GUIs have never been this good or resource efficient, there are a couple other Java frameworks but they are apparently financially too resource constrained to compete yet.
As for the enterprise, I’ve seen both, retrograde Windows shops reluctant to change, riding a slow-paced product lifecycle, as well as agile projects upgrading their .NET stack a few days after the most recent GA release, often having run CI on RC releases well ahead.
Perhaps it’s location dependent. Denmark being an outlier is virtually exclusively .NET. In China, Go is very popular, you also see many contributors to Go projects on GitHub from China. Same with Vue. In short, there are also socioeconomic idiosyncrasies to it.
It's either what you mentioned or they have very outdated development practices.
Also, they did terrible work when it was first introduced, low level details were leaked to app surface and it was impossible to comprehend for a regular programmer what the hell is going on? Do you remember ConfigureAwait(false)?
Years later such guidance compiled: https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/b...
Agree with the grandparent. Async/await is unnecessary complexity in all but the most performance-oriented languages (like Rust).
Very curious to see how Java Loom will pan out in practice.
assert P;
foo(); // blocking call
assert Q;
and assert P;
await foo(); // await on an async call
assert Q;
?There may be some (e.g. thread identity is preserved in the former but possibly not in the latter, depending on implementation, and that could be expressed with proper assertions), but they only highlight how the differences are merely technical and certainly not "inherent".
The question is rather: is it possible to remove the await and just automatically rewrite every program to use await where necessary?
And the answer is no, because with only sync functions you have the guarantee that if your thread crashes, every code immediately stops executing. Not so with async functions. Once they are run there is a chance that your own thread crashes but some other thread keeps executing more code, at least for some time, potentially executing side effects.
It cannot be automatically decided if this is okay or not. Or to turn it around: the behaviour of a program that automatically awaits async functions (which formerly where sync) can be different.
Wrong. Languages that definitely got it right:
Erlang/Elixir (high level), especially elixir's Task.async
Zig (low level)
Very close runner-up: Go
vs-threading should be part of the .NET standard library but somehow isn't.
I knew Go can do it, so it doesn't "always fail"
What if you are reading the file and somewhere else in the code there is some logging happening. Should the logging flow stop until reading the file is done? Should it not? If not, what should happen if the "thing" (e.g. thread) that executes the code to read the file crashes?
Go does not treat sync and async the same. It specifically has syntax to deal with async, e.g. go routines.
I remember it and still use it, and you should, too. It can be elided in ASP.NET Core, which is the web application framework. Outside of that, there’s no escaping that you have to know what you’re doing.
I understand that such a design is called "green threads" https://en.wikipedia.org/wiki/Green_thread
As far as I know, there have been recent prototypes in .NET, but nothing shippable.
https://stackoverflow.com/questions/37285366/green-threads-i...
https://www.reddit.com/r/csharp/comments/vapgxn/net_experime...
It took me quite a bit of coffee to fully appreciate the simple phrase "it's async/await all the way down"
This is not a good idea unless you like having to make all your code thread-safe (well, async-safe). Explicit declaration of "hey this method might not run all at once or be interleaved with other methods" is a good idea; explicit opt-in is the same in every other implementation of async/await (ex: js).
Nope, it is not same in every other implementation. e.g Golang.
It’s literally the configuration, to be used according to your needs
What makes you think that this no longer applies? It still does to my knowledge. The page you linked to has a section for it that just says "TBD".
In modern ASP .NET, it does nothing, so we don't use it.
https://stackoverflow.com/questions/42053135/configureawaitf...
For example, very rarely in my experience does a function switch between synchronous and asynchronous. So when it does happen and I have to update upstream call sites, it's not so frequent nor painful enough to damn the whole abstraction and then go "see? it sucks".
When people suggest an alternative abstraction like Go, I compare my 50 lines of WaitGroup code in Go to things like `await Promise.all([prom1, prom2])` in Javascript. It's all just trade-offs.
Take a look at Java's approach (Loom + Futures + Structured Concurrency). It allows you to be succinct yet avoid the explicit async/await approach.
Also, async/await doesn't cut you off from anything. You just need to understand what is and isn't an asynchronousable end-point, people get confused then start throwing random keywords around without really grasping how it works (e.g. "if I await everything, it is concurrent, right?!" then write a bunch of code that actually runs synchronously but with tons of overhead).
I guess this is my nice way of saying: You need to read this very article. It corrects your concerns, and shows you when async/await is useful and likely when it isn't.
2. We already have a way of making things run in parallel: threads and processes.
See the first code example in the fine article. The OS
Good: Rust, JavaScript/TypeScript, C# and Swift
Interesting: Golang, Erlang/Elixir
Bad: Java and most JVM implementations, C++ (cumbersome, the language is bad by modern standards in general)
* pull based -> you don't need to worry so much about rate-limiting like you do with events
* works well when needing to pull over slow communications (serial, remotes)
1) Use Task.Run and await its result whenever you need it.
2) make a blocking call; same as if async wasn't available.
How does having option 1 make the situation worse?
With async/await the code ends up structured the same as if the operations were synchronous. It's much easier to follow and modify.
It’s not .NET Framework anymore. Or .NET Core. And it’s none of the countless random things Microsoft has labelled .NET. I think the name fundamentally misleads my brain every time given it’s not necessarily a web framework. I need .NET runtimes for my video games.
So it’s basically a managed group of tools and libraries to let you build stuff in a handful of different languages, usually C#, but targeting the same runtime, which is a JIT? So is it basically like Java but with far too much marketing involvement over the years?
It all started with '.NET Framework', which was the old Windows-only implementation. Eventually they rewrote everything to be cross-platform and called it '.NET Core'.
Distinguishing between the two was confusing, so MS took the genius decision of rebranding it all as just '.NET'. So today you can make a project in .NET 5, .NET 6, .NET 7, etc., and they're all cross-plat.
Various frameworks exist on top of .NET. The biggest one is ASP.NET Core, the web framework. And there's frameworks on top of that like Blazor.
The runtime is JIT by default, but you do actually have AOT options nowadays, which is nice.
.NET Framework is analogous to the JVM.
Micro-frameworks that don’t pack the kitchen sink like nodejs became popular, so Microsoft made .NET Core to be philosophically similar to that.
Because people such as yourself got confused by this, they eventually stopped pushing Framework and renamed .NET Core to .NET.
Microsoft has never been popular with the valley crowd, so everything they have ever done is pooped on constantly by people on here.
You should check out some of the posts on here when VS Code came out. A lot of people were amazed that Microsoft had built something decent “out of nowhere” like those people hadn’t just been living in a bubble their whole career.
Wouldn't CLR be closer to JVM? https://learn.microsoft.com/en-us/dotnet/standard/clr
And then... I don't know, .NET Framework to JDK, or something like that?
I like the whole thing (since .NET now runs on Linux well enough, C# feels okay as a language and has good tooling, like Visual Studio or JetBrains Rider) but there's definitely some naming and branding confusion sometimes going on, including in my own head.
No, its the library, not the runtime.
> Micro-frameworks that don’t pack the kitchen sink like nodejs became popular, so Microsoft made .NET Core to be philosophically similar to that.
.NET Core was still a very batteries-included library, it just dumped bits tied to Windows and made some other backward-compatibility sacrifices to get something cross platform and open sourcable.
> Because people such as yourself got confused by this, they eventually stopped pushing Framework and renamed .NET Core to .NET.
IIRC, they announced the long term plan to move all functionality that would be retained into Core and converge on a single implementation fairly early on, but to move forward in parallel until then .NET Standard versions were created to identify compatibility across Core and Framework during this period.) Dropping Framework and making Core just unqualified . NET (and eliminating the need for Standard) was just the completion of that strategy.
an ecosystem made of languages, compilers, runtimes, libraries, tools and community.
Even those the work at Microsoft haven't been able to work that out since they coined the term, let alone developers etc.
Except you don't need anything .Net specific to be installed on the end user machine. I build and deploy single-file C# binaries to Linux all the time. There's no longer a dependency on having the .Net framework installed or having dozens of DLLs accompanying your binary.
Self-contained deployments are platform-specific.
A deployment that depends on a shared runtime can be cross-platform, since all the platform-specific parts are in that shared runtime installed for that machine's platform.
Which does .NET do? all of the above.
This is not wrong.
.NET Framework = the built-in class libraries. Confusingly, also ".NET Framework" can mean the older, legacy, Windows only version of the whole thing.
ASP = the web server and web services centric parts of the framework.
NuGet = package management for built-in and 3rd party libraries.
Roslyn = the C# compiler
CIL : the bytecode "Intermediate Language" emitted by that compiler
CLR = Common Language Runtime for CIL, and related concerns such as GC and JIT
So I suppose "ecosystem" is correct.
C# a general purpose high-level language, OO-first but with some functional things.
The other problem is that it's broad: a person can use C# and.NET for one thing (e.g. Web services, or Desktop GUIs), and have strong opinions about what's needed and how to do things, and have them validated daily with all colleagues, assume that this is universal but ... those opinions are not true of the other.
Yeah, it's confusing. Took me some work to get through too.
The JRE-equivalent in the .NET stack is the Common Language Runtime. The JRE processes Java bytecode; the CLR processes Common Intermediate Language (CIL, formerly MSIL) instructions.
The simplicity of:
dotnet build MySolution.sln
Is the only reason I am still doing software for a living. I am completely over my tools. I just want to solve problems and build things now. If I have to lose 5% perf because I'm lazy, so be it. I'll hire someone to obsess over the 5% later on - and only if the customer complains.C# is an amazing, well thought out language, agreed.
> async/await is the same as in javascript
How many variations of async/await coroutine programming are there? Not saying I disagree, but I think most of them are similar.
> the documentation and official guides are miles ahead of Java
This is where you lose me. It's been a few years, but the last time I looked at dotnet docs it was a steaming pile compared to most other languages I've looked at, including Java.
That being said, I would never tell am aspiring developer, especially one with a CS degree to learn it.
Besides, Microsoft, it’s not used heavily in most companies that pay top of the market and it’s definitely not the language that I would chose to use if I had to go through a generic coding interview.
Yes, I’m well aware that most of the 2.7 million developers in the US are “enterprise developers” and many use .Net. While .Net has been cross platform for years, it’s still the choice of mostly old school Windows shops.
> language and compiler capable of rewriting normal control flow into a state machine implementation of coroutines