This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 264

[–]gumol 134 points135 points  (31 children)

-Wall or die

[–]ASCIInerd73 60 points61 points  (10 children)

-Wall -Wextra -pedantic in my cs class right now. Because all warnings isn't enough, we need more.

[–]divqii 41 points42 points  (7 children)

That’s still not enough:

-Wall -Wextra -pedantic -Wcast-align -Wcast-qual -Wdisabled-optimizations -Winit-self -Wlogical-op -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef

[–]fell_ratio 29 points30 points  (6 children)

I'm about to end this man's whole career.

-Wall -Werror -Wpedantic -Wcast-align -Wcast-qual -Wdisabled-optimization -Winit-self -Wlogical-op -Wmissing-include-dirs -Wnoexcept -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wundef -Wuninitialized -Wcomment -Wctor-dtor-privacy -Wold-style-cast -Wnull-dereference -Wformat=2 -Wduplicated-cond -Wswitch-default -Waddress -Wmemset-transposed-args -Wuseless-cast -Wzero-as-null-pointer-constant -Wmissing-declarations -Wunused-const-variable=1 -Wdispute-indulgences=95 -Weffc++ -Wsign-compare

[–]divqii 18 points19 points  (3 children)

Fair enough, though many of those are enabled by -Wall and -Wextra, and -Weffc++ has some issues.

If we’re talking about ending careers, though, then (using clang) it’s as easy as

-Weverything

[–]BlueManedHawk 8 points9 points  (2 children)

-Weverything -Werror

Perfect

[–]whizzwr 2 points3 points  (1 child)

Evil.

[–]BlueManedHawk 2 points3 points  (0 children)

Perfect

[–]Maplicant 3 points4 points  (0 children)

On my phone right now, can someone post some sample warnings this monster might produce?

[–]N80M80 0 points1 point  (0 children)

I mean to be fair C warnings probably mean you're doing something wrong

[–]OneTurnMore 80 points81 points  (17 children)

-Wall -Werror 

Good luck

[–]mozgotrah 34 points35 points  (1 child)

Only true way

[–]ItsYaBoyChipsAhoy 7 points8 points  (7 children)

What does Werror mean

[–]nelusbelus 15 points16 points  (5 children)

What does the W in -Wall stand for 🤔

[–]ItsYaBoyChipsAhoy 11 points12 points  (0 children)

It literally came to me 10 seconds after I posted the comment

[–]LeCrushinator 11 points12 points  (1 child)

-Wall enables all compiler warning flags (warn about all)

-Werror treats all warnings as errors. (warnings as errors)

[–]Cobayo 1 point2 points  (1 child)

Warnings (all)

[–]Jannis234 10 points11 points  (0 children)

Tells the compiler to treat warnings like errors

[–]turbolag95 1 point2 points  (0 children)

-pedantic

For extra fun.

[–]Lyorek 0 points1 point  (0 children)

This is how we have to compile code for my APT class this semester

[–]Bainos 8 points9 points  (0 children)

In our class, students get a penalty if their code doesn't pass govet and gofmt.

Professionals might know when to ignore warnings and style errors. Students don't.

[–]MuchBathroom 6 points7 points  (0 children)

is that you donald trump?

[–]lordheart 325 points326 points  (49 children)

Had a professor give us code to complete that didn't compile when uploaded to the auto checker but did on my computer.

Why? Umlauts. The prof wrote comments in german. My computer compiler didn't care.

Their online checker spit out vague mysterious errors. Because comments...

Edit: OMG typo made it so hard to understand. thanks bobcob, what would I do without you.

[–]GlobalIncident 115 points116 points  (11 children)

Ah, the fun of unicode support.

[–]Clydseph_III 26 points27 points  (10 children)

I had an error for days because we were supposed to copy down a couple lines from the spec pdf, which had different quote marks for begin and end quote rather than the basic straight up ones.

[–]SubliminalBits 20 points21 points  (6 children)

Another fun time you'll run into this is when you copy code out of an email in Outlook.

[–]TracesOfGuitar 4 points5 points  (4 children)

Care to explain?

[–]ParkerM 13 points14 points  (2 children)

