C++ Generics – How Often is Generic Programming Used in Industry

cgenericsobject-oriented

I do programming in an academic setting at the moment, so I can use whatever I want. I'm using the boost graph library for a few things, and I'm wondering whether investing effort in understanding GP more deeply is worth it.

I'm curious – is generic programming (GP) used much in industry? My guess is that most programmers are much more comfortable with OOP or are using languages that don't emphasize or support GP, so that outside of calling STL data structures/functions in C++, my impression is that GP isn't used all that frequently in practice. But, being outside industry at the moment, it'd be nice to hear from practitioners on this.

(as I'm writing this, I see that generic-programming isn't even a valid tag!)

Best Answer

I'm curious - is generic programming (GP) used much in industry?

It's really widely dependent on the context of the team and the project.

For example, in video games, often the code is the "simplest" possible (and even sometimes too simple) but in large architectures. That's because game developers have a lot of problems to fix and don't want to bother with meta programming (that is a separate very abstract and hard to grasp language inside C++).

At the same time, basic usage of templates are common even in those shops and you can see some template-based optimizations in some very specific functions of some engines.

But in game dev, most people will just avoid any metaprogramming.

Now, on the other extreme side, some really complex or heavy processing applications, that are not common, requires some kind of heavy metaprogramming because of performance and flexibility (at compile time) requirements that are not common. I'm working in one right now.

It's not common but it exists and some niche domains (in some scientific or number-crunching embedded contexts) does require people knowing a lot about metaprogramming or wishing to learn.

In the middle, most people will just use meta-proggramming as "client", not as "designer". Most meta-programming code are bundled in libraries because libraries are tools for code and what is better than a library that can adapt to the custom types you've been working with until now?

Boost (http://boost.org) is a set of libraries, some being made of heavy metaprogramming black magic, and are used in a lot of C++ shops as "STL++", an extension of the STL (and it is). Not every shop does use it for several reason, like compiler compatibility (some boost libraries can make your compiler beg pardon for every time he did hurt your feeling...) and more often because some developers don't like not being able to understand how a tool works inside (try to understand Boost.Spirit...)

Whatever the companies you will work for, some will use this paradigm, some will less or not at all or even forbid them.

There is no consensus because nobody have the same needs, context or team.

But still, obviously, it is used. Maybe ask who use boost on their mailing list to have more real-world examples?

Related Topic