4 ms·
?? Compilers do reject code that doesn't meet a certain standard. C++ does come with a "linter". You might want to check out what -Wall does in gcc & clang. I'
by dahart 10y ago
?? Compilers do reject code that doesn't meet a certain standard. C++ does come with a "linter". You might want to check out what -Wall does in gcc & clang.
I've never met a linter I liked more than a real compiler, not even close. Linters for scripting languages only exist because the scripting languages aren't compiled, and they are only lightweight second rate optional type checkers. Linters' attraction and usefulness is that you aren't required to use them, so you can iterate quickly and run code without having to wait for the compiler every single time you save your file. Linters are not better at keeping you within good style and safety bounds, generally speaking.
- Manishearth 10y ago> Compilers do reject code that doesn't meet a certain standard. Yes, a bare minimum standard, which must be backwards compatible. What a compiler enforces is not best practice, it is bare minimum. Something enforcing best practice has to be allowed to be backwards incompatible, since newer better ways of doing things will always come up (that's how languages evolve), and you want to discourage the older stuff. "I've never met a linter I liked more than a real compiler" -- it's not an either or situation, use a linter on top of the compiler.
- dahart 10y ago> What a compiler enforces is not best practice, it is bare minimum. -Wall gives you a lot more than bare minimum. But, you can't really call it bare minimum when you compare compilers to linters in general. If a compiler enforces bare minimum, then a linter enforces less than bare minimum. Linters in general do not detect type errors that compilers catch and that prevent the program from running. A compiler is a bigger, better safety net than a linter. I have ~25 years experience with many linters and many compilers, and my opinion is that compilers provide more security than linters, on the whole. When I can, I try to use a real compiler for production use of scripting languages, for example Google's closure compiler in JavaScript rather than linters like eslint or jslint. > it's not an either or situation, use a linter on top of the compiler. This is true, and I agree completely, it's not an either-or situation. That's in part what I was trying to say. The compiler already does linting and it does much better static analysis, so you don't need to choose, you can just use a compiler. There are certainly higher level style analyzers, clang-tidy was mentioned already, and there are others. PEP-8, and Rubocop are in part a set of guidelines designed to prevent code mistakes and type errors precisely because the languages they represent don't come with a static type-checking compiler. Many of the linting rules and best practices only exist to prevent unsafe code that would have been prevented if there was a compiler involved, and only need preventing via style guides and linters because a compiler is not necessarily there. There are certainly best social practices that some linters enforce that many compilers don't, but for that it doesn't make any sense to avoid learning C++. The OP's comment - that he feels like C++ is a minefield without a linter - is missing the forest. It is easier to know you're writing correct C++ than it is to know you're doing correct Python, because of C++'s compiler. Unfortunately no compilers or linters are that good at preventing you from writing code that runs and then crashes.
- Manishearth 10y ago> If a compiler enforces bare minimum, then a linter enforces less than bare minimum. I'm considering linters as something you use in addition to compilers. Yes, they enforce fewer checks, but the assumption when running a linter is that the code compiles, already. Or, at least, that's what the assumption should be. > This is true, and I agree completely, it's not an either-or situation. Ah, okay. Yeah my issue was mostly with the either-or framing here. > because the languages they represent don't come with a static type-checking compiler. Yes, but this thread is about C++, which is a different world.
- dahart 10y agoTrue true, and this sub-thread is specifically about someone who is afraid to use c++ due to lack of a linter. I've used c++ for the majority of my career, and all I really wanted to say to @codebeaker is don't be afraid to learn c++ for lack of a linter, because it comes with one. My mistake that I framed it in an argumentative way, that ultimately wasn't my intent.
- Manishearth 10y agoAh, I see :)
- rleigh 10y agoThis is way too low a bar. I already use this plus: -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wextra -Wformat=2 -Wimplicit-atomic-properties -Wmissing-declarations -Wno-long-long -Wnon-virtual-dtor -Woverlength-strings -Woverloaded-virtual -Wredundant-decls -Wreorder -Wswitch-default -Wunused-variable -Wwrite-strings -Wno-variadic-macros -Wno-unused-local-typedef -Wno-language-extension-token -fstrict-aliasing and optionally: -Wconversion -Wdocumentation -Wfloat-equal -Wmissing-prototypes -Wold-style-cast -Wunreachable-code and this is still insufficient. Why? Because this is only checking syntactical and semantic correctness. It can't check for violation of local policy, such as: no use of new/delete (use make_unique or make_shared) correct and consistent use of virtual inheritance across the entire codebase rule of three and rule of five usage etc. These are mostly higher-level concerns. Stuff which other people on my team might introduce, and/or miss in review. I don't yet have anything automated in place for this, but clang-tidy is on my todo list for investigation.
- dahart 10y agoSo, then you feel that @codebeaker should wait to learn C++ until tools that fulfill your wishlist are available? You agree that C++ is a minefield compared to Ruby, only because Ruby has Rubocop and C++ doesn't? Have you used any linters? Because linters are even worse than what you're describing with the C++ compiler. What they do is complain about style issues that some people believe are likely to lead to syntactical and semantic errors, without actually checking for the syntactical and semantic errors like a compiler does. Linters also don't check for violation of local policy, unless you extend them yourself. (And feel free to extend clang's warnings to suit your needs... it is open source.) I fully 100% completely agree that C++ tooling could be way better, and I wish it was too. But that's not the issue we're talking about here at all.