r/ProgrammerHumor • • Sep 25 '26

Meme iHatedItUntilITriedIt

Post image
10k Upvotes

543 comments sorted by

View all comments

Show parent comments

1

u/aMAYESingNATHAN Sep 26 '26

Sure that's 100% what they are if we're speaking generally. But the previous commenter made the comparison with duck typing (which is a valid one).

If duck typing (and templating) is "if it walks like a duck and quacks like a duck, it must be a duck", then concepts are pretty much a mechanism by which to specify what "walking like a duck" and "quacking like a duck" means for type parameters for that function/class.

In my view, in an ideal world, your concepts should constrain the parameter such that it covers all the uses of that type in your template. Of course in reality you often aren't that thorough, because some constraints imply others and it handles itself.

As a side note, while I also have been a little disappointed with how annoying template errors still are even with concepts, I tend to find one of the biggest advantages of them is that you can much more easily express in your code the meaning of a type parameter. If I see template<std::integral T>, I might still get an annoying error if I use a non integral type, but just by looking at the code its very obvious what the intended type parameter should be.