3 ms·
This is a pretty great talk. I listened to it as a podcast instead of a video and it worked very well. You can even figure out the mistakes he's talking about w
by IshKebab 3y ago
This is a pretty great talk. I listened to it as a podcast instead of a video and it worked very well. You can even figure out the mistakes he's talking about without the code because we've all been there, e.g. the for loop, presumably this:
for (int i = 0; i < 10; ++i);
{ ...
I agree with him on all points, though I'm not sure about warnings. I think most people are against warnings because they've been traumatised by C/C++ where a ton of the warnings really should be errors (my favourite is -Wreturn-type which can cause insanely difficult to debug issues if omitted). Any sane C++ project has to turn on `-Wall -Werror` because so many of the warnings are really "backwards compatible errors".
So warnings are a disaster in C++ but I don't think that means they fundamentally are. Warnings in Rust seem to be fine.
And having no warnings at all is more annoying than Rust's approach. Go won't let you have unused variables - which is an indication of mistakes - but is really annoying when you're writing incomplete code.
- JonChesterfield 3y agoWerror means as soon as someone uses a new compiler with a new warning your code stops building. Even if it's something about misleading parenthesis or brace position. It's not a good thing to have on by default in build script.
- IshKebab 3y agoYou should have it on for CI and for first party developers by default, but have it off if you distribute your source to third parties for the reason you stated. That's kind of my point. C/C++ have a really bad implementation of warnings, which leads people to think that warnings are fundamentally a bad idea, which is not something I am convinced by.
- Gibbon1 3y agoI think people should look at the output of their compiler and fix warnings before checking in code. And frankly I'd rather the build not stop on the first error. In fact it would be best if the build system tried to link even if there are errors. Might work.
- IshKebab 3y ago> I think people should look at the output of their compiler and fix warnings before checking in code. I agree, but I don't think they should be required to fix all warnings before checking in code, which is what no-warnings languages like Go require. > And frankly I'd rather the build not stop on the first error. In fact it would be best if the build system tried to link even if there are errors. Might work. Not sure what your point is here. Most compilers don't stop on the first error.
- pornel 3y agoBut that is still a problem specific to C, not warnings in general. First of all, languages with less legacy constraints can have the line between warnings and errors in the right place, so users don't have the need to turn all warnings into errors. Werror can be reduced from being the best practice to just overly cautious pedantism. Then, even Werror can be made more robust. Rust solves this in a few ways: • cap-lints: it suppresses its Werror equivalent when building someone else's code (dependencies), so the code you can't fix yourself won't break on you due to just a lint. • editions: Bigger language changes that could render old code incompatible are gated behind the edition setting, which is an opt-in to new stuff, including some new warnings. • `allow(warning_id)`: you can put it on any code block or even the whole project. So even if you get a new warning that is a false positive or just don't have time to deal with it, you can reliably and precisely turn it off in the source code (as opposed to compiler-specific flags, #pragmas, or reshuffling the code until the warning goes away). • clippy: all the weaker, experimental, and more opinionated warnings are in a separate tool. The compiler proper adopts clippy's warnings only if they prove to be useful. The type of people who use Werror use clippy, so they'll likely have their codebase clean of these warnings before they make it to the compiler.