Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommend a linter for C++? #8

Closed
kytrinyx opened this issue Aug 17, 2014 · 8 comments
Closed

Recommend a linter for C++? #8

kytrinyx opened this issue Aug 17, 2014 · 8 comments

Comments

@kytrinyx
Copy link
Member

See exercism/docs#54 for details.

@LegalizeAdulthood
Copy link
Contributor

There are a couple issues here. First, there is the "styling" of code: spaces vs. tabs, placing of space characters, bracing styles, etc. Second, are static analysis tools.

@kytrinyx
Copy link
Member Author

This is definitely about (consistent) style (spaces, braces, that sort of thing), not static analysis.

Static analysis is a delightful rabbit hole, though, and we're exploring the possibility of integrating some aspects of that into exercism (see exploration/discussion here: exercism/exercism#1607).

@LegalizeAdulthood
Copy link
Contributor

OK, in the realm of styling, I know of tools that exist to reformat your C++ according to some style guide, but they don't give you feedback on how well you are doing at matching a particular style or even if your style is consistent throughout.

I think what comes closest to the ruby example shown in pull request #1607 for C++ is cppcheck with it's performance and style category of warnings. clang-modernize is a source-to-source transformation tool that can replace outdated constructs with C++11 constructs, but it simply modifies your source file in place, it does not provide feedback without the user running a before-and-after diff.

@kytrinyx
Copy link
Member Author

I think warnings are more useful than transformations, except where there's a language-wide consensus (such as with Go - Go has both go fmt that does transformations for everything that is completely accepted, and go lint for style warnings). This is because I think it's interesting to have the discussions about why one choice might be better than another, rather than just enforcing a choice.

In this case I think that cppcheck sounds like a better choice.

@LegalizeAdulthood
Copy link
Contributor

Yeah, cppcheck is better for providing this sort of feedback. For instance, cppcheck will issue an error when you use iterators over containers along with container modifying operations in such a way that the iterators are invalidated and you're going off into undefined behavior. It also will nitpick you on things like bit shifting signed quantities in ways that lead to undefined behavior, memory leaks, etc. Those all fall into the error category.

Things get more interesting when you turn on style and performance warnings. Then you get things like preferring ++iter instead of iter++ unless you need the previous value of iter. While cppcheck isn't the greatest, I think it is easy to use, easy to deploy and the messages are easy to interpret.

@kytrinyx
Copy link
Member Author

cool, it sounds like a good choice.

@celavek
Copy link

celavek commented Jul 27, 2016

How about clang-tidy?

@LegalizeAdulthood
Copy link
Contributor

cppcheck is available on all platforms; there isn't an out-of-the-box ready experience for clang-tidy on Windows yet AFAIK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants