KColorScheme - additional (convenience) ctors

Matthew Woehlke mw_triad at users.sourceforge.net
Tue Sep 4 16:57:31 BST 2007


Simon Hausmann wrote:
> On Sunday 02 September 2007 20:06:12 Matthew Woehlke wrote:
>> Simon Hausmann wrote:
>>> I suggest to change the signature of the constructor that takes a const
>>> QWidget & to take a const QWidget *. Nobody passes around QWidget
>>> references, so everyone using this constructor has to dereference the
>>> widget to pass for no good reason IMHO.
>> Thanks for the feedback. I thought about that also, the problem is that
>> passing a NULL reference is not valid. By requiring a reference rather
>> than a pointer, this makes it explicitly clear that you must pass in a
>> real object. Otherwise, the ctor has to either throw an exception or
>> abort(), neither of which it currently does.
>>
>> So I guess my preference is to make people type an extra '*' (and to
>> force them to stop and think about what they're doing, which they need
>> to be doing either way). But I'm willing to reconsider. Which evil is
>> lesser?
> 
> I don't think you gain any readability from requiring people to write the *. 
> It just seems inconsistent to me. QLayout::addWidget takes a QWidget pointer, 
> too, even though it doesn't make sense to pass a null pointer to it.

Yes, dfaure convinced me on IRC that abort() (i.e. Q_ASSERT in debug, 
otherwise actually just causing a SEGV) is better. But see my reply to 
winterz.

-- 
Matthew
When in doubt, duct tape!





More information about the kde-core-devel mailing list