single letter variable names
Quite a while back, I took up the task of exploring the Qt source code in order to explore the possibility of making a specific modification for the development team I am a part of. I didn't have the intention at the time of building Qt from source, as I was only exploring the code at that point, so I didn't bother setting up the Qt project in a proper IDE (just used notepad++). While doing this, one thing really got at my nerves; the use of single letter variable names for global variables. This, as I thought every semi-decent programmer knew, is very very bad practice (even for local variables). For one, they do not describe in any way what they do or what they're for, and second, for people using an editor that does not contain a "find all references/usages" option (like in my case), when you use one word variable names for global variables, it can be nearly impossible to find the usages via a normal search, which drives people trying to read the code insane.
Please, PLEASE, for the love of God and people reading your code, change the variables names to something more descriptive and searchable.
Hi and welcome to the (user) forums
Fully agree about singe letter variables, however, i have not really noticed any so
could you point to some examples ?
The specific one that got to me: https://code.woboq.org/qt5/qtbase/src/corelib/kernel/qobject.cpp.html#809
This line ?
d->threadData = (parent && !parent->thread()) ? parent->d_func()->threadData : QThreadData::current(
is it the d-> you mean ?
VRonin last edited by
What I think you are referring to are
qthat are not global variables but very well defined concepts described here: https://wiki.qt.io/D-Pointer
The Qt Style guide agrees with you and actually bans single letter variables unless they are obvious (for example
for(int i=0;is allowed): https://wiki.qt.io/Qt_Coding_Style#Declaring_variables
Yes it is mostly the d->.
I think this should be renamed to something that can be searched for. It seems quite important to how Qt operates, and I find it odd this wasn't given a name people can search to find all references of.
Well the d name is from the concept its based on.
It could be called _private or something like that but most do have an IDE to navigate so
im not sure it was considered.
Also , the code browser can show where its used.
But yes, it does hurt readability but its the price of trying to not
breaking binary compatibility between versions.
jon_rurka last edited by jon_rurka
Yea, that's fair. But I still think something could be done about it. A comment (wherever d is used) to show where this member is declared would be helpful to people reading the code who are curious what this object is.
people reading the code who are curious what this object is.
It's perfectly clear from the context - it's the private data of the class you're looking at. See https://wiki.qt.io/D-Pointer