I'm using C in a minimal, efficient OOP style to build a game engine. A problem I've begun to face as the engine code settles is my (erstwhile) choice to use this
. For example, I have:
void Engine_initialise(Engine * this);
void Window_terminate(Window * this);
Window * this
contains a reference to the singleton Engine
. Now, let's say I reference this Engine
member from both Engine_initialise(..)
and Window_terminate(..);
. In the former it will be this->member
, yet in the latter it will be (window->
)engine->member
.
This inconsistency annoys me; if it is the same, it should look the same. And as I work purely in a text editor without IDE, I want a single find-replace across all files, instead of multiple find-replaces.
Let's consider another example, where there isn't only one argument of the given type.
Blob_compare(Blob * this, Blob * that);
vs.
Blob_compare(Blob * blob, Blob * blobOther); //or blob1 and blob2, or whatever
...in spite of my preference for losing this
, the former looks better as it is descriptive and concise.
Question: Are there any particularly strong arguments for continuing to use this
as the name of current object instance in my various functions? I'm thinking of replacing all this
with engine
(or similar). I would like to settle on a coding standard in this regard, for all C code.
I am asking about the usefulness of this
as the primary function argument; the names of other parameters of similar type are not of major importance here in spite of my second example. To me it seems sensible, if the function is prefixed with Blob_
, to assume that blob
refers to the current instance. And no, I really don't care one iota about renaming types - these are well fixed.
FILE *file
in the prototype to make it clear how to use your functions.