| ▲ | randusername 2 hours ago | |
> Although there is an opinion that templates are dangerous because of executable code bloating, I think that templates are developer’s friends, but the one must know the dangers and know how to use templates effectively. But again, it requires time and effort to get to know how to do it right. idk man, obviously I don't know much since I don't have my own online book, but templates would not be at the start of my list when selling C++ for bare-metal. unit suffixes, namespaces, RAII, constexpr, OOP (interfaces mostly), and I like a lot of the STL in avoiding inscrutable "raw loops". I like the idea of templates, but it feels like a different and specialized skillset. If you are considering C++ from C, why not ease into it? | ||
| ▲ | lkjdsklf 32 minutes ago | parent | next [-] | |
Templates don’t have to be complicated. Just very basic type substitution is one of the most useful uses of templates and is useful in pretty much all software They’re also useful when you can’t use virtual dispatch. Concepts help a lot in making that tolerable. Sure they can get stupid complicated and ugly as hell, but you don’t have to do that. Even their basic form is very useful That said, RAII is probably the must useful thing | ||
| ▲ | bluGill 2 hours ago | parent | prev [-] | |
Most of the good parts of the STL are implemented as templates. If you are considering C++ from C, then treating it like C with the STL templates is a great first step. Over time you will discover other useful features of C++ that solve specific problems. Virtual functions in a class - better than writing a table of function pointers. Lambda - sometimes much better than a function pointer. Custom templates - better than doing the same thing in macros (at least some times). Exceptions are sometimes really nice for error handling (and contrary to popular belief are not slow) And so on - C++ has a lot of features that can be useful, but most of them are features that can also be abused in places they don't belong creating a real problem. | ||