[Development] Qt API review with clazy

Ch'Gans chgans at gna.org
Mon Sep 12 09:26:54 CEST 2016


On 12 September 2016 at 19:06, Mathias Hasselmann
<mathias at taschenorakel.de> wrote:
> Just that the approach of clang-tidy is fundamentally wrong:

Hi Mathias,

No offense, but you arguments are fundamentally wrong too. Your
workflow is not everyone's workflow!

>
> You simply don't do static checks as a after thought, at random times when
> sun, mars and moon are in proper constellation.

I don't see the problem, people are free to choose if, when and which
checks they fancy run.

> Why? Because when running this checks occasionally too much cruft will have
> accumulated that it is worth and reasonable to fix those issues: Too big
> chunk of boring and still expensive work. Too big risk to introduce
> regressions.

Running clang-tidy is way slower than compiling code, a nightly check
might be enough (or not, again this is a personal choice), or you
could decide to run the checks systematically on pull requests because
you don't trust the authors (for whatever reason, inc the usual "oops,
forgot to do that", human do errors).

> You really want to make this checks part of your daily development
> experience, you want the compiler to tell you about your mistakes as soon as
> you compile that code for the first time. It's much easier to fix your
> mistakes if you just wrote them. It's much safer to fix them before even
> doing the first tests. Well, and you'll learn much earlier about possible
> anti-patterns, so you'll write less of such code.

Maybe, but again, this is a personal choice based on personal usage of
the said tool.

> I hear you saying "but you could add clang-tidy" to your build scripts, but
> that's not a valid argument adding the following flags is considered too
> much effort already:
>
>   -Xclang -load -Xclang ClangLazy.so -Xclang -add-plugin -Xclang clang-lazy

This has nothing to do with clang-tidy, this is how you would use
Sergio's *clang plugin*.
Clang tidy is a separate tool that you can run externally once you
have extracted the compilation database from your project. clang-tidy
doesn't compile anything, it just run sanity checks, period.

Sanity checks ran by clang-tidy can be of arbitrary complexity, and as
such can take really long time. You might not want to be slow down by
this while you're actively developing.
If you go this way, then why don't you always run your applications in
profiling mode to make sure you don't introduce bottle-necks or memory
leaks "as-you-go"? Well we all know the answer: Because it is way too
slow.

Chris.

> Thanks,
> Mathias
>
> Disclaimer: I am working with Sergio and using his awesome plugin since its
> very first days.
>
>
> Am 12.09.2016 um 08:38 schrieb Ch'Gans:
>>
>> On 12 September 2016 at 10:34, Sergio Martins <sergio.martins at kdab.com>
>> wrote:
>>>
>>> On Sunday, 11 September 2016 21:43:46 WEST Jérémie Delaitre wrote:
>>>>
>>>> Can the same checks be implemented in clang-tidy instead of having yet
>>>> another tool? clang-tidy now has boost specific checks so maybe they
>>>> would
>>>> also accept a Qt specific module in there.
>>>
>>>
>>> I haven't been able to use clang-tidy on big qmake projects such as Qt,
>>> it
>>> either crashes or stops with "include not found" errors. It also requires
>>> an
>>> intermediate step, where you generate a "compiler command database" file
>>> with
>>> yet another tool [1]
>>
>>
>> Both CMake (since 2.8.5, see [1]) and Qbs (master branch) can generate
>> this "compiler command database".
>> Maybe your tool could be made to work with this DB (via clang-tidy)
>> and as a clang plugin.
>> The DB approach has the added advantage that it doesn't require
>> modifying CXX flags, which can be a problem on projects that have
>> "buggy" build files.
>> Having your checks run by clang-tidy would also definitely widen your user
>> base.
>> clang-tidy have specific rules for LLVM, boost, google, ... Would be
>> nice to add Qt.
>>
>> Chris
>>
>> [1]
>> http://clang.llvm.org/docs/JSONCompilationDatabase.html#supported-systems
>>
>>> clazy, otoh, is a compiler plugin, it integrates with your normal
>>> compilation
>>> run, you don't have to run any more tools after doing "make" as you
>>> usually
>>> do.
>>>
>>> Enabling clazy is just a matter of modifying your CXX flags,  which you
>>> can
>>> easily do with qmake or mkspec. Or ENABLE_CLAZY in CMake if you're
>>> building
>>> KDE.
>>>
>>>
>>> [1] https://github.com/rizsotto/Bear
>>>
>>> Regards,
>>> --
>>> Sérgio Martins | sergio.martins at kdab.com | Senior Software Engineer
>>> Klarälvdalens Datakonsult AB, a KDAB Group company
>>> Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
>>> KDAB - The Qt Experts
>>> _______________________________________________
>>> Development mailing list
>>> Development at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/development
>>
>> _______________________________________________
>> Development mailing list
>> Development at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/development
>>
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development



More information about the Development mailing list