News for hackers. Stuff that matters.
Re:Best aspects of C by loup-vaillant on Tuesday November 17, 2020 @05:36PM (#25130854)
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.

Re:Best aspects of C by josephcsible on Tuesday November 17, 2020 @07:20PM (#25131662)
> 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...

Re:Best aspects of C by loup-vaillant on Wednesday November 18, 2020 @03:11AM (#25134268)
> 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.

Re:Best aspects of C by josephcsible on Wednesday November 18, 2020 @09:12AM (#25136916)
The 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.
Re:Best aspects of C by loup-vaillant on Wednesday November 18, 2020 @06:00PM (#25143783)
My 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.

Re:Best aspects of C by gautamcgoel on Tuesday November 17, 2020 @10:29PM (#25132880)
I have to say, this is one of the most patronizing comments I've come across. It's rude even by HN standards.
Re:Best aspects of C by loup-vaillant on Wednesday November 18, 2020 @03:12AM (#25134270)
That certainly wasn't the intention. What part rubbed you the wrong way?
Re:Best aspects of C by gautamcgoel on Wednesday November 18, 2020 @06:32PM (#25144137)
This 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.

Re:Best aspects of C by randomNumber7 on Wednesday November 18, 2020 @05:50AM (#25135329)
> 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()...

Re:Best aspects of C by loup-vaillant on Wednesday November 18, 2020 @07:02AM (#25135844)
The "impossible" has been done: http://www.projectoberon.com/

Not sure about the memory allocator, Oberon may have avoided the problem by having a GC.

Re:Best aspects of C by randomNumber7 on Wednesday November 18, 2020 @02:57PM (#25141655)
This 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-pasc...

Re:Best aspects of C by int_19h on Thursday November 19, 2020 @03:13PM (#25153822)
This 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

Re:Best aspects of C by loup-vaillant on Wednesday November 18, 2020 @05:57PM (#25143747)
Thanks 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.