Systems Programming in C# by Joe Duffy
infoq.com
infoq.com
It's fine to try to salvage good ideas from a project that failed at its initial goals (and MS seems to have!), or even to hold on to thinking the basic ideas were good even though the implementation failed. But if he could just be candid about what wasn't right, he could spread those expensive insights you get by actually building a thing, and show a real ability to learn from failures. Who wants a postmortem that doesn't discuss what went wrong? How useful is it to talk architecture if you aren't clear about downsides and tradeoffs?
Concretely: What did the decision-makers who finally canned Midori dislike? What were the performance bottlenecks (and numbers) after all their tuning? Had they given up too much safety by the time they had it performing well? Was it a compatibility thing, and if so what are his thoughts on an approach to that? Was it just going to take too much investment to finish? I think a little candor about the limitations, downsides, and hard-to-swallow parts of Midori could advance the thinking about its basic ideas much more than a lot of posts about implementation tricks.
Everyone that was able to use Oberon or the Xerox stacks knows that it is possible to have such systems and do productive work on them.
Mads has said that the changes that are coming are for apps like games that need more low level features.
No one is saying that a previous version, the current version, or even the next version of C# will be used to write an OS.
That being said, I really wish they had open sourced midori so that work was available to build on. I know that a lot of you think that only C should be used for OS development. (With the exception of a few of you that think Rust is magic.) They actually built a real operating system with managed code. It's basis in singularity included really novel ideas about where process boundaries should be drawn and how an OS should be composed. It's a shame that it isn't available. Not everyone wants to use or work on a UNIX clone.
Check Burroughs developed in 1961.
http://www.smecc.org/The%20Architecture%20%20of%20the%20Burr...
Or read about the Mesa/Cedar Workstation at Xerox PARC:
https://archive.org/details/bitsavers_xerox
If you want to read about a OS written in a fully memory safe language, including the source code, check Niklaus Wirth books:
http://www.ethoberon.ethz.ch/books.html
Specially Project Oberon. The 2013 re-edition has an updated hardware design for an FPGA.
http://people.inf.ethz.ch/wirth/ProjectOberon/index.html
This is how it used to look like in its latest incarnations as BlueBottle written in Active Oberon:
http://www.progtools.org/article.php?name=oberon§ion=com...
I would definitely still advocate using the right tool for the job, though. If the vast majority of your application would be best written in C++ or Rust (something without managed memory) I would just go ahead and do that.
A lot of people, however, have cross-layer applications where a substantial amount of the code has strict performance requirements, but much or most of the rest of the code has looser requirements.
Now imagine you stacked 2ms GC pauses into that level of the system. That would be a barely serviceable kernel. Forget any real-time facilities.
So you can have a GC free TCP/IP stack, while enjoying the GC comfort in areas where the 2ms pause aren't an issue.
http://lukego.github.io/blog/2013/01/03/snabb-switchs-luajit...
Real-time just means bounded latency. If 2ms was a hard upper bound, that's hard realtime. If it's ~90% bounded by 2ms with a small variance, that's soft realtime.
However, it doesn't change the fact that it allows for lots of low level stuff in the similar vein as Oberon, which is why I happen to take Go's side, even if I rather use other more expressive programming languages.
And to be faire, Niklaus Wirth latest language changes (Oberon-07) are even more minimalist than Go's.
Some things about Go may make that style of programming feel more natural. For example, structs are the default and syscalls look like other function calls. The stdlib might be friendly to this style (for example, widespread io.Reader/Writer lets a lot of stuff stream data through a reusable buffer rather than allocate big blobs) but I don't know enough to usefully compare it with the .NET libs/BCL.
Or C# could be better for you. It has a lot of work behind it, including in the collector. Go's collector is now decent at keeping most work in the background but isn't generational or compacting as the CLR collector can be. And using a new language is always weird; you never start out as good with the new as you were with the old. The CLR's SustainedLowLatency collector mode, which tries to defer compaction as long as it can at the cost of RAM footprint, is the one that sounds most like Go's, FWIW.
It all depends so much on what kind of deadlines your app has, how much memory pressure, what else you're getting/paying for in C# land. It's always tricky to grok a different ecosystem. The best ideas I can think of are to look for something existing in Go that seems kind of like what you want to do (like if you're implementing some kind of queue, look at NATS or nsq or such), or just build the smallest project that seems like a reasonable test.
Even hardware interfacing via memory mapped addresses would just need a small shim and types that are byte compatible with C structs you can call via P/invoke, isn't particularly complicated.
Can you give a specific example of what you're referring to?
What sort of performance issues do you see? Do you mean the p/invoke/marshalling costs?
The performance issues were in the image processing and analysis areas. Image analysis doesn't really lend itself to bounds checking, non-deterministic memory usage, little control over heap allocated memory, etc. Also, I lose access to some of the most powerful imaging libraries out there.
I can work around a lot of it, but why should I have to? Should have used the right tool from the start.
You haven't specified what the right tool is. I think classifying C/C++ as the right tool is contentious too for the reasons I outline. The "type wrangling" isn't there for no good reason, the reasons are quite clear: to maintain memory safety and benefit from automatic memory management. There's also the possibility that you're making it more complicated than it needs to be.
In the slides posted by pjmlp[0], I found one slide particularly interesting: Slide 38 about Contracts:
Contract.Requires(buffer != null);
Contract.Requires(
Range.IsValid(index, count, buffer.Length)
);
or the Debug variant of it : Contract.Debug.Requires/Assert/Fail
It reminds me of the Dafny programming language[1], but here this seems to be used for performance. The future C# AoT compiler could be validating those Contracts, and from these Contracts enables more aggressive optimizationsThe slide about PackN (and future "Safe" stackallock) is also great, it seems like the easiest optimization someone can apply to its current code.:
int[] array = new int[8] { 0, ..., 7 };
// Heap allocation! For short-lived arrays, this is bad!
Versus the proposed "Safe": Span<int> span = stackalloc int[8] { 0, ..., 7 };
[0] https://qconnewyork.com/system/files/presentation-slides/csy...In some ways, yes, but was C# ever intended to be a systems language? No, and that's obvious from its design. So, what is this really telling us? That the language has issues when used in a way it was never intended to be used?
Improving the compiler to better handle X, Y, Z will yield to improvements all over the spectrum, not only in systems programming. C# used as a systems language only helped us find those issues faster.
Short-lived stack allocated arrays, zero copy, etc. isn't something only systems programmers need. if your average ASP.Net webserver can benefit from it, it's a good thing.
I can understand why L4 choose C++ at the time, as it had stricter checking than C, but OS kernels have very little internal code reuse that necessitates inheritance or templates. This is doubly true of microkernels. There is literally no reason to use C++ in this domain. Ada or C, and soon Rust should be the only considerations IMO.
If you install the CodeContracts verifier, it does.
Usually the videos take some time to appear at InfoQ.
You are right about the github one.
https://en.wikipedia.org/wiki/Oberon_(operating_system)
http://wiki.osdev.org/Go_Bare_Bones
If I am able to write an OS using just the language, with the help of some Assembly, or bootstrap the language and runtime, it is a systems language.
Many of the criteria people use to judge systems languages like inline assembly, would disqualify C when applied to a pure ANSI C compliant compiler without language extensions.
You don't want the GC to mess with your lovely data structure?
Allocate on the stack, as a global static or let the GC know not to touch it.
Check Algol-68RS, Mesa/Cedar, Modula-2+, Modula-3, Oberon, Oberon-2, Active Oberon, Oberon-07.
Whether a particular language makes that nice enough to be more worth using than a non-GC language is another question.
This is only true of specific GC implementations. Incremental GCs never pause the program. On-the-fly and realtime GCs pause the program for a few microseconds.
[1] https://www.netbsd.org/gallery/presentations/mbalmer/fosdem2...
https://en.wikipedia.org/wiki/Real_time_Java
https://www.aicas.com/cms/sites/default/files/rtsj-next-gen-...
http://www.ibm.com/developerworks/java/library/j-devrtj1/ind...
Languages don't have unpredictable runtime characteristics, only specific language runtimes have unpredictable language characteristics. One could replace the standard .NET runtime GC with a hard realtime GC, and .NET would then have more predictable runtime characteristics than C and C++.