News for hackers. Stuff that matters.
Re:Fuchsia is not Linux by tines on Wednesday April 11, 2018 @06:38PM (#16816387)
> You shouldn't need dispatching or template metaprogramming in a microkernel, as code reuse is minimal since all primitives are supposed to be orthogonal to each other.

Orthogonality doesn’t obviate the need for metaprogramming though. For example, there are lots of places you might need a linked list structure, where the nodes store different types. You might use templates over intrusive structures to gain some type safety without duplicating code for each contained type.

Re:Fuchsia is not Linux by andrepd on Wednesday April 11, 2018 @07:14PM (#16816650)
That's not what template metaprogramming means. That's just plain generic programing, with templates. TMP is this: https://en.wikibooks.org/wiki/C%2B%2B_Programming/Templates/...
Re:Fuchsia is not Linux by yoklov on Wednesday April 11, 2018 @08:11PM (#16816965)
That doesn't really seem super relevant, given that the parent comment seems to have been using template metaprogramming in the same way -- to just mean any template code.
Re:Fuchsia is not Linux by tines on Wednesday April 11, 2018 @10:28PM (#16817517)
Sorry, good point. But C++ gives you templates as well as template metaprogramming, so my point still stands.
Re:Fuchsia is not Linux by naasking on Wednesday April 11, 2018 @09:20PM (#16817282)
> For example, there are lots of places you might need a linked list structure, where the nodes store different types.

Sure, but linked lists have solutions already using simple macros [1]. There aren't many sophisticated kernel data structures, mainly tables for indexing and linked lists, all of which have simple expressions as macros. Templates perhaps make this a little easier, but are overkill.

[1] http://www.roman10.net/2011/07/28/linux-kernel-programmingli...

Re:Fuchsia is not Linux by tines on Wednesday April 11, 2018 @11:04PM (#16817666)
This isn't type safe though, namely this part:

   aPerson = list_entry(node, struct Person, list);
while the templated way is.
Re:Fuchsia is not Linux by naasking on Wednesday April 11, 2018 @11:17PM (#16817713)
I'm not sure why that's problematic. It's a simple 1-liner that can be audited manually and reused arbitrarily. If you add it up, the TCB is actually less than relying on the complex template elaborator.
Re:Fuchsia is not Linux by tines on Wednesday April 11, 2018 @11:46PM (#16817811)
That’s the thing - it has to be audited manually. I’m sure I won’t convince you here of the value of static typing but some people think it is.
Re:Fuchsia is not Linux by naasking on Thursday April 12, 2018 @12:38AM (#16818023)
I'm a big static typing fan. That's not particularly relevant to this security consideration though, the TCB is the biggest factor. The C++ compiler and toolchain are a far larger TCB than the C toolchain and this one liner. As long as this reuse problem isn't a persistent pattern in a kernel, then the unsafety is less of a problem than introducing the larger TCB.
Re:Fuchsia is not Linux by tines on Thursday April 12, 2018 @06:55PM (#16825704)
Sorry, I’m not familiar with what a TCB is, and google isn’t being helpful. do you have a link I could read?
Re:Fuchsia is not Linux by adrianN on Thursday April 12, 2018 @12:41AM (#16818039)
People make mistakes, even with simple one liners. Type checkers don't. Running the compiler is also a lot cheaper than having someone inspect every line of code carefully.
Re:Fuchsia is not Linux by naasking on Thursday April 12, 2018 @09:03AM (#16820442)
> Type checkers don't.

Sure they do, unless your type checker is formally verified. Are you suggesting there exists a formally verified C++ compiler?

> Running the compiler is also a lot cheaper than having someone inspect every line of code carefully.

Except that's not what I suggested. You only need to audit lines that perform potentially undefined behaviour. The C type checker ensures the rest are fine. I think it's clear this problem is worse in C++ given all of the additional abstractions that interact in surprising ways.

Furthermore, C++ has no formal verification tools, so if you wanted real guarantees, you'd use something like Frama-C or a theorem prover like they did with seL4. Microkernels in C++ have been tried, and in every case they switched back to C for very good reasons.

Re:Fuchsia is not Linux by adrianN on Thursday April 12, 2018 @03:30PM (#16824140)
Are you suggesting that the error rate of type checkers, verified or not, is even in the same ballpark as the error rate of human reviewers?

If I care so much about system correctness that I do the insane amount of work that is formal verification (just look at how many man years sel4 consumed!), I don't write C or C++ at all, I use Spark. There is a reason why you can count the number of formally verified kernels on the fingers of one hand, and it's not because everybody tries to use C++ instead of C.

Re:Fuchsia is not Linux by naasking on Friday April 13, 2018 @10:06AM (#16830081)
> Are you suggesting that the error rate of type checkers, verified or not, is even in the same ballpark as the error rate of human reviewers?

Nope, but your unqualified statement was simply false, and in any case, your point isn't really relevant. This single line of code we're discussing is easily verifiable by manual inspection and automated testing. We're not talking about huge swaths of code here, we're talking about a few unsafe primitives, because this kind of reuse isn't typical of a microkernel.

The type safety of a single operation expressed as a template is relatively insignificant compared to the added complexity of C++, particularly considering the "reuse" benefits are non-existent for microkernels, and if all you're left with is some elusive "type safety" for a linked list, that's simply not enough.

This is obvious when you know the history of multiple C++ kernel verification efforts, all of which failed, no matter how simple of a C++ subset was chosen. Many C verification efforts have succeeded, and tools for lightweight formal methods, like Frama-C, make the transition to verification possible with C. C++ is a dead end for this purpose, and the various L4 groups that created L4 kernels in C++ and then rewrote them in C all agree.

Re:Fuchsia is not Linux by ninkendo on Wednesday April 11, 2018 @07:03PM (#16816581)
More evidence IMO that when people think they need template metaprogramming, what they probably really need is basic collections primitives. Go is a good example of this. (Strings, maps, lists, slices are just done once by the language, you don't get to write your own implementation because there's no generics, but in practice nobody cares.)
Re:Fuchsia is not Linux by wrinkl3 on Wednesday April 11, 2018 @07:14PM (#16816649)
> but in practice nobody cares

I haven't worked with Go personally, but "no generics" is probably the most commonly vocal complaint I hear about it, so clearly some people do care.

Re:Fuchsia is not Linux by rrcaptain on Thursday April 12, 2018 @02:19AM (#16818452)
It's kind of a meme at this point though. Shitting on other people's favorite language is a well honored SWE tradition.
Re:Fuchsia is not Linux by littlestymaar on Thursday April 12, 2018 @03:40AM (#16818767)
“lol no generics” is the meme. But the lack of generics is a real problem that bothers a lot of people (and several already developed their own solution to work around this problem)
Re:Fuchsia is not Linux by mickronome on Wednesday April 11, 2018 @08:01PM (#16816908)
People actually do care a lot about the fact that you can't have type safe and thread safe code, or abstractions without tons of synchronization code repeated ad nauseum throughout the code.

Multiply that by 10 if you have several junior team members who have been told, and read, that concurrency and parallelism is easy in go.

Re:Fuchsia is not Linux by temac on Wednesday April 11, 2018 @08:38PM (#16817084)
"nobody" is a little strong.

Advanced users might want to use advanced data structures that are not built-in in the langage, and templates can be convenient to do that.

Re:Fuchsia is not Linux by pcwalton on Wednesday April 11, 2018 @08:42PM (#16817101)
Have you ever wanted to call .map() on an array? Or sort with a custom comparison function?
Re:Fuchsia is not Linux by SamReidHughes on Wednesday April 11, 2018 @09:13PM (#16817250)
Sorting you can do -- the function takes indices. And no, I've never wanted to call .map() -- I love writing for loops over and over, it feels really productive.
Re:Fuchsia is not Linux by Touche on Wednesday April 11, 2018 @07:21PM (#16816698)
> but in practice nobody cares.

Not my observation at all.