Live data from Hacker News

Thor – A minimalistic operating system in assembly and C++

github.com

21–30 of 152 posts

Re: Thor – A minimalistic operating system in assembly and C++

#21
post #3

An OS in C++? But Linus said... http://harmful.cat-v.org/software/c++/linus

As other's have stated, that is just Linus's opinion, which he is entitled to. It's also even understandable given his position managing all of the Linux kernel and git development work, and the large number of people who contribute (or try to anyways...) If you don't want people to blow their damn leg off, don't give them a shotgun ( http://programmers.stackexchange.com/questions/92126/what-di... ). That said, this…

Totally agreed with your comment until that:

> as long as you have a disciplined team and sane coding guidelines

Is it not possible at all anymore to just hire people actually understanding what they are doing? Or cargo cult is here to stay?

I am sorry - please don't take that as a personal attack, but explaining people that C++ can actually be used in OS development by mindlessly sticking to some rules doesn't seem a way to me... but rather a counter-argument to what you said yourself.

Re: Thor – A minimalistic operating system in assembly and C++

#22
post #3

An OS in C++? But Linus said... http://harmful.cat-v.org/software/c++/linus

Does this actually use classes and other features of C++? Scanning a few files on Github I see namespaces being used but not much else.

Very impressive either way - I was just curious how C++ was leveraged.

Re: Thor – A minimalistic operating system in assembly and C++

#23

Earlier quoted context omitted.

As other's have stated, that is just Linus's opinion, which he is entitled to. It's also even understandable given his position managing all of the Linux kernel and git development work, and the large number of people who contribute (or try to anyways...) If you don't want people to blow their damn leg off, don't give them a shotgun ( http://programmers.stackexchange.com/questions/92126/what-di... ). That said, this…

Totally agreed with your comment until that: > as long as you have a disciplined team and sane coding guidelines Is it not possible at all anymore to just hire people actually understanding what they are doing? Or cargo cult is here to stay? I am sorry - please don't take that as a personal attack, but explaining people that C++ can actually be used in OS development by mindlessly sticking to some rules doesn't seem…

No No No! Don't apologize, its a great question! And to be fair I'm absolutely against "cargo cult" programming, and my point was actually that when you are doing C++ in this type of environment, you can't always stick to a hard set of rules or the conventional wisdom. When I say guidelines, I mean just that, and not a rigorous law you MUST adhere to.

As an example: When I was working on a project for a very constrained embedded device, we needed to get some extra man-power on our team for a few sprints to help out with some functionality. One of the pieces of our system was a "debug console" I had written that allowed some interactivity with the system over a serial port. The new guy was a very sharp engineer, but he typically worked on higher level stuff than we were doing. He wanted to add some functionality to the debug console, and dutifully started writing stuff in using the C++ string handling libraries. And consequently he blew our stack budget, and we ended up very quickly rewriting part of it together.

Now, the point is he wasn't doing anything using some crazy STL functionality or Boost, and he was doing the "right" thing by handling strings using the Standard Library functionality. What we had to do for our system was actually bend the conventional knowledge ("Don't write a string handling library yourself"), because we knew exactly what we needed, and exactly what resources we had.

So perhaps I could have phrased my point better. When I say "have a disciplined team and sane coding guidelines", I don't mean a team that codes by the book, I mean a team that knows what it is doing, and knows when the rules are meant to be bent. In our case sane coding guidelines meant we did things that were against the conventional wisdom, but they were sane, because they were justified in our case based on our engineering analysis. We were certainly open to breaking / changing these guidelines but it had to be justified. (And in fact our 'guidelines' were less a set of rules about how you needed to do every last detail, and more of a set of project specific "design patterns" and a large set of lessons learned in a shared wiki page which described issues we had run in to, and justified certain design decisions that were made)

(Edit: Other examples included disabling RTTI, and completely disabling and disallowing the usage of C++ exceptions to write our own error handling. Against the common advice to use what the language gives you, but made sense for our application)

Again, no need to apologize! I could have made my point clearer, and I hope I did, but please feel free to follow up with me! I'm always looking for ways to improve :-)

Re: Thor – A minimalistic operating system in assembly and C++

#24
post #2

Last week I read the very good 'How to build an operating system from scratch' [1], and I'm glad I did. It meant that I could burrow into the files on this github project and understand exactly what was going on. One day, when I finally have some free time, I am totally going to do this myself. --- [1] https://www.cs.bham.ac.uk/~exr/lectures/opsys/10_11/lectures...

Check out the broken thorn tutorials on the subject. They are far more complete.

Re: Thor – A minimalistic operating system in assembly and C++

#25

Earlier quoted context omitted.

