4 ms·
I write very C-ish C++17, that is, C + constexpr + a very restricted subset of templates (you can only use integral types as arguments). No template metaprogram
by gnulinux 8y ago
I write very C-ish C++17, that is, C + constexpr + a very restricted subset of templates (you can only use integral types as arguments). No template metaprogramming, ever. By extension you're also not allowed to use _Generic macro of the new C standard, if you absolutely absolutely must use it, then use C++ template. Metaprogramming with constexpr, static if etc is fair game. No class methods, just use C style POD with functions. You cannot use references (just pointers). You're not allowed to use any C++ library, but any C library is fair game.
This works really well in practice for us. We use GCC to compile.
- taneq 8y agoAfter a foray into C++-ish C++ I also write fairly C-ish C++. I see it as being like walking into an armoury and being able to choose anything you want. Chances are, if you want to resolve a domestic dispute, you don't want a claymore. Or a Howitzer. Or an aircraft carrier, or a lump of unshielded semi-critical plutonium. But that's OK, you don't have to choose them. You can walk right past those shelves to the shelf with the megaphone and the padded vest, and just take those. That's how you program with C++.
- blattimwind 8y ago> I see it as being like walking into an armoury and being able to choose anything you want. Chances are, if you want to resolve a domestic dispute, you don't want a claymore. Or a Howitzer. Or an aircraft carrier, or a lump of unshielded semi-critical plutonium. But that's OK, you don't have to choose them. You can walk right past those shelves to the shelf with the megaphone and the padded vest, and just take those. Is this an Ammu-Nation ad? :)
- taneq 8y agoMaybe my analogy would be clearer if I mentioned that half of the munitions in the stockpile were irrevocably pointed at my foot... but that which half is which is not clearly labeled and depends on subtleties of architecture and compiler. :)
- dman 8y agoIs the codebase publicly available?
- gnulinux 8y agoNo, unfortunately I'm not at liberty to share this code.
- thestoicattack 8y agoI was with you until "you cannot use references." Why not?
- muro 8y agoOnce you allow only pointers, you know if you see foo.bar, foo is a value on the stack. As a function parameter, you know that mutable calls with "." don't change state outside of the function. It reduces mental overhead.
- thestoicattack 8y agoThat's a good point. I use references, even with that mental overhead, because they're not nullable. Clearly there are trade-offs.
- muro 8y agoI think const ref is ok, but avoid non-const
- gnulinux 8y agoI have nothing particularly against references, especially since they look nicer with function pointers. But, you can do everything with pointers alone and if you open the gates of hell.. erm I mean C++ then there will be countless questions about lvalue references, rvalue references whether it's ok to use T&& whether it's ok to use std::forward, std::move etc... It's just simpler to stick to pointers.