←back to thread

In Defense of C++

(dayvster.com)
185 points todsacerdoti | 8 comments | | HN request time: 0.623s | source | bottom
1. franky47 ◴[] No.45268116[source]
What’s a good (ie: opinionated) code formatter and unit test framework for C++ these days?

I just had a PR on an old C++ project, and spending 8 years in the web ecosystem have raised the bar around tooling expectations.

Rust is particularly sweet to work with in that regard.

replies(3): >>45268262 #>>45268281 #>>45268294 #
2. jonstewart ◴[] No.45268262[source]
Catch2 is great as a unit test framework.

Running unit tests with the address sanitizer and UB sanitizer enabled go a long way towards addressing most memory safety bugs. The kind of C++ you write then is a far cry from what the haters complain about with bad old VC6 era C++.

replies(1): >>45281578 #
3. lang4d ◴[] No.45268281[source]
My go to for formatting would be clang-format, and for testing gtest. For more extensive formatting (that involves the compiler) clang-tidy goes a long way
replies(1): >>45270932 #
4. IshKebab ◴[] No.45268294[source]
The only formatter is clang-format, and it isn't very good. Better than nothing though.
5. CalChris ◴[] No.45270932[source]
I think you meant for more extensive static analysis. Clang-tidy is really awesome. There is also Facebook's Infer.

  https://fbinfer.com
replies(1): >>45275419 #
6. account42 ◴[] No.45275419{3}[source]
Clang tidy does both: it can run clang's analyzer [0] (also available with clang++ --analyze or the scan-build wrapper script which provides nicer HTML-based output for complex problems found), has it's own lightweight code analysis checks but also has checks that are more about formatting and ensuring idiomatic code than it is about typical static analysis.

MVSC [1] and GCC [2] also have built-in static analyzers available via cl /analyze or g++ -fanalyzer these days.

There is also cppcheck [3], include-what-you-use [4] and a whole bunch more.

If you can, run all of them on your code.

[0] https://clang-analyzer.llvm.org/

[1] https://learn.microsoft.com/en-us/cpp/build/reference/analyz...

[2] https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.h...

[3] https://cppcheck.sourceforge.io/

[4] https://github.com/include-what-you-use/include-what-you-use

7. einpoklum ◴[] No.45281578[source]
> Catch2 is great as a unit test framework.

It's "great" mainly in the sense of being very large, and making your code very lage - and slow to build. I would not recommend it unless you absolutely must have some particular feature not existing elsewhere.

Here's a long list of C++ unit testing frameworks: https://en.wikipedia.org/wiki/List_of_unit_testing_framework...

And you might consider:

* doctest: https://github.com/doctest/doctest

* snitch: https://github.com/snitch-org/snitch

* ut/micro-test: https://github.com/boost-ext/ut

replies(1): >>45292468 #
8. jonstewart ◴[] No.45292468{3}[source]
I guess I consider it great in comparison to CppUnit, Boost Test, and Google Test. I also like that it incorporated nonius, that's a big win.