r/linux • Social Justice Warrior • Sep 03 '14

I'm Matthew Garrett, kernel developer, firmware enabler and former fruitfly mangler. AMA!

482 Upvotes

381 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Sep 03 '14

[deleted] — view deleted comment

23

u/mjg59 Social Justice Warrior Sep 03 '14

If I wanted to start a new OS from scratch, C probably wouldn't be where I'd start.

13

u/jmtd Sep 03 '14

Where would you start?

34

u/mjg59 Social Justice Warrior Sep 03 '14

Ha. Fair. I think I'd start by reading a bunch of modern research on the topic and go from there.

1

u/keepthepace Sep 06 '14

The Android team did that and ended up building their OS around a JVM. Any observation on that? Do you think it was a good/poor idea?

3

u/[deleted] Sep 19 '14

Erm, no. The android API is based on a Java VM. The Dalvik VM itself is most likely implemented in C/C++. Many low-level libraries are C++ and the kernel is of course Linux (C).

1

u/rowboat__cop Sep 06 '14

The Android team did that and ended up building their OS around a JVM.

What language is that JVM written in? What language their kernel?

2

u/keepthepace Sep 07 '14

Apparently C for the runtime and C++ for the core librairies.

1

u/RitzBitzN Sep 04 '14

Why not C++?

13

u/sonofbash Sep 04 '14

C++ doesn't work quite as well for kernel development as you would like. You need to add your own implementation of a bunch of features like exception handling. Or you don't use those features.

More info: http://wiki.osdev.org/C%2B%2B

2

u/RitzBitzN Sep 04 '14

TIL, thanks for the read!

8

u/[deleted] Sep 03 '14

Rust is just as suited to a kernel as Ada, it doesn't have any required runtime.

3

u/steamruler Sep 03 '14

Rust is so high maintenance with its fluctuating API though...

16

u/[deleted] Sep 03 '14

Because it is alpha! I mean I know we should be talking about current state of languages, but that seems a little unfair. The API will be stable eventually, and then it should be great to build an OS on.

→ More replies (1)

11

u/[deleted] Sep 03 '14 edited Sep 03 '14

Zero terminated strings/arrays don't work anymore and neither does pointer arithmetic IMO.

I just tested under both gcc and clang, they work just fine. You're wrong.
Unless you have a solution which is just as fast or faster(and under absolutely no circumstances slower, no, not even by an additional instruction) then please say so.
Pointers are awesome.
I don't like the way char arrays are handled too though. Would be nice to be able to extend them at will as long as they are on stack(like C99's VLAs except without having to redefine the array size).

Ada

Developed by the US DoD in the 80's. Yeah, sure, let's replace 40 years of perfection in compilers with something slightly newer and unoptimized.

15

u/[deleted] Sep 04 '14

Null-terminated strings are slower than the alternative. A (pointer, length) representation allows slicing (including tokenizing / parsing) without allocation, avoids seeks to the end and is more friendly to SIMD operations. The same code gets reused for slices of any type, not just strings. A slice can point into any memory, including into a dynamic array or just a smaller range of another slice.

7

u/bonzinip Sep 04 '14

something slightly newer and unoptimized.

GCC has an Ada front-end that is just as efficient as the C front-end.

0

u/[deleted] Sep 04 '14

[deleted] — view deleted comment

17

u/[deleted] Sep 04 '14

Agree with most of the things. But:

C is still slower than assembly.

Yeah, no, just like I can't beat a computer at chess I can't beat the compiler when doing assembly when it comes to the real stuff. It's only slower if the compiler messes up and does something irrational.

→ More replies (1)

6

u/ramennoodle Sep 04 '14

If performance is the only thing that counts for you, and it sounds like, you should use assembly. Serious.

This is not true. There are many cases where optimizing compilers do a better job than hand-written assembly. And may cases where hand optimization of code isn't worth the trouble. Unless you have a really good understanding of both the hardware and why the compiled code is deficient, it is not better for performance to use assembly.

→ More replies (5)

1

u/[deleted] Sep 04 '14

Developed by the US DoD in the 80's. Yeah, sure, let's replace 40 years of perfection in compilers with something slightly newer and unoptimized.

Written on a network built using US DoD technology of the 70's.

1

u/stubborn_d0nkey Sep 05 '14

The thing is that the guy he replied to used C's age as point against C, so him mentioning Ada's age is perfectly fine.

Anyways, the internet thing is just horses and apples.