Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Agreed. I honestly thought C++ templates were just a convenient meh before reading this thing. Insane.
For beginners, a quick introduction to compile time computation (just one of the things C++ templates allow) would be this: https://monoinfinito.wordpress.com/... -
klonky2577yTo everyone including those that never touched c++.. This is the stuff, the homedinger of 🍯 dripping gold paved streets.. Anyone who think of themselves as a programmer should read this just for fun. Overselling it slightly?
-
@SHA-16384
I dont have much experience in any other languages exept C++ yet, so I can't help you with that :/
The concept that this book builds on is that of generic programming. It is basically a way of programming your compiler to generate code for you. In C++ you can define "templates" for classes or functions which take types as arguments. You write these templates just like you would write an actual class, only that a template can have fields of an undefined/variable type.
Only once you want to use a templated class in your code you define what types it should use and the compiler will generate the actual class/function by inserting the type you provided.
This means that you can write the "same" class for all the types you will ever need. And while this might sound only barely useful, it is really suprising how easily you can write extremely flexible, expandable and yet efficient code. -
@SHA-16384
But what this book is actually getting at is the idea of policy based design, where you basically construct completely different classes on the fly by providing policies to a host class template. The policies are just classes which define functions and structures and by passing these to the host class template, you construct a completely new class just like that. It is maybe a bit like inheritance, only a lot less limited and also, it is all evaluated at compile time, which means most errors will be caught there.
I hope I did not just write a bunch of rubbish, I have just started with the book, but the first 10 pages already got me excited about all the new possibilities. It really blew my mind. -
World29687y@stimulate Studied C++ and templates last sem. Didn't know about the book. Thanks for the review. And the mention.
-
If you like this book, see the last Herb Sutter talk in cppcon 2017. It was the most amazing thing I see since constexpr
Related Rants
-
xjose97x19Just saw a variable in C named like this: long time_ago; //in a galaxy far away I laughed no stop.
-
Unskipp24So this happened last night... Gf: my favorite bra is not fitting me anymore Me: get a new one ? Gf: but it ...
-
sam966911Hats off to this lady .... I would have just flipped the machine
To all the C++ programmers who haven't read "Modern C++ Design" by Andrei Alexandrescu yet, READ IT! Its great. To me, it opened up an entirely new approach to designing classes with a whole new dimension of possibilities. And it reads really well! Sometimes I got shivers because the code was so sexy 😅😂😂
undefined
generic programming
c++
policy based design