I’ve seen some discussions lately on the web about POD types in C++. These are classes without complicated constructors, assignment operators, etc and are extremely useful for defining things like vectors (float vectors, not the standard library list).
Trouble is, in games your expert programmer will define the vector in the most efficient POD way and everything will run well. That is until someone less obsessed with the low-level details of C++ comes along, flips to the appropriate page of their object oriented programming book, and adds a complex constructor to the class. Everything will continue to work but there’s a very good chance that programmer just wreaked havoc on the frame-rate.
So, here’s what i’m proposing. I want an attribute, just like the __attribute__ extension GCC already has which says “this is a POD class so don’t let anyone add anything to it that stops it being POD”. Note, i don’t want the attribute to make the class POD, its already POD by design. I want the attribute to enforce that property to stop anyone doing anything unwanted thats allowed by the language, but will make the engine gurus angry.
Anyway, just an idea, but one that I think could really be valuable. I’ve also been thinking that a command line option to ban calling virtual functions or malloc from an __attribute__((hot)) function would be nice, or maybe a new attribute that means “so hot you can’t call virtuals from in here”.
Also, just realised the POD attribute isn’t strictly necessary as you could define a union containing an element of the class and comment next to it to say that the union is guaranteeing the POD-ness of the class, but I still like the idea of having more attributes to control allowed code (and give error messages when the rules are broken), and not just hint things to the compiler as most current attributes do.