[Development] Improving toInt, toLong, etc.

Robert Knight robertknight at gmail.com
Fri Feb 7 11:35:14 CET 2014


> Returning default-constructed value is heavily used practice in qt api and it simplifies our code.

It is often convenient, but he problem is that an error can propagate
a long way from the source before it gets discovered, which makes
debugging difficult, especially if the error gets propagated to
persistent storage or other systems.

The proposed solution to Q_ASSERT() in debug builds partially
addresses this. I suspect that for a lot of actual uses the overhead
is low enough that such checks could be left enabled in release builds
as well. That might be a separate discussion though.

Regards,
Rob.


On 7 February 2014 09:51, Branislav Katreniak <katreniak at gmail.com> wrote:
>> > The idea was to silently return a default-constructed type.
>>
>> I'm not keen on that. Aside from adding extra restrictions to the
>> types that the class can be used with as you mention,
>> it runs the much more severe risk of masking serious bugs.
>
>
> Returning default-constructed value is heavily used practice in qt api and
> it simplifies our code. We (try to) design our code such that
> default-constructed value means safe default / failure.
>
> Kind regards
>  Brano
>
>



More information about the Development mailing list