100DaysOfGameDev: Day 34

or may I say

template<typename D, class Topic, typename V>
#DDaysOfTopic: Day V

Today, I started on the painful adventures of templates, or generics if you have a Java background. Usually, I have a rate of 20 pages per hour while reading this book; today it dropped to 8 pages. There can be two reasons: first I am tired and need sleep, second, this topic is absolute bottom/back/behind/insert the vulgar word here. It has always been one of the topics, that confused me the most. However, I have to give them credit that it sucks less, than the Java implementation, because the latter one was absolutely horrible and confusing. Yes, I am talking about erasure. On the other hand, I can see the way it can optimize generated code for higher performance and stuff. Fortunately ( or not ) I am not a AAA company yet, so I won't make heavy use of that. Nevertheless, I should quit ranting and talk about the content. Basically, templates are heavily used for the design of standard library facilities in C++, where it makes the most sense to apply. For readers, who are not familiar with its concept, it allows to reuse of the same piece of code for different types. That is if my soap can clean a face, then I can say soap and re-use the same soap to wash my insert the vulgar word here like so soap. Since there are many body parts, I do not want to define soap for each one like class FaceSoap, class TorsoSoap, class LegSoap, but I can have only one #template<typename T>class Soap; and just use that. It is also compile-time safe. That means no information will be lost if you decide to use certain soap only for your butt and then accidentally use it for your face and regret it later, the compiler will warn you in advance that you intended to only use it for your private ( or so private ) part. That's the simple concept behind it, however, I do not have much processing power to explain it further now, so thank you for passing by, and see you tomorrow!