As other's have stated, that is just Linus's opinion, which he is entitled to. It's also even understandable given his position managing all of the Linux kernel and git development work, and the large number of people who contribute (or try to anyways...) If you don't want people to blow their damn leg off, don't give them a shotgun ( http://programmers.stackexchange.com/questions/92126/what-di... ). That said, this…

Totally agreed with your comment until that: > as long as you have a disciplined team and sane coding guidelines Is it not possible at all anymore to just hire people actually understanding what they are doing? Or cargo cult is here to stay? I am sorry - please don't take that as a personal attack, but explaining people that C++ can actually be used in OS development by mindlessly sticking to some rules doesn't seem…

It's more that certain features can be way more expensive than they look.

e.g. say you're working on an embedded system, and you want a string, so you do:

    std::string s = "fnord";
At first it seems to work fine --- but you firmware image's RAM requirements have just gone up by 32kB, and a week later there's a crisis when adding another feature causes the system to stop linking because the RAM address space is full.

What happened is that std::string uses the heap to store the string data, so adding the line above caused the linker to pull in all the heap code and allocate a 32kB block of RAM to put the heap in. Because previously, the product wasn't using a heap: it was using static memory allocation throughout.

That example's contrived, but only a little. I've done the must-avoid-dynamic-memory-allocation dance many times in real life. (I've also discovered that printf() requires a raise() implementation on some platforms.)

A more realistic one is that embedded platforms typically have RTTI turned off, which means no exceptions, which means no throwing exceptions from constructors, which means two-phase construction throughout your program and you have to be really careful about which bits of the STL you use...

Re: Thor – A minimalistic operating system in assembly and C++

#26

Earlier quoted context omitted.

Totally agreed with your comment until that: > as long as you have a disciplined team and sane coding guidelines Is it not possible at all anymore to just hire people actually understanding what they are doing? Or cargo cult is here to stay? I am sorry - please don't take that as a personal attack, but explaining people that C++ can actually be used in OS development by mindlessly sticking to some rules doesn't seem…

No No No! Don't apologize, its a great question! And to be fair I'm absolutely against "cargo cult" programming, and my point was actually that when you are doing C++ in this type of environment, you can't always stick to a hard set of rules or the conventional wisdom. When I say guidelines, I mean just that, and not a rigorous law you MUST adhere to. As an example: When I was working on a project for a very constrai…

Thank you, I get your point. Re-reading it, and other comments here, I am getting reinforced in suspicion I already had for some time -- people don't do operating systems in C++ simply because they cannot hire big enough teams of C++ developers skillful enough to code in an OS environment.

Re: Thor – A minimalistic operating system in assembly and C++

#27
post #20

Earlier quoted context omitted.

'It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do nothing but keep the C++ programmers out, that in itself would be a huge reason to use C' Solid argument that. His two other arguments: - infinite amounts of pain when they don't work (and anybody who tel…

As long as you avoid "virtual", I can't even think of any C++ features which would lead you towards worse performance characteristics than C. Templates may bloat your binary size and increase compile times, but they're plenty fast.

There's also making unnecessary copies of things like strings and vectors passed to functions and exception overhead (in binary size at least)

Re: Thor – A minimalistic operating system in assembly and C++

#28
post #5
post #3

An OS in C++? But Linus said... http://harmful.cat-v.org/software/c++/linus

I agree 100% with Linus, especially the boost comment. It was heavily used in a project I worked on and "boost" soon became a curse word.

I don't agree with Linus, but yes, boost is horrible.

Re: Thor – A minimalistic operating system in assembly and C++

#29

Earlier quoted context omitted.

Totally agreed with your comment until that: > as long as you have a disciplined team and sane coding guidelines Is it not possible at all anymore to just hire people actually understanding what they are doing? Or cargo cult is here to stay? I am sorry - please don't take that as a personal attack, but explaining people that C++ can actually be used in OS development by mindlessly sticking to some rules doesn't seem…

No No No! Don't apologize, its a great question! And to be fair I'm absolutely against "cargo cult" programming, and my point was actually that when you are doing C++ in this type of environment, you can't always stick to a hard set of rules or the conventional wisdom. When I say guidelines, I mean just that, and not a rigorous law you MUST adhere to. As an example: When I was working on a project for a very constrai…

Ha. You posted this while I was writing my answer, and I see you (very nearly) used the exact same pair of examples that I did. This is possibly a hint as to where the pain points are...

(Your post is better than mine, though.)

Re: Thor – A minimalistic operating system in assembly and C++

#30
post #15
post #3

An OS in C++? But Linus said... http://harmful.cat-v.org/software/c++/linus

The problem with C++ is more about collaboration than with the language. It's harder to misuse C than C++. When you have a large group of people contributing, proper usage matters. Everything Linus rants about is improper usage.

On the other hand smart pointers (which I think didn't exist when linus wrote this?) and RAII make C++ harder to misuse than C.
Post reply on HN