Monday 21 September 2015

Bad naming

I'm facing a big refactoring job with game messages, but it's worse than that. I was a bit careless about naming some things and now it's going to give me some extra work.

What I have already changed was message.cpp (and .h) to gamemess.cpp. The reason behind this is that you should always name the source file as closely as possible to class name which here is Game_Message. What happened in this case is that I wanted to create an atomic class for messages, called Message. Yes, it would be confusing to use another file name for that class.

Much bigger problem is that I'm using a global instance of Game_Message called msg. Yet another big mistake, because now I want to create a namespace for message ids and it's going to be msg. Not only that, I'm using a function called Message in Game_Message which should have been overloaded version of Write rather than Message, because for one I need Message for the new class and it would look really stupid to write message->Message().

Or maybe it would be better to preserve Message as the internal function for messages in game object classes and give the class some other name, something like Message_Data? The new Message class is for pointers in message data, so when you use a message id the location of text is retrieved from that class instance which also contains alternative versions for messages.

No comments: