6 ms·
It’s not just about writing code though. If you want to properly read code you have to understand all the “advanced” features they have used. I’m reasonably fa
by ratorx 5y ago
It’s not just about writing code though. If you want to properly read code you have to understand all the “advanced” features they have used.
I’m reasonably familiar with C++, but not so much with arcane template meta programs. I never write templates, but it still trips me up from time to time when I have to understand one.
- deleted 5y ago[deleted]
- rightbyte 5y agoI guess the messy ugly template headers could be hidden as compiler intrinsics, like in Go with its compiler blessed generics for standard containers. Or how C's printf is implemented as compiler magic instead of vardiac macros. The complexity needs to be somewhere in the end. A charitable view would be that Cpp's approuch is more ... inclusive?
- truncate 5y agoYeah. All the arcane template stuff, even if I understand for sometime, you're bound to forget it as soon as you stop using it (which you probably should in most times). It reminds me, every time I try to jump too implementation of some standard library method/class, it just seems like a completely different language to me. And C++ is the language I've most experience with. Meanwhile, I jump to some Rust or Golang* standard library implementation, it makes perfect sense very quickly. Even though I just use them for hobby projects. * Go is probably a bad example because it doesn't have any generics. But still love how much more approachable their stdlib code is.
- beached_whale 5y agoA lot of that is that you have to protect against name collisions. You have things like c macro's so methods need to be wrapped in brackets{e.g (min)( a, b ); } and also internal names need to be prefixed with an underscore and start with a capital (e.g _Foo) as that is reserved. The global namespace still exists so unqualified names that do not have a reserved id( eg _Foo ) cannot be used and need to be qualified (e.g ::std::(min)( a, b );). All this to protect against us. Some codebases are easier to read, I would rank them from libc++, MS STL, libstdc++ is readability. libstdc++ also seems to have code all over the place and use far more inheritance for composition of things.
- ncmncm 5y agoThere is no reason to use "arcane template meta programs" anymore. That is all old-C++ stuff needed to work around missing language and library features. It has been literally years since I coded or even (visibly) used any template meta program construct. That's not to say it doesn't exist in the implementation of the Standard Library. I just never have any need to see any of it.