[Development] API style guide: scoped enum or not?

Volker Hilsheimer volker.hilsheimer at qt.io
Thu May 4 15:38:59 CEST 2023


> On 3 May 2023, at 18:40, Giuseppe D'Angelo via Development <development at qt-project.org> wrote:
>> But sometimes it’s also creating too much verbosity to use a scoped enum (ie. Qt::Orientation::Horizontal would perhaps not be an improvement).
> 
> I wouldn't consider this tiny bit of extra verbosity a huge impediment. Note that Qt::Horizontal is violating the API naming guidelines. It should've been called Qt::HorizontalOrientation. How is that now better than Qt::Orientation::Horizontal?
> 
> No, Qt::Horizontal isn't "unambiguous" so it can't be non-qualified. Does it refer to what? Text alignment? Text direction? Layout direction? (Hint: none of these.)


Some concepts are abstract enough to be ubiquitous. On/Off, true/false. Horizontal and Vertical are IMHO implicitly clear. What it refers to is not clear anyway unless you see the code that uses the enum. I can make a slider or a layout or a text horizontal or vertical, and it’s IMHO obvious what calls to

textLayout->setOrientation(Qt::Horizontal);
slider->setOrientation(Qt::Vertical);

are doing. The word “Orientation” in the enum itself adds no value.

Should we have Qt::TextLayout::Horizontal and Qt::Layout::Horizontal? Or QSlider::Orientation::Horizontal?

I do think that these are the exceptions though.


Cheers,
Volker



More information about the Development mailing list