TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Is C# suitable for creating a modern OS like Windows 7?

37 pointsby sshykesover 11 years ago
Are C# and the .Net framework suitable to create a modern OS like Windows 7?<p>This is a followup question from [the now deleted] thread:<p>http:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20100812071342&#x2F;http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;783238&#x2F;why-windows-7-isnt-written-in-c<p>What kind of problems might one expect to encounter by choosing C# over the tried-and-true strategy of using C? What kind of problems in this domain might be better solved by a high-level language like C# compared to C?

13 comments

damian2000over 11 years ago
Microsoft had this as their aim with &quot;Windows Longhorn&quot;, announced ten years ago this month, but failed in their task and released instead Vista.<p>Here&#x27;s some relevant snippets from <a href="http://arstechnica.com/information-technology/2011/06/windows-8-for-software-developers-the-longhorn-dream-reborn/" rel="nofollow">http:&#x2F;&#x2F;arstechnica.com&#x2F;information-technology&#x2F;2011&#x2F;06&#x2F;window...</a> ...<p>* ... Longhorn would integrate .NET into the core Windows platform. .NET FX, as it was known in the company (with &quot;FX&quot; standing for &quot;framework&quot;) would give way to WinFX, a Windows Framework based on the same technology. Among other things, this would include a brand new way for writing user interfaces, codenamed Avalon, that would be thoroughly modern, vector-based, and hardware-accelerated. Windows itself would be written to use WinFX for its user-visible programs—Explorer, calculator, and so on—and, going forward, .NET would be the way to write Windows applications. Win32 would still exist for backwards compatibility, but it would be frozen and left static.<p>* Longhorn would have been the end of the old ways of writing Windows programs, and the dawn of a new era of modern Windows development, one that was not hamstrung by design decisions made ten or fifteen years prior.<p>* As we all know now, Longhorn never shipped as such. The project grew enormous, unmanageable, and broken. Around the same time, Windows XP, on which Longhorn was based, was being ravaged by hackers. Microsoft poured its resources into making Windows XP and Windows Server 2003 tolerably secure—an effort that culminated in Windows XP Service Pack 2 and Windows Server 2003 Service Pack 1—then, for the most part, started development of its next operating system, the one eventually to ship as Windows Vista, all over again.<p>* One of the biggest losers in this developmental reboot was .NET. Windows Vista, though radical in some ways, abandoned the entire &quot;WinFX&quot; concept. Avalon did ship—it&#x27;s now known as Windows Presentation Foundation (WPF)—but as an add-on to the operating system, not a core part.
评论 #6480766 未加载
评论 #6480789 未加载
评论 #6481027 未加载
memracomover 11 years ago
Yes, there is no question that C# is sufficient to write an OS. However, you would need to ignore&#x2F;replace the libraries that are normally used with C# applications. Instead you would write your own low-level libraries that provide only the kind of services that an OS requires. But the biggest hurdle will be the compiler. A normal C# compiler only generates bytecodes that will be run on the .NET or the Mono virtual machine engines. You will need an additional stage of compiler that either produces machine code, or something that can easily be converted to machine code such as C code or GCC&#x27;s intermediate representation. It is a hurdle but not a massive one since there is a lot of support out there for writing compilers. People have recently been writing compilers for a number of languages that emit Javascript and your hurdle is no more complex.<p>When you write your compiler you will probably end up leaving out some C# features such as reflection, because they are too intertwined with .NET. This is common with other languages when people have tried to write a compiler that emits machine code and it does not usually cause a problem because the problem of interfacing with hardware does not demand the same features from a language as building a modern web app does.<p>Do your research before starting this because you will likely find a lot of projects that have already built bits and pieces that you can reuse.
fleitzover 11 years ago
Yes, it&#x27;s already been done. <a href="http://en.wikipedia.org/wiki/Singularity_(operating_system)" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Singularity_(operating_system)</a>
评论 #6480704 未加载
评论 #6480999 未加载
评论 #6481024 未加载
fusiongyroover 11 years ago
The Lisp machine operating system was written in Lisp. In fact, it was Lisp all the way down to the microcode, or at least, it would present the microcode in Emacs as if it were Lisp, and you could modify it there. The Lisp machine OS was similar to other OSes of the age, more capable in many ways.<p>A modern OS is a huge amount of work. It&#x27;s so vast, your choice of language isn&#x27;t going to make or break you. Moving a mountain with a tablespoon should proceed three times faster than with a teaspoon. You&#x27;re still looking at an eternity if you&#x27;re the only guy.<p>For this reason, your best bet is to narrow in. Decide what it is you want to write an OS for. Do you want to explore novel user experiences? C# is probably fine for that. You don&#x27;t need to write the whole OS there, just the &quot;shell&quot; and the window manager. You can do that now, and not spend any time dealing with drivers. Do you want to experiment with microkernel or exokernel architecture? You&#x27;ll be breaking new ground. Is C# OK for that? What you&#x27;re really asking is, what are the limitations of C# that you&#x27;ll run into? The GC pause is one, another is dealing with raw bytes and making it perform. If make the CLR self-hosting, you&#x27;re going to find performance problems like crazy. If you make fixing that your mission, you could be a hero like the PyPy guys, and everything gets better, or you might just be throwing away a lot of work.<p>I happen to think a lot of interesting problems would benefit from a high-level approach. Security is a declarative process. You want to say what you want secured and not how. Only one system I know of has ever used Prolog for this (MeeGo, IIRC?) but it was probably a perfect fit. There are lots of opportunities for this kind of thing in OSes and they&#x27;re never really exploited. If your whole kernel is C and you want to add a declarative security module, well, you&#x27;ll be writing C. You can surely accomplish the same tasks in C as C#, but if it&#x27;s a pain in the ass you&#x27;ll either wind up with a weaker or more limited version in C, or you&#x27;ll spend more time writing and polishing it. But the world is ripe for a few people to take the unpopular tradeoff and see how well it works out, rather than taking their predecessor&#x27;s word for it.<p>To sum up, they&#x27;re not suitable for the whole job from start to finish. However, if you tried it, you&#x27;d make some interesting stuff, and learn a lot, maybe even make things better for other people. Take a crack at it. Worst thing that could happen is you fail. :)
评论 #6480917 未加载
评论 #6480769 未加载
spongleover 11 years ago
Yes but why would you want to?<p>I can&#x27;t think of a single long term advantage of using a language that high level to build system software. Sure it makes a cute research project but that&#x27;s about it.<p>As for application level stuff, a big chunk of windows 8 is c#, mainly in the metro space as is windows phone.
runjakeover 11 years ago
I&#x27;m going to put the equivalent effort into answering this question that you did into researching it: maybe, maybe not.<p>That you didn&#x27;t mention Singularity or Cosmos tells me that you haven&#x27;t cared enough about this to even do a cursory Google search on the subject.<p>Anyway, Google those above OSes, browse through their white papers and you&#x27;ll have your answer (as given above). You might also check out JavaOS, Inferno, JNode, etc which have similar goals.<p>To get you started with less effort:<p><a href="https://en.wikipedia.org/wiki/Singularity_(operating_system)" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Singularity_(operating_system)</a><p><a href="https://en.wikipedia.org/wiki/Cosmos_(operating_system)" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Cosmos_(operating_system)</a>
sseveranover 11 years ago
In fact a few people at MSR had that exact idea (<a href="http://research.microsoft.com/en-us/projects/singularity/" rel="nofollow">http:&#x2F;&#x2F;research.microsoft.com&#x2F;en-us&#x2F;projects&#x2F;singularity&#x2F;</a>).
CyberFonicover 11 years ago
To write an OS you need to generate native executable for the hardware that you are running on. The mainstream implementations of C# require CIL + CLR. i.e. you need a virtual machine + libraries and framework. Not exactly &quot;bare metal&quot; environment.<p>But C# is more advanced language than C, so that might be beneficial in some areas. As a minimum you would need a C# to native compiler and facilities to include assembly language code in some low level areas.<p>To get a better idea of what it takes to implement an OS, take a look at the Linux kernel source code. Or if that is too daunting, you could look at Minix 3 sources.
评论 #6480693 未加载
评论 #6481023 未加载
agsamekover 11 years ago
What makes C suitable for low level programming is not only lack of GC, but lack of global heap at all. Global heap is just a library thing. You can decide to alloc on a stack or use a particular memory region for allocation. Also you routinely copy between user and kernel spaces for security. This is totally different then global GC and global heap approach of c#. All works around this problem is basically getting away from C# so could you still call it OS written in C# when this problems were solved?
devxover 11 years ago
You might want to wait for Rust to be ready, because this way you can build an OS that truly made for the future (very optimized for multi-core).<p>If you don&#x27;t want to appeal to the general market, but more for a specialized market (like in enterprise or whatever), then you should probably optimize it for AMD&#x27;s Mantle API, too, and take full advantage of the performance for both the CPU and GPU that you get from that. Also don&#x27;t even bother with 32-bit.
yareallyover 11 years ago
Elementary OS is built on Vala, a language syntactically similar to C#, but compiles to C. Not trying to detour you from C#, but it might be a better option as even Singularity is not entire C# (the lower level stuff).<p><a href="http://elementaryos.org/" rel="nofollow">http:&#x2F;&#x2F;elementaryos.org&#x2F;</a>
评论 #6480745 未加载
topbananaover 11 years ago
Microsoft carried out a research project looking into this, but an open source group is actively developing another implementation.<p>What they&#x27;ve achieved is really quite impressive. <a href="http://cosmos.codeplex.com/" rel="nofollow">http:&#x2F;&#x2F;cosmos.codeplex.com&#x2F;</a>
评论 #6481035 未加载
pshcover 11 years ago
No, but Rust is a contender.
评论 #6480710 未加载