4 ms·
You probably don't realise it, but you're cheating. Operating systems are currently written in C, and therefore have a C interface. Which language is best at i
by loup-vaillant 6y ago
You probably don't realise it, but you're cheating.
Operating systems are currently written in C, and therefore have a C interface. Which language is best at interfacing with C? (No trick here, just a rhetorical question.) C of course. Other languages would need some sort of FFI, which is generally unwieldy enough that the designers hid it behind a comprehensive standard library.
C doesn't need an huge library to be available, you say? Oh but it does. It's called the kernel. Comes with a freaking huge runtime too.
> Imagine if you need to write a new OS, a compiler, a linker, or a shell interpreter... you get the idea.
I think I do, but I'm afraid you don't. Writing an OS (and the rest) in Pascal (I'm thinking of Oberon specifically) is no harder than to write it in C. If you write your whole OS in Blub, interfacing with Blub will be easiest in Blub, you won't need an extensive Blub standard library because you already have the kernel, all the tools (debuggers, editors…) will be Blub friendly…
Lisp machines used to be a thing, you know.
> My conclusion is that language designers still didn't get what made C so successful […]
Language designers can't even address what makes C so successful: network effects.
- josephcsible 6y ago> Operating systems are currently written in C, and therefore have a C interface. Not true. Operating systems are written in C with some assembly, and the interface to userspace is universally written in assembly. E.g., https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/arch/x86/entry/entry_64.S?h=v5.9.8#n95 https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux...
- loup-vaillant 6y ago> the interface to userspace is universally written in assembly. Which by some eery coincidence happens to conform to the C ABI of the platform. Come on.
- josephcsible 6y agoThe point is that it has a C interface despite being written in assembly. Your original post said the only reason it had a C interface was that it was written in C.
- loup-vaillant 6y agoMy original sentence was "Operating systems are currently written in C, and therefore have a C interface." I stand by that claim: the only reason operating systems have a C interface is because they are (at least originally) written in C. The fact that the kernel has some parts in assembly is immaterial, even if those parts happen to comprise the userland interface. And it's not just the kernel: when UNIX was re-written in C, everything was written in C. The compiler, the core utilities, the editor, the shell… the whole OS, not just the kernel. Of course it was easier to interface to that in the same language everything else was written in. Likewise, the Oberon operating system, which was written almost entirely in the Oberon language (which should have been named Pascal-3) has an… Oberon interface. Want to use C to interface with it? My, you'd have to write a whole compiler, perhaps a non-trivial runtime, debugging tools, and of course an FFI to interface to Oberon, the de-facto linga franca. C looks much worse when it's not already the king of the hill. Its strength lies in its ubiquity more than in any quality of the language itself.
- gautamcgoel 6y agoI have to say, this is one of the most patronizing comments I've come across. It's rude even by HN standards.
- loup-vaillant 6y agoThat certainly wasn't the intention. What part rubbed you the wrong way?
- gautamcgoel 6y agoThis line: "I think I do, but I'm afraid you don't. " PS. I appreciate you reaching out and making an effort to understand why the comment seems snarky to me.
- randomNumber7 6y ago> Writing an OS (and the rest) in Pascal (I'm thinking of Oberon specifically) is no harder than to write it in C. You can't because it is impossible to escape the type system. Without the ability to cast pointers you can't write a memory allocator. You can't write a function like dlopen()...
- loup-vaillant 6y agoThe "impossible" has been done: http://www.projectoberon.com/ http://www.projectoberon.com/ Not sure about the memory allocator, Oberon may have avoided the problem by having a GC.
- randomNumber7 6y agoThis is a nice article about the shortcomings of pascal. I don't know oberon so maybe it changed a bit. http://www.cs.virginia.edu/~evans/cs655/readings/bwk-on-pascal.html http://www.cs.virginia.edu/~evans/cs655/readings/bwk-on-pasc...
- loup-vaillant 6y agoThanks for the link, I'll go take a look. I'm pretty sure Oberon addressed some of the pitfalls cited there, if only so Wirth could write an OS with it. Not every language is OS worthy, after all.
- int_19h 6y agoThis article talks about Wirth's Pascal as originally defined. But various language dialects evolved way beyond that, and some of them became effectively dominant. Here's what low-level programming in Pascal looked like on DOS: http://www.retroarchive.org/swag/TSR/0022.PAS.html http://www.retroarchive.org/swag/TSR/0022.PAS.html