Replies: 12 comments
-
Gonna recommend clang static analysis tools. They tend to be pretty amazing. And on dynamic analysis, the clang Sanitizers (address sanitizer, memory sanitizer, ubsantizer) are pretty amazing. They're not like valgrind (in the sense that valgrind is basically a VM). They work by compiling your code with some dynamic checks added, and seeing if while running, your memory/pointers/etc raises any flags. edit: oh heck I didn't see the first comment. I might've been too early. Sorry about that! Gonna read it and maybe write more tomorrow (I'm again, awake at some ungodly hours...) |
Beta Was this translation helpful? Give feedback.
-
I see you've left a comment there on Mutation Testing. I've been following the work on Mull for years, and the two guys making it are pretty legit and have shown some seriously cool results. It is C++, and therefore it basically works out of the box for C and Cpp :3 |
Beta Was this translation helpful? Give feedback.
-
I super agree. Both making the rules explicit in the "contributing" documentation or whatever, and making CI check for formatting and e.g. code coverage or a mutation testing score, is work off from everyone's shoulders that will definitely show results in just a couple of months of usage. I think making this explicit and/or automatic is a fantastic idea :) |
Beta Was this translation helpful? Give feedback.
-
Having had that enforced before, I would argue against it. It tends to mean documenting meaningless functions (see the below fictive example) and reduces the value of the other important documentation. /// Moves the user to the provided channel
///
/// @arg{user} the user to move
/// @arg{channel} the channel to move the user into
bool moveUserToChannel(User user, Channel targetChannel) {
// ...
} It is great to document public API, but full coverage implies wasted time on meaningless documentation in my experience. Other than that, I completetly agree with enforcing code guideline with tools and automated. Great idea! |
Beta Was this translation helpful? Give feedback.
-
I like the idea of using the smart pointer! One notorious thing that keeps many developers away from C/C++ is manual memory management. Modernizing this part would make our life much easier :D. And as for the coding guidelines, I believe this is absolutely necessary. During my primitive journey of contributing to mumble, I discovered that the codebase is in a variety of styles and sometimes it is hard to know what kind of style I should stick with. Fortunately, in my previous commits, @Krzmbrzl was willing to help me check my coding style and provide helpful instructions to make things neat. (Big thanks to him ^^) However, the current diversity of coding styles of our codebase makes new contributors hard to follow a new style immediately, by simply inferring from old code. Therefore, to enforce a new style and a set of rules, we must make sure all old files are rewritten in accordance with the guidelines. It would be rather frustrating to be asked to fix the coding style when one is just trying to keep his code in line with the old code. I think we need to have a plan for this :). However, personally I always welcome the mumble team to provide any kind of feedback on my PRs, and I'm always happy to make mumble neater and cleaner. And thank you guys again for developing such a good app and the support you have provided! |
Beta Was this translation helpful? Give feedback.
-
I see your point. However I think the approach of documenting "where appropriate" has several drawbacks as well (imo):
What I also thought about though, would be to lift the restrictions a bit in order to force documentation on all non-private functions. That way you could get away by not documenting some internal helper function in your class. I think this kind of rule could also still be verified automatically (although it probably takes quite a bit more effort to do so). |
Beta Was this translation helpful? Give feedback.
-
I mostly like the proposed guidelines, especially the smart pointer thing and clearly indicating what function takes ownership. However when a function does not take ownership, references should be preferred over raw pointers (if possible), as they guarantee to be not nullptr. Are there any plans to move to a more modern C++ standard? Qt 6 is around the corner and will require C++17, so I would propose going the same direction. |
Beta Was this translation helpful? Give feedback.
-
Yeah absolutely. My statement about that was intended to be read as "if a pointer is required, use smart pointers if the function should take ownership and raw pointers otherwise". If however a reference can work as well, go with that 👍
Yes we will almost certainly use cpp17. |
Beta Was this translation helpful? Give feedback.
-
@bendem @magnus-gross @Johni0702 do you have an idea how to overcome the problems of not enforcing documentation everywhere in order to allow a less strict rule for it? |
Beta Was this translation helpful? Give feedback.
-
I have also been pointed to the following documents that contain c++ coding guidelines: |
Beta Was this translation helpful? Give feedback.
-
Furthermore I just found https://github.com/cheshirekow/cmake_format |
Beta Was this translation helpful? Give feedback.
-
In addition to clang-tidy we can use clazy that is designed to make clang understand Qt semnatics better and to include Qt-specific compiler warnings. |
Beta Was this translation helpful? Give feedback.
-
As mentioned in #4195 (comment) we're sticking to C++ for the future of Mumble development.
We still want to make sure that we make the code as stable and as maintainable as possible and in order to achieve that we'd like to gather some guidelines / best practices here. Furthermore we're also looking for tools (like static analyzers) that we can deploy (on the CI) that ensure code quality as good as possible.
clang-tidy
new
anddelete
: We should completely switch to smart-pointers for managing and expressing ownership. In general we should only have one single owner of a given piece of data, sostd::unique_ptr
is probably the best choice in like 99% of cases. For allocating new objects we should then usestd::make_unique
clang-tidy
?GUARDED_BY
,REQUIRES
, etc.) everywhere a lock is involvedclang-thread-safety-analysis
static_assert
for this?clang-tidy
?clang-sanitizers
clone()
method instead - that way we could avoid unintentional copyingclang-tidy
?const
everywhere. Not only should we be const-correct but we should mark a value asconst
, if it doesn't change. In any situation.std::vector
, etc.) is okay as we have move-semantics. No need to work with pointers for thatclang-formatter
(+ some custom check on CI whether re-formatting changes a file's content)hyde
and/orDoxygen
(standardese
?)Links
Why am I putting so much value into enforcing the new guidelines? Well as an OpenSource application we have a wide variety of contributors and relying on every contributor to magically know about the rules and to also stick to them does just not work. Same applies to expecting a code-reviewer to never forget about checking one of these guidelines.
Therefore I think having a program to check all of these guidelines is actually the best way for us to make sure that no code slips through the review :)
If you have additional suggestions as to what we should aim for for our guidelines, please let us know. Also if you think one of the suggested ones is a bad idea, let us know why. And finally: If you know other / better tools for static analysis and/or enforcing one of the guidelines, please shar your knowledge here.
Beta Was this translation helpful? Give feedback.
All reactions