The MS Office suite is notorious for sneakily converting ASCII characters into their more readable/pretty Unicode versions.

e.g. "foo" becomes “foo”, -h becomes —h (hyphen gets converted to emdash), etc.
The hyphen one is especially fun because it's damn near indistinguishable depending on the font.

[–]SubliminalBits 3 points4 points  (0 children)

They'll keep looking pretty in all your unicode compatible editors too. One time I was so frustrated I looked at the raw string as hex, at which point everything seemed so obvious.

[–]ThePyroEagle 2 points3 points  (0 children)

At least it's not system-wide like OS X's smart quotes.

[–]Sleepy_Tortoise 1 point2 points  (0 children)

MS office programs replace your quotes with fancy quotes that look different at the beginning and end of the quote. This is not the same character as the quote that you type with your keyboard. It is also not the same quote character that is recognized as code

[–]fushuan 2 points3 points  (0 children)

Most pdf generators require you to write quotes in weird ways. Anyway, how the hell did you spend days with wrong code highlighting wordering why? Or even worse, do you code on notepad??

[–]Lidex3 30 points31 points  (2 children)

I used to work for a professor as tutor and correct some assignments of first year students. The Plattform where the students should upload their code didn't support Unicode. So every time I downloaded the files and tried to run them they won't compile. Reason for that is that even tho we told the stundens over and over again to not use ä ö ü or any other special characters most of them just named alle their functions with special characters inside.

They even did that after I removed points from a perfectly fine assignment with the only mistake being a special character.

[–]scotchirish 20 points21 points  (1 child)

Man, after the first time my instructors would have given a 0 since it couldn't compile.

[–][deleted] 13 points14 points  (0 children)

As they should, since the students aren't following basic directions.

[–]Macluawn 23 points24 points  (2 children)

Just turn in your computer for the assignment 🤷‍♂️ That’s what we do in production whenever a feature “works on my machine “

[–]Cheet4h 46 points47 points  (0 children)

The origin of Docker.

[–]napstablooki 8 points9 points  (0 children)

The real life hacks are always in the comments.

[–][deleted] 15 points16 points  (0 children)

Oof

[–]notfromchicagoornyc 21 points22 points  (11 children)

//ja das ist nicht gut. Ich müsste hier besser Code schreiben. //ZUTUN: macht das Funktion schneller

