12

Qt makes heavy use of the PIMPL idiom in their development process: https://wiki.qt.io/D-Pointer

As I've read here: "The name 'd-pointer' stems from Trolltech's Arnt Gulbrandsen, who first introduced the technique into Qt, making it one of the first C++ GUI libraries to maintain binary compatibility even between bigger release.". But nobody says what "D" stands for.

So what does the "D" stand for in D-Pointer?

463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185
Jacob Krieg
  • 2,834
  • 15
  • 68
  • 140
  • 1
    I believe "d" stands for "data", as d-pointer points to a structure that stores all the class' data. In other words, it's a "data-pointer". – vahancho Oct 23 '19 at 10:09
  • 1
    I've never seen a statement anywhere in Qt's documentation, but I've always thought about it in terms of d = data. More generally, a d-pointer is Qt's usage of the pimpl design pattern i.e. it's an opaque pointer. You could always view it as an upside-down p (where p is for pimpl). – Peter Oct 23 '19 at 10:23

2 Answers2

14

From this page Data Sharing with Class (an old docs from QT), it says:

Before we can share an object's private data, we must separate its interface from the private data using an idiom called "d-pointer" (data pointer)

So, d-pointer means data-pointer

Amadeus
  • 10,199
  • 3
  • 25
  • 31
8

I'll add my own answer, since I remember the day it happened.

I was trying to extend something while maintaining binary compatibility, and noticed that there was a pointer called 'data' that I could reuse for a different purpose. So I made a private class for implementation-related data (a pimpl), put both the old data and my new data there, and since the existing name seemed to fit I kept the name.

I abbreviated it from data to d after a short meeting later on the same day, where we agreed that the pattern I'd invented stumbled upon was good and we should use it widely, and that d-> was short enough and unique enough to be used everwhere as a mark of implementation-specific fields.

At the same meeting, we decided to put implementation-specific data in d-> as a matter of policy from then on, mostly in order to keep the number of includes down, but also to keep the declared API clean in general. Fewer private variables in the class declaration means few opportunities for error, fewer temptations, fewer things that can conflict with subclass naming and so on. Better hygiene.

arnt
  • 8,949
  • 5
  • 24
  • 32
  • Are you talking about the Qt API or some other project you were working on? :) – Jacob Krieg Jun 02 '21 at 06:21
  • 3
    About Qt, of course. That's the source of the term "d pointer". Other people did similar things, but used other names, mostly "pimpl". – arnt Jun 05 '21 at 22:46
  • 1
    Probably the answer from who is the inventor of such thing should be on top! Ignorant will read the first answer and does not look at who is answering the question. Thank you Arnt for ```d_ptr``` :) @arnt – Soheil Armin Oct 20 '21 at 06:36
  • @arnt Can you also explain what the "q" in q-pointer stands for? (And thank you so much for shedding light on these puzzling identifier names!) – ʇsәɹoɈ Jan 22 '23 at 22:02
  • The [QPointer](https://doc.qt.io/qt-6/qpointer.html) class exists because it's quite common to have code where you know/decide object lifetimes and can use ordinary pointers for almost everything, but there's one exception, one kind of object that has other deallocation rules than the rest of your program: Someone else decides when to close windows. So Qt offers a special class that you can use to point to the kinds of objects that go away when a window goes away. – arnt Jan 23 '23 at 09:03
  • Programmers have been complaining that users close windows at unforeseen times ever since the GUI was invented. With some toolkits that leads to dangling pointers, with others it leads to much of a muchness. Say calling window->getHeight() throws an exception if the window has been closed, how different is that from having a dangling pointer? – arnt Jan 23 '23 at 09:08
  • I am referring not to the QPointer class, but to the [q-pointer](https://wiki.qt.io/D-Pointer#The_q-pointer) as accessed via `Q_Q()` and `q_func()` within the private implementation of Qt classes. I understand that it is the d-pointer's complement, for accessing the public side from the private side, but I don't know what the "q" in "q-pointer" stands for. – ʇsәɹoɈ Jan 23 '23 at 22:46
  • Well, I suppose this illustrates why one shouldn't ask questions in comments. Ask a new question instead, that gives you the room to ask precisely the question you intend. – arnt Jan 24 '23 at 18:19
  • I think I did ask precisely, and did so in a comment because it's a very closely related follow-up to the main question here. The d-pointer and q-pointer are mirrors of each other, after all. Sorry if I've bothered you. – ʇsәɹoɈ Jan 25 '23 at 01:08