OK. I'm writing this from a self-driven hacking session which should last for as long as it can without interruption. I've got nothing better to do, and it's good practice for my Math 12 exam. I'm taking a break because my head hurts. So I thought I'd tell a little story which happened three hours ago, about how something went from crap to really good.
Anyways, I'm working on a 3D engine, and one of the bits are the vector typedefs. Formerly, they were defined as:
Well, there were a variety of fascinating problems that came out of that approach, mainly to do with the fact that I'm working in pure C, and C doesn't have a & operator for referential parameters or whatever they're called. So, I'm sitting on my chair, staring at my monitor, drinking "Tension Tamer" herbal tea, (Tranquilitea!), and thinking, "Holy smokes, what a pile of creepy crawlies I've created. How the heck do I deal with that?" In particular, there's a truly impressive phenomenon which will go down in history as "The 64 cell 4x4 matrix bug". I've got pointers flying all over the place, my code's a mess, my SDL Parachute has three big gashes in it, and I've spent two hours in GDB laying breakpoints and trying to figure out if I'd be better off developing a career as a screenwriter.
So, I log onto IRC while thinking about it, and a character by the name of Yorick suggests that I just use structs instead. You get better typecasting and functions can return them.
That would be nice, I think, except that I don't want to do something like:
So, I think... and I decide, "Why not do it this way?"
Then I start thinking again. A neat secondary advantage is that you can easily recognize which terms are matrix components and which terms are vector components in an equation. So if you've got something like this:
Now, at first I thought, "OK.... well, that'll fix THAT batch of problems... but how sucky!" Then I see how much easier everything gets. Sweet! No more worrying about pointers not typecasting correctly, stupid errors, and the amazing 64 cell 4x4 matrix bug. Then I see the fact that I can now easily recognize vectors, and that everything will become so much nicer from here-on in.
Now, that seems like a _REALLY_ little thing, right? So bloody trivial, you're asking "well, why bother?" Little details like this are important. I think this is easier to use -- it certainly let me clean up my own code and get it all working -- so it may even speed up productivity. It's nice to find the better way occasionally... especially for something trivial, like redefining a few simple typedefs. My thanks to Yorick for the excellent suggestion. (FWIW, he suggested that I go with v about thirty seconds after I thought "my what a good idea"!)
Don't even ask about the amazing 64 cell 4x4 matrix bug. I can only assume that it was a sign of the second coming.