6 ms·
> 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 ea
by tines 9y ago
> 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.
- ninkendo 9y agoMore 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.)
- wrinkl3 9y ago> 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.
- rrcaptain 9y agoIt's kind of a meme at this point though. Shitting on other people's favorite language is a well honored SWE tradition.
- littlestymaar 9y ago“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)
- Touche 9y ago> but in practice nobody cares. Not my observation at all.
- mickronome 9y agoPeople 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.
- temac 9y ago"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.
- pcwalton 9y agoHave you ever wanted to call .map() on an array? Or sort with a custom comparison function?
- SamReidHughes 9y agoSorting 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.
- deleted 9y ago[deleted]
- andrepd 9y agoThat'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/Template_Meta-Programming https://en.wikibooks.org/wiki/C%2B%2B_Programming/Templates/...
- yoklov 9y agoThat 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.
- tines 9y agoSorry, good point. But C++ gives you templates as well as template metaprogramming, so my point still stands.
- naasking 9y ago> 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-programminglinked-list/ http://www.roman10.net/2011/07/28/linux-kernel-programmingli...
- tines 9y agoThis isn't type safe though, namely this part: aPerson = list_entry(node, struct Person, list); while the templated way is.
- naasking 9y agoI'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.
- tines 9y agoThat’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.
- naasking 9y agoI'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.
- 9y ago