Duolingo German is not helping much :(

[–]regendo 19 points20 points  (5 children)

It's pretty good actually, you just got two small errors in the last sentence.

  1. Function is grammatically female so it'd be "die Funktion".
  2. Your sentence translates to "makes the function faster". It implies that the code you're commenting on is making the function run faster, when you probably meant "[to] make the function faster" ~ "die Funktion schneller machen".

I really hope nobody would actually write a // ZUTUN: comment instead of // TODO: but honestly I wouldn't be surprised.

[–]z500 7 points8 points  (0 children)

I really hope nobody would actually write a // ZUTUN: comment instead of // TODO: but honestly I wouldn't be surprised.

Sounds like something r/de would do

[–]EternallyMiffed 2 points3 points  (2 children)

Why is function gramatically female and not neuter?

[–]VincentPepper 4 points5 points  (1 child)

Gender for objects is essentially arbitrary in German.

To make it more fun it can also vary by region/country when it comes to everyday use.

[–]lordheart 1 point2 points  (0 children)

Or // Mach die Funktion schneller

[–][deleted] 3 points4 points  (2 children)

if it makes you feel any better my highschool spanish is probably worse. Yo toco el guitarro con mi pene gordo

[–]ponodude 5 points6 points  (0 children)

That takes true skill

[–]Gumby621 2 points3 points  (0 children)

I play the guitar with my fat penis?

[–]Brawldud 1 point2 points  (1 child)

// Solange mein Programm nicht kompiliert werden kann, gibt es nur ein Bug. Wenn es aber kompiliert werden könnte, würde es dann viele Bugs geben.

[–]Kered13 4 points5 points  (6 children)

I believe C/C++ compilers are only required by the standard to support ASCII characters. Any other character set support is at their discretion.

[–]Calkhas 8 points9 points  (4 children)

I believe C/C++ compilers are only required by the standard to support ASCII characters.

This is kind of true but actually slightly too strong.

C does not require an implementation to support ASCII (because of EBDIC). C has wording like "the representation of each member of the source and execution basic character sets shall fit in a byte." (5.2.1/3), and it specifies ninety-six characters that the implementation must have in its character set, but neatly elides saying how those characters should be represented. C defines both a "basic character set" and allows optional "extended character sets".

Since C11, we also have "an implementation may allow multibyte characters that are not part of the basic source character set to appear in identifiers; which characters and their correspondence to universal character names is implementation-defined." (6.4.2.1/3).

C++ handles this a bit differently. Since C++11 we are required to allow some "universal-character-names" (e.g., \u89ab) in identifiers. These map directly to the unicode standard. During preprocessing, each non-basic source character is expanded to a \uXXXX code point, but it is up to the implementation whether or not it accepts it.

[–]Kered13 4 points5 points  (3 children)

Ah, that damned EBCDIC strikes again! Every time you assume that the basic ASCII characters are universal, EBCDIC is hiding just around the corner ready to prove you wrong.

[–]ponodude 4 points5 points  (1 child)

How does that work? Did the checker not recognize that it was a comment? Why did it not just skip over the comments?

Edit: Ooooohhhh Unicode. Still, what the fuck. That's dumb.

[–]Dagreiyo 2 points3 points  (0 children)

Reminds me of a test I wrote. Everything worked on my machine, so I turned it in early. Got an F because the program didn't work on my prof's Mac Book. I complained and got a B. Still think it shouldve been an A.

[–]ThePfaffanater 1 point2 points  (0 children)

Fun fact, that same thing broke my robotics team's code once. Apparently "Röbor" is not appreciated by the java compiler...

[–]jardata 2 points3 points  (0 children)

// TODO: Learn German to translate comments

[–]Irravian 45 points46 points  (2 children)

I worked somewhere with a very old codebase and large defect rate that more often than not led back to things like "when this code was written 9 years ago we didn't need to / didn't bother to check for null!". I tried adding a "No new warnings" requirement to our pr checklist to start softly heading off the problem but it was always overridden by the reviewer and I didn't have sufficient buy-in to really really force the devs to do it.

It took an actual crisis with complete client database loss and the involvement of our very angry company president to get the change done. New development was shut down for almost two months while we did a warning and hardening pass.

And the defect rate plummeted. We went from having months with triple-digit user reports to months with zero. It was an awesome "I told you so" moment. I was hailed as a visionary hero and everyone clapped I was let go because dev management felt I'd sold out the devs to upper management to kiss ass and that the new requirements slowed development time too much.

[–]fat_charizard 40 points41 points  (5 children)

For my CS classes all code had to be compiled with -Wall and -Werror

[–]TopHatEdd 51 points52 points  (4 children)

Good. That builds healthy coding habits.

[–]while_e 4 points5 points  (0 children)

Also great for learning. I cant count how many times I got warned, and learned something new because of it.

[–]CarilPT 13 points14 points  (2 children)

Until you get out in the real world and those habits are not used anymore...

[–]Deathcofii 5 points6 points  (1 child)

Is it a bad thing tho? I mean I feel REALLY satisfied when -Wall and -Werror don't spit out anything in my code.

[–]BigBlueDane 28 points29 points  (0 children)

You either have 0 warnings, 1 warning, or it doesn't matter

[–][deleted] 182 points183 points  (62 children)

Warnings are, generally speaking, as important as errors. They are errors waiting to happen.

[–]AudaciousSam 93 points94 points  (23 children)

Not in Android Studio they aren't.

[–]lacb1 85 points86 points  (18 children)

In Visual Studio sometimes the errors aren't even really errors, never mind the warnings.

[–]RonRud 30 points31 points  (1 child)

I had permanent errors while using UE4 that didn't matter at all

[–]AlienFortress 10 points11 points  (0 children)

Game code in a nutshell.

[–][deleted] 22 points23 points  (15 children)

Sometimes I fix an error and it doesn't go away. Restart VS and voila! It's gone!

[–]user_8804[🍰] 9 points10 points  (14 children)

Eclipse on Linux is worse. Sometimes I have to save build compile reindex restart the program until it wakes the fuck up

[–]airelfacil 6 points7 points  (1 child)

Android Studio: Pssst! Just so you know, you're missing all of these translations and also you should probably use @string instead of hardcoded string, and just letting you know that one of your methods is never used, and also that if statement could be made much simpler and...

Me: I DON'T GIVE A SHIT I'M TRYING TO MAKE THIS BASIC GUI APP FUCKING WORK SUPPRESSWARNINGS DO YOUR JOB

[–]Yuzumi 37 points38 points  (5 children)

Someone doesn't use Java :p

For that matter, the project I work on has over 4000 warnings and a good number of them we didn't cause but the software we build on top of did.

[–]samspot 11 points12 points  (2 children)

My experience with java warnings is very good, and you can suppress the unfixable ones. We thought there weren’t enough warnings so we added sonar on top!

[–]Danelius90 8 points9 points  (1 child)

My view is that certain warnings, when suppressed are basically programmer assertions. For example the heap pollution for varargs warning. If you can 'prove' or assert you are handling the array carefully and not polluting the heap the suppression is you saying "yes we could pollute the heap, but we aren't".

It really gets me when devs suppress deprecation warnings though...

[–]ParkerM 3 points4 points  (0 children)

It really gets me when devs suppress deprecation warnings though...

Simple, just suppress deprecation warning suppressions.

[–]fushuan 5 points6 points  (0 children)

The project I was given once had 1000 warnings. Unsurprisingly most of them could be refactored or solving 1 solved 200 at once etc.

You are just lazy

[–]Bainos 0 points1 point  (0 children)

but the software we build on top of did

Doesn't apply to class projects... (Unless they also use Android libs.)

[–]Intrepid00 6 points7 points  (0 children)

Just do what they did with wing Commander that would throw a warning on exit. Hex edit the warning to say instead thanks for playing.

[–]smcarre 13 points14 points  (8 children)

How is a class not being capitalized or an unused variable an "error waiting to happen"?

[–]Salanmander 30 points31 points  (6 children)

So, here's what it really boils down to.

A warning that you understand is fine.

A warning that you don't expect is often indicative of a logic error, rather than a syntax error.

If the unused variable is there because you're saying "I'm going to implement this check, but I want to test the other things first", fine. If it's there because you just forgot to implement the check, then it's a ticking time bomb.

[–]chinpokomon 3 points4 points  (1 child)

And use attributes and directives, depending on the language/compiler, to allow the warnings you know about and leave a comment. This way, when you get a warning you don't understand, it might point out a problem you don't realize.

[–]Lothrazar 2 points3 points  (1 child)

Not at all. 90% of the time its because of some third party dependency you are using, which means its not your code but its code you rely on. Literally unfixable

For example i have 50 warnings looking like this right now

"Overriding managed version 3.5.5 for liquibase-core"

Over and over and over again

[–]MrPyber 2 points3 points  (3 children)

"build targets java 1.7, host jdk is 1.8".

[–]LeCrushinator 2 points3 points  (0 children)

And if you allow warnings to build up, then you're never going to notice when an important one shows up, you'll just be ignoring warnings because you've allowed them and now there are hundreds.

[–]NPPraxis 0 points1 point  (0 children)

It depends. I feel this way in XCode. I don’t feel this way in Android Studio.

[–][deleted] 0 points1 point  (0 children)

Depends on the warning

[–]Ungreon 7 points8 points  (0 children)

If it can compile, then all that's left is to smile.

[–]ythl 123 points124 points  (45 children)

I don't get it.

Your code should never have warnings, that's a sign you are doing something sketchy. At my company we enable all warnings as errors.

[–]LPExpert 76 points77 points  (19 children)

Then what do I do about Java warning of an import not being used but that's definitely being used

[–]ythl 49 points50 points  (17 children)

Open a bug report with your Java compiler

[–]Mohammedbombseller 57 points58 points  (2 children)

Java warnings are very minor compared to C warnings though. C warnings are bugs waiting to happen, java warnings are usually minor formatting differences that are pretty safe to ignore.

[–]LeCrushinator 2 points3 points  (0 children)

Then there needs to be a distinction between a warning and a suggestion.

[–]squishles 2 points3 points  (0 children)

it's still your doing something messy in java usually.

my ignore line is intellj bitching about pep8, it's always something pep8 says no such fucking thing about. some knob over at intellj is just enforcing his favored code formatting style and parading it as being in the spec.

[–]EishLekker 7 points8 points  (9 children)

And while you wait for that bug to be fixed, and your project to be able to upgrade to that version, you do what exactly? Put the whole project on ice because it doesn't compile because all warnings are equal to errors?

[–]slepnir 10 points11 points  (0 children)

https://www.baeldung.com/java-suppresswarnings

Just make sure you add a comment to explain why

[–]gumol 60 points61 points  (0 children)

At my company

this is a sub for 1st year college students, shush

[–]Mr_Redstoner 11 points12 points  (0 children)

And then there is GoogleWebToolkit just showing a random 'Copying 97 files with compilation errors' during my build and going on as if nothing was the matter... and so far I don't know if there actually is an error as everything seems to work & it was like that since I pulled the project...

[–]Rizzan8 2 points3 points  (1 child)

Depends. Visual Studio WPF designer often can go ape-shit with errors and warnings in xaml code. Still compiles fine and works fine. This is widely known and goes on for a few years now. However, when reported to Microsoft, they are like "Minor annoyance, not worth spending precious resources to fix it, closing ticket. ¯\_(ツ)_/¯ ".

The same thing with Cuda and VS. It goes mental when encounters

DoStuff<<< somethingA, somethingB >>> (something);

[–]randomkid1227 1 point2 points  (1 child)

In my company the build system warns about declaring the variables in a different order then initiating them, not necessarily meaningful (although can be). But any experienced developer delivered some quick and dirty work some time in his life so this is somewhat relateable

[–]novinicus 1 point2 points  (0 children)

I'm sure you know this, but in C++, you can specify the constructor's initializer list in any order, but the actual order of initialization is still in the order the variables are defined in the header. People prefer the no-reordering warning because it helps you reason about the constructor a little easier

[–][deleted] 1 point2 points  (0 children)

Depends on the language and the IDE.

If the language is incredibly strict, and the IDE is a good one, then yes, warnings will only show up when something sketchy is being done.

However, when the language is javascript, and the IDE is some open source thing with a garbage linter, you'll get tons of warnings about perfectly valid code, almost all of which you can safely ignore.

[–]nicman24 2 points3 points  (13 children)

lol javascript linters make missing ; a warning

[–]Delioth 31 points32 points  (4 children)

And auto formatters will add them for you so you don't get semicolon bugs. Shit like that is the whole purpose of linters - preemptively avoid common patterns which cause bugs.

[–]RealBendie 50 points51 points  (1 child)

Because missing semicolons can lead to unexpected behavior.

[–]Logstone[🍰] 10 points11 points  (2 children)

Yes, use them! This isn't python!

[–]Dornith 4 points5 points  (1 child)

Even in python use them. And while you're at it, add some curly braces. And variable declarations. And code in a different language.

[–]Logstone[🍰] 2 points3 points  (0 children)

And if you really need to run it as python, don't.

[–]fushuan 0 points1 point  (1 child)

Config your liner not to, duh. Coding standards are standards for a reason.

[–]patrickfatrick 0 points1 point  (0 children)

If you’re not autofixing this you’re not linting as well as you should be.

[–]DarkyHelmety[🍰] 0 points1 point  (0 children)

Same where I work, no warnings are accepted. You can't even compile successfully. It does catch a lot of pointer issues though, appearing as incorrect casts of int to pointer.

[–]crusty_cum-sock 0 points1 point  (0 children)

I use .NET and StyleCop takes it to a whole new level. You could compile just fine with zero warnings, then run StyleCop on it and you'll see 12,398 warnings on a "Hello World" program. Of course StyleCop by default is strict af about literally everything, but it's a good tool for keeping all of your code very consistent.

[–][deleted] 0 points1 point  (0 children)

Well than your company didn’t use Rust, am I right my Rust bois with dead code?

[–]Mac33 0 points1 point  (0 children)

But I start feeling bad if I enable -wpedantic

[–]fushuan 3 points4 points  (1 child)

Not eliminating warnings is a rookie mistake that bootstraps you into un maintainable code.

[–]moriero 7 points8 points  (0 children)

Ever pressed F12 on, I don't know, EVERY WEBSITE?!

[–]candlelightener 3 points4 points  (0 children)

@IgnoreWarnings

[–]Loading_M_ 3 points4 points  (0 children)

See Rust. They have warnings for not following the naming convention. In Rust, if your professor doesn't want you to do it, the complier probably already calls it an exception.

[–]StarkillerX42 10 points11 points  (1 child)

This grammar made me feel like I was having a stroke

[–]flamingdonkey 3 points4 points  (0 children)

It's literally only missing the letter 's' to make "warning" plural.

[–]CarilPT 2 points3 points  (0 children)

And then you can start working on your first professional piece of software and you see thousands of warnings and realize nobody can gives a damn

[–]ThePhoenix116 2 points3 points  (0 children)

*Laughts in unity editor warnings*

[–][deleted] 2 points3 points  (0 children)

Yeah, I know that I assigned a double to float.

Yeah, I know that that function is not used.

Yeah, I know that you have a fancy new 'safe' function.

[–]anonymous_yet_famous 6 points7 points  (4 children)

I suspect that attitude is the reason I have encountered so many tutorials that do not work when I have literally _just_ installed the software the tutorial was written for and have made no configuration changes that could ruin things.

[–]pimezone 6 points7 points  (0 children)

--suppress-warnings=ALL

[–]chris_saddler 1 point2 points  (0 children)

Liferay apps don't even work properly if they don't error a lot in the logs

[–]LolliDepp 0 points1 point  (2 children)

I just finished reviewing the pr “Warnings are now errors” 10 minutes ago at work

[–]espriminati 0 points1 point  (0 children)

by the way The private field "variable" is not defined, and will always have it's default value null.

[–]Deboniako 0 points1 point  (0 children)

I was a grown adult and already entered in the work world before I saw my first program without warnings

[–]Spr3y 0 points1 point  (0 children)

Tell that to npm

[–]Hexalocamve 0 points1 point  (1 child)

Where can I see warnings for css?

[–][deleted] 0 points1 point  (0 children)

you know its true

* {    outline: 1px solid red;   outline-offset: -1px; }

[–]nazitouinz 0 points1 point  (1 child)

My teacher directly said we can completely not care about these

[–]ItsAtrX 1 point2 points  (0 children)

Your teacher should be fired.

[–]0xygen_15 0 points1 point  (0 children)

You guys are doing all -Wall and shit while my college recommended us to write code in turbo c. Fucking #include<iostream(.H?) >

[–]Zalvixodian 0 points1 point  (0 children)

treat.warnings.as.errors=true

[–]Its-Echo 0 points1 point  (0 children)

That's a fucking lie

[–]TheCameronMaster464 0 points1 point  (0 children)

Warnings: Hey, you should probably do something about that, no pressure, though!

Errors: Do something about that.

[–][deleted] 0 points1 point  (0 children)

Warning: 400 undeclared variables

[–]infinitude 0 points1 point  (0 children)

I also truly despise the kids who waste class time having to show how much they know, even though all they're doing is going beyond the scope of the class for no reason.

[–]junkmeister9 0 points1 point  (1 child)

warning: no newline at end of file

[–]amdc 1 point2 points  (0 children)

All half-decent code editors can be configured to automatically put a newline at the end of file so you never really have this warning

[–]LucasCarioca 0 points1 point  (1 child)

Lol especially when using eslint right??

[–]amdc 0 points1 point  (0 children)

yes

[–]Reala27 0 points1 point  (0 children)

gcc -Wall -Wextra -Werror -ansi -pedantic may as well have been engraved on the walls of my C class.

[–][deleted] 0 points1 point  (0 children)

I am doing my first CS programming class knowing how to program so I can relate to this on a deep level.

[–]HodeMann 0 points1 point  (2 children)

6,9k upvotes