r/ProgrammerHumor • • 17h ago

Meme checkBuildSettings

Post image
2.9k Upvotes

67 comments sorted by

View all comments

337

u/FabioTheFox 14h ago

Warnings as errors my beloved

89

u/nfsp-g35 13h ago

On the CI pipeline for pull requests. Your WIP branch can have all the build warnings you want, but main is having none of your shenanigans. 

42

u/FabioTheFox 13h ago

No not even on the other branches, my CI fails when the program has warnings regardless of what branch you're on, never letting warnings touch the dev branch in the first place is the only way

22

u/nfsp-g35 13h ago

I guess it depends on your source control strategy. If it were me and I was using using gitflow (assumption since you said dev branch) then protect the dev, test, stage, prod, main or whichever branches actually represent an environment... but I personally don't like to force too strict of rules on every branch or even run CI if there's no PR/MR, it burns lots of build minutes, generates noise, and can run counter to commit/push early and often. That said, I'd still prefer your approach to the wild-west, no rules nonsense that I've seen waaay too much in the industry. 

11

u/FabioTheFox 13h ago

Oh yeah totally, my wording might have been a bit off I was talking about PRs to any of the main branches (the ones you mentioned)

People can do whatever they want on their own feature branch but when it's time to push the code into one of them then they gotta pass all the checks first

2

u/LinAGKar 4h ago

That's sorta what we did at my job. If you have warnings, it will still successfully build and run the tests, but a check at the end of the CI pipeline will fail the pipeline if you have introduced warnings. And as long as the pipeline is failing, you can't merge. But yeah, that does mean we get a pipeline failure message even if we haven't created an MR yet.

20

u/generally_unsuitable 11h ago

Nah. Ignoring warnings creates notification fatigue. Clean your builds until they're silent

16

u/PrincessRTFM 5h ago

For years, my argument has been that if the warning is correct then it should be fixed, and if it isn't then it should be explicitly suppressed at that location. I don't give a fuck that it's "just a warning", warnings exist for a damn reason. Either the compiler is right and that code isn't doing what I expected, or I know better and I should save myself and any future maintainers effort by adding a suppression and explanation. The only reason I don't set all warnings to be errors is because some of them trigger while I'm still writing my code and I want to be able to test in stages.

7

u/Prawn1908 3h ago

Exactly. Warnings either get corrected or locally suppressed with a comment right above the #pragma explaining exactly why it's safe.

7

u/PrincessRTFM 2h ago

my favourite is the way rust does it: #[expect(whatever)] will emit a warning if no warning of category whatever is emitted. if you refactor things and that warning is no longer relevant, you need to remove the suppression, and using expect instead of allow is perfect for that.

4

u/raunchyfartbomb 3h ago

Oh, you used a ternary instead of an if? That’s warning because for some reason the new visual studio doesn’t like it.

Your using “new X()” instead of “new()”? Gtfo

Your extension methods for IServiceProvider don’t exist within a project named “System”? (IDE0130)

Some warnings are noise.

8

u/Prawn1908 3h ago edited 3h ago

Nothing pisses me off more than those stylistic warnings. I have my own style that makes sense to me and my coworkers and we follow strictly, and we're not going to go refactor our whole codebase every time Micro$lop adds new syntactic sugar to C#. I hate languages that try to impose their own style on me, and integrating that into the compiler at the same level as real warnings about potential dangers is offensive.

However, those warnings get suppressed, not ignored.

4

u/generally_unsuitable 1h ago

Exactly. You turn them off explicitly because 278 stylistic warnings will hide one real warning that causes issues.

15

u/ThaBroccoliDood 13h ago

NGL Rust gets it right on this one. Unused variables or unnecessary mutability, sure, give a warning. But anything else really ought to be an error. C/C++ are way too lenient on what you can ignore when it knows it’s wrong

2

u/beyluta 4h ago

Clang-Tidy rules for C and C++ can help with some of these headaches. But the setup is tedious and some flags only work on C++ but not on C or vice versa (for some unknown reason).

3

u/TiF4H3- 9h ago edited 5h ago

And even better, it's entierly customizable using directives within the code itself!
It evencan be set for the whole project, or for a specific module.

If you are still prototyping, you can add a little

#![allow(unused)]

and change it into a deny/forbid on the production build.

On the other end, a

#![forbid(unsafe)]

is a wonderful guarantee for your codebase.

There also a lot of very specific lints you can turn on, relating to endianness, and a bunch of more domain-specific things.

Quick edit:

More specifically, there's the whole restriction lint group, which is allow per default.

It has a lot of things related to enforcing some uncommon coding guidelines (like no else if without an else).

And there's also the whole pedantic lint group, also allow per default.

It's instead lints that are technically good, but more among the realm of micro optimizations and pedantic bullshit than the realm of actually important errors (like using an unstable sort to sort primitives, as it's slightly faster than a stable one).
But they can be very useful in contexts where these actually matter.

3

u/PrincessRTFM 5h ago

point of detail: it's #![...] not !#[...]

also, inline code doesn't get syntax highlighting so the leading rs for the language just gets rendered directly

2

u/TiF4H3- 5h ago

Thanks!

I always mess up the #! and never remember which is correct, lol.

2

u/pint_o_paint 7h ago

I hate that for a second I suspected your post to be an AI-copypasta; only because at first glance I saw proper formatting and an upbeat/enthusiastic intro ("And even better, it's entierly customizable[...]!").

I love proper formatting and enthusiastic posts, darn it.

→ More replies (1)

4

u/RandallOfLegend 3h ago

If warnings were a problem they should have been an error from the start. Or just not have warnings at all.

1

u/FabioTheFox 3h ago

Absolute nonsense

1

u/RandallOfLegend 57m ago

Yes, but did you know that what you're doing could result in a null reference?

1

u/FabioTheFox 55m ago

Well how about we put a ? Or ! after it to acknowledge it and act accordingly

1

u/FillingUpTheDatabase 3h ago

I prefer errors as warnings

1

u/rock_and_rolo 12m ago

My favorite codebase had Werror turned on. It was very comforting.

I find building open source stuff to be a little stressful, because I don't know whether any of the hundreds of warnings are important.

→ More replies (4)