Changed error handling to avoid exceptions
ClosedPublic

Authored by tbaumgart on Jan 7 2019, 6:42 PM.

Details

Summary

Throwing exceptions was not an elegant solution here. Returning an
invalid date and having errorCode and errorMessage methods to provide
information about the last conversion seems to be a better solution.

In the process, I also cleaned up the interface a bit and hide
implementation details behind a d-pointer.

Diff Detail

Repository
R471 Alkimia Library
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
tbaumgart requested review of this revision.Jan 7 2019, 6:42 PM
tbaumgart created this revision.
habacker added inline comments.Jan 7 2019, 7:54 PM
src/alkdateformat.cpp
110

This is unrelated, but should this code not used also for Qt >= 5.0 and < 5.8

428

Please use 4 spaces as indention

433–436

dito.

We already used kde-dev-scripts/uncrustify-kf5 to use a common format. Seems to be good time to rerun this script on master branch as a single commit and refresh this review with a crustified update.

src/alkdateformat.h
67–68

Why are you not using this

class Private;
Private *const d;

as already used by other classes ?

We should use the same style in all classes, either this, if it has advantages or what has been already used.

tbaumgart added inline comments.Jan 7 2019, 8:34 PM
src/alkdateformat.cpp
110

No, from the Qt documentation of QDateTime::fromSecsSinceEpoch

This function was introduced in Qt 5.8.

428

Ooops, these slipped through.

src/alkdateformat.h
67–68

It would not allow to use the Q_D macros but we can certainly change it if you want.

tbaumgart updated this revision to Diff 48916.Jan 7 2019, 8:36 PM
  • Fixed indentation where necessary
tbaumgart marked 3 inline comments as done.Jan 7 2019, 8:37 PM
habacker added inline comments.Jan 7 2019, 10:34 PM
src/alkdateformat.cpp
117

The Qt5 equivalent has been changed to

QDate convertStringKMyMoney(const QString& _in, bool _strict, unsigned _centurymidpoint)

without const. Please keep this method in sync.

src/alkdateformat.h
67–68

Using

AlkDateFormat::ErrorCode AlkDateFormat::lastError() const
{
   Q_D(const AlkDateFormat);
    return d->m_errorCode;
}

adds a redundant definition to each public method with additional runtime costs (casts) without any benefit, where is would be otherwise simply

AlkDateFormat::ErrorCode AlkDateFormat::lastError() const
{
    return d->m_errorCode;
}

Please use

class Private;
Private *const d;

habacker added inline comments.Jan 7 2019, 10:36 PM
src/alkdateformat.cpp
110

I see, thanks for this pointer. A related comment at this place explaining this would be nice.

tbaumgart updated this revision to Diff 48945.Jan 8 2019, 7:48 AM
  • Keep Qt4 signature in sync with Qt5 version
  • Don't use Qt style d-pointer logic
tbaumgart marked 2 inline comments as done.Jan 8 2019, 7:51 AM
tbaumgart added inline comments.
src/alkdateformat.h
67–68

with additional runtime costs (casts) without any benefit

You underestimate modern compilers/optimizers significantly:

0000000000000190 <_ZNK13AlkDateFormat9lastErrorEv>:
 190:   48 8b 07                mov    (%rdi),%rax
 193:   8b 40 08                mov    0x8(%rax),%eax
 196:   c3                      retq

I don't see any runtime overhead in here.

habacker accepted this revision.Jan 8 2019, 4:59 PM

I'm going to submit this with removed obsolete forward declaration

class AlkDateFormatPrivate;
src/alkdateformat.h
67–68

Indeed that looks good :-)

I looked at the macro, which looked not trivial

#define Q_DECLARE_PRIVATE(Class)\
    inline Class##Private* d_func() {\
        return reinterpret_cast<Class##Private*>(qGetPtrHelper(d_ptr));\
    }\
    inline const Class##Private d_func() const {\
        return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr));\
    }\
    friend class Class##Private;

The complexitivity of the Qt way is required to handle all needs from the huge Qt library including derived private classes, which I do not see here yet. If required, we can add this without much work to all classes probably by a gawk or sed script in future, so nothing is lost. :-)

This revision is now accepted and ready to land.Jan 8 2019, 4:59 PM
This revision was automatically updated to reflect the committed changes.