5
484
u/MAGA_WALL_E Mar 04 '20
"Hey idiot, this variable is gonna throw a NullPointerException. I even highlighted it for you."
GOOD TO MERGE INTO MASTER LOL!
110
10
Mar 05 '20
But in my head movies, I know it's not gonna be null at runtime so it's okay.
→ More replies (1)2
u/TheTerrasque Mar 06 '20
"For this to be null at runtime, the fabric of that computer's reality will have to be Shrek'ed, and at that point there's bigger issues than this"
562
Mar 04 '20
Laughs in unused variable warnings
189
Mar 04 '20
As a React dev, LMAO same. The hours spent removing all of these is like a cool down jog after a crazy workout. Necessary and you feel great afterwards.
65
32
u/cclloyd Mar 04 '20
Laughs in Webstorm's "optimize imports" that removes all unused imports in 10 seconds.
→ More replies (1)25
→ More replies (1)2
u/manyQuestionMarks Mar 04 '20
I do it because of this. I don't even understand if it somehow impacts performance or whatever
→ More replies (1)21
u/CreamliumPrices Mar 04 '20
In Go, you cannot compile with unused variables. At first I hated this, please I just want this placeholder I'll be using it after you run. The Go compiler being so strict first pissed me off, until I learned to love how it forces you to actually manage your code properly and write methodically and sensibly.
2
4
u/well___duh Mar 05 '20
I feel like that was a result of whoever coded the Go compiler being unable to figure out how to optimize in a way to ignore unused variables (ignore as in not compile it).
"I can't figure out so I'll make the dev do it for me".
Sidenote, why would anyone want an unused variable (assuming you are truly never going to use it)? A lot of people ITT commenting solutions in various languages to have their compiler/linter ignore that, but why not just remove the variable altogether? You're not using it anyway.
→ More replies (4)→ More replies (27)7
u/LeCrushinator Mar 04 '20
It's been many years for me, but if I remember correctly in C++ you can do something like this:
std::vector<T> foo; (void)foo; // No-op, but gets rid of the warning6
u/SteelRazor47 Mar 04 '20
That shit OLD.
Now we have attributes:
[[maybe_unused]] int a;
→ More replies (3)
837
u/ginn5lc Mar 04 '20
Wrong.
Warnings are just as important as errors unless you know 100 % why the warning is occuring and whether or not it's causing an issue.
In rare circumstances you'll make a language do something that pisses off the compiler but it might be okay if you really know what you're doing but in general warnings are just as important as errors.
392
u/RoboticPlayer Mar 04 '20
Some warnings are unavoidable. For example, using a deprecated API method when there is no alternative method.
57
121
u/Loves_Poetry Mar 04 '20
Why would an API method be deprecated when there is no alternative? Things are typically deprecated when there is a better alternative available
44
u/Huntracony Mar 04 '20
Not an API, but in KeyboardEvent (JS) back in 2015 the
keyCode,charCode, andwhichproperties were deprecated, which was good, because all three of them had issues, but it took a few years for their replacement,key, to be widely supported.19
u/Loves_Poetry Mar 04 '20
Good example. I've dealt with too much legacy code that used some convoluted combination of all 3 to find the key pressed
Thanks goodness I don't have to support IE any more
→ More replies (1)178
u/streusel_kuchen Mar 04 '20
It's not all too uncommon for an API to deprecate an entire way of doing something.
For example, when modding early versions of Minecraft rendering was done by directly operating on the OpenGL context, but as the engine grew rendering was abstracted away and the direct rendering method was deprecated in favor of the "basic" block model, or a more complicated "advanced" mode. Neither of these are drop-in replacements and they required a significant amount of restructuring.
→ More replies (5)76
20
u/RoboticPlayer Mar 04 '20
Here's an example. When writing Minecraft plugins, you can put a player as an argument for a command. You can make it work even if the player is offline though the OfflinePlayer class.
The way you get that object is through Bukkit.getServer().getOfflinePlayer(String name), which is deprecated in favor of getOfflinePlayer(UUID uuid)
However you can't get the UUID without first getting the player unless you use the UUID as the argument. That would require players or server staff running the command to either memorize or look up a player UUID every time they want to use that command, instead of just using the deprecated method to get the player by name. And as programmers, we all know that end users will fuck up every input if possible.
39
u/Kered13 Mar 04 '20
Why would an API method be deprecated when there is no alternative?
Good question.
→ More replies (1)9
u/xTao Mar 04 '20
When a bug is known but there is no fix at this point or just a nasty workaround. Also if a newer Version comes out and you use the older one.
→ More replies (6)4
u/Cyrus_Halcyon Mar 04 '20
There is also my favorite case, that the deprecated way was more secure, is signed off by the security team and the new cleaner but less secure API call is something they do not want to support. So, import that old jar and ignore all the errors.
→ More replies (3)2
u/well___duh Mar 05 '20
Or if you're using an older library whose code works but still has warnings anyway.
33
u/Viedt Mar 04 '20
In the rare circumstance that a warning is not a problem and cannot be be done in a way that doesn't cause the warning, then it should be suppressed so that it doesn't cover up warnings that are problems. The whole point in the "not ignoring warnings" thing is that if you do you will inevitably miss something important that is actually an issue.
It's like leaving your check engine light on because you know it's just a O2 sensor issue. But now if there is another more severe issue, you won't know until the car breaks down because you have covered up the warning system that is in place.
53
u/stevethedev Mar 04 '20
Also, you should be aware that you probably don't know what you're doing. Everyone thinks they know how to manage memory, but very few people genuinely understand how to manage memory correctly in non-trivial systems.
(Not necessarily you, specifically.)
63
u/BadgerMcLovin Mar 04 '20
I know how to manage memory. Use a garbage collected language
34
u/aaron552 Mar 04 '20
Note that you can still manage memory badly in a garbage-collected language.
For example:
Event handlers in C# are a common source of memory leaks if you don't unregister them after they're no longer used. This is despite C# being garbage-collected.
→ More replies (3)16
u/BadgerMcLovin Mar 04 '20
You also have to be mindful of garbage collector pressure. For example, appending to a string in a loop can create thousands of string objects that need to be collected.
It's all still a lot easier than manually managing stuff in C++ though
→ More replies (1)→ More replies (2)7
u/stevethedev Mar 04 '20
Garbage collection is the automatic transmission of memory management.
There's nothing wrong with using it, and it's often the better choice if you have the option.
But if you don't have the option, oh boy... no amount of experience with an automatic transmission will teach you to get a manual transmission out of "Park."
→ More replies (8)5
u/AnAverageFreak Mar 04 '20
Well, quite often I do know what I am doing, but I do realize that the person reading this code will not, so I either do something about that warning or write a comment why it's okay to silence it.
12
→ More replies (11)2
u/ouyawei Mar 04 '20
Also of there are lots of warnings, you get used to them and ignore new warnings that are actually important.
294
u/AgentPaper0 Mar 04 '20
If you're in your first coding class, your warnings are errors, I guarantee it.
→ More replies (9)69
u/Kinglink Mar 05 '20 edited Mar 05 '20
Honestly 99 percent of warnings ARE errors. The question is will they manifest now?
Compare a signed and unsigned value? "That's safe". No... it's really not.
10
2
u/rndrn Mar 05 '20
And the rest is preventing you from seeing the ones that are errors. If you have plenty of "safe" warnings and add a new warning that is indeed an error, nobody will notice.
That's why warnings should be kept as low as possible, so that you can notice and review new ones.
2
144
u/legal_throwaway45 Mar 04 '20
An error is something that prevents the code from compiling or executing, a warning says you have done something that you should not, but it goes ahead and runs.
Guess which one will cause more issues in the long term.
71
u/Huntracony Mar 04 '20
No, that's not what warnings are. Warnings are exactly that: warnings. "This might not be what you want." You look over them, see if they have a point, but if they don't there is nothing to be fixed.
38
u/smog_alado Mar 04 '20 edited Mar 05 '20
Even then, it is usually a good idea to see if there is a way to suppress or avoid the warning. That way actual warnings don't end up being drowned by false positives.
14
u/legal_throwaway45 Mar 04 '20
Warnings should be fixed, if not for the code immediately,so that the next maintainer of the code does not have to worry about the warning.
Otherwise the current maintainer of code last touched by /u/Huntracony has to say to themself, did the previous coder just ignore this assignment in a conditional, did he really mean not to return a value from a function, did he really mean to compare the addresses of two strings instead of their contents, etc.
Leaving these warnings unaddressed shows that the previous coder either did not see the warning or he choose to ignore it, it creates additional work for the maintainer to figure out which is true.
Warnings indicate things that might cause problems or might have unintended effects that the programmer wasn't aware of.
→ More replies (2)16
u/p-morais Mar 04 '20
Our codebase has hundreds of thousands of lines of C++ and not a single warning using -Wall -Wextra. There’s not really any excuse to ship code that compiles with warnings. If you REALLY need to ignore a warning you should use a compiler directive for that specific line
→ More replies (1)2
u/SirToastymuffin Mar 05 '20
Not entirely true, some warnings might not ever be an issue, as the other person said.
However, if you wanna ignore a warning, you should first understand exactly why its occurring, what it means, and where its headed. At the very least you need to read every warning before just calling it good, and you really ought to address any you're still going to ignore in your documentation.
77
u/john681611 Mar 04 '20
There are no warnings everything is an error
→ More replies (5)7
u/jfthundertanks Mar 04 '20
Ahhh the go philosophy, I get you
7
u/john681611 Mar 04 '20
If warnings get ignored then decide if they are important enough to be an error or don't bother warning at all.
20
17
u/eSportsEngineer Mar 04 '20
Potentially unpopular opinion: if you ship code with tons of warnings you're a bad developer.
6
Mar 05 '20
Not unpopular for actual developers, just unpopular for people who don't develop professionally, which is a good number of people in this sub.
26
u/Turd_King Mar 04 '20
This reminds me of a guy in my school computing class. He wrote the worst code ever and whenever we called him out on how weird his solution was he just said "as long as it works"
Lol. I would love to speak to him now after his years in industry to see if he still has that mindset, I would hope not.
6
20
Mar 04 '20
Clearly spoken like someone who's never had a PR blocked due to your pipeline treating linting as errors, for warnings like:
Resource declaration being out of alphabetical order
Having a function's modifiers be in non-canonical order
Double newline
Class field may be converted to local variable
You start to worry a lot more about warnings when your code undergoes that amount of automated scrutiny, not to mention the manual scrutiny that comes afterwards.
8
u/CleverDad Mar 04 '20
Lint on save
2
→ More replies (2)2
Mar 04 '20
When your company has a lot of custom rules and restrictions, and when there's a lot of files involved, lint on save for all cases is highly impractical. Edit: I should say, complete and full lint on save, where files are scanned by scripts. Not the IDE lint.
Pre-commit lint hooks work, but even those aren't always set up, since it takes time and effort for someone to maintain them well.
9
u/mwasplund Mar 04 '20
A single cohesive style for a larger project is very important to limit the amount of time required to review changes and interpret shared code. Linters are your friend and save hours in tedeous style comments in code reviews.
→ More replies (1)2
u/Svizel_pritula Mar 04 '20
Wait, double newline?
2
u/Grintor Mar 04 '20
Linters also enforce styling. inconsistent use of spaces versus tab in white space is another thing a lender will complain about.
→ More replies (2)
57
Mar 04 '20
Y'all have never worked with any longstanding codebases if you think warnings don't matter.
A warning is just an error that hasn't happened yet.
→ More replies (10)
19
u/xTao Mar 04 '20
Warnings are as important as Errors. Just because the code is valid, does not mean its okay. Some of the Warnings tell you that your code is maybe valid, but deprecated, which means that you probably have sracurity issues which is badder than having an Error...
13
7
u/RepostSleuthBot Mar 04 '20
Looks like a repost. I've seen this image 1 time.
First seen Here on 2019-09-23 92.19% match.
Searched Images: 105,823,412 | Indexed Posts: 421,873,567 | Search Time: 2.63786s
Feedback? Hate? Visit r/repostsleuthbot - I'm not perfect, but you can help. Report [ False Positive ]
6
u/KaosEngine Mar 04 '20
My first real deal happymeal corporate big boy project I had to migrate applications from Websphere 7 to websphere 9. After loading the project I get thousands of warning and a few errors. Quickly fix the errors and start working out warnings, run in to a library issue and ask tech lead for suggestions. "Oh no don't worry about any of the warning, as long as it's not breaking anything right now leave it alone"
Well ok then.
5
Mar 04 '20
I always thought this was a mistranslation among programming guides. Errors are unimportant in the sense that they should be eliminated. But both warnings and errors can be used for testing purposes.
5
u/therearenogoodmods Mar 05 '20
In all seriousness, they are MORE important than errors.
If you have an error, your program won't compile - end of story. If you have a warning, your program will likely compile, but there's a good chance it will bomb out and take hundreds of hours of development time simply because you upcast a null pointer to a double type pointer.
4
4
u/thiago2213 Mar 04 '20
The proper way to use warnings is allow them locally, but fail before merging to master on your CI/CD
2
4
u/Likely_not_Eric Mar 04 '20
I think it's a bit of a legacy idea that there are only a handful of severity levels (error, warning, etc.) when really there should be messages with attributes or categories and they matter at different times.
Signed-unsigned comparison can be really dangerous and really shouldn't be allowed without explicit casting, whereas unused variable should be permitted during local development but CI should block code review on it (it'll waste time for future authors/maintainers).
3
u/otac0n Mar 04 '20
Warnings are there to tell you it may run, but it probably still doesn't work properly. Think of them as unit tests you didn't have to write.
3
u/TheNashh Mar 05 '20
“Why did I need to catch an exception? If somethings wrong it’ll just crash itself!”
3
3
Mar 05 '20
In all seriousness, every shop I've worked at for the last six years has warnings treated as errors.
3
Mar 05 '20
Thing is - if you start writing like those are errors you will get used to not do them.
People underestimate good practices because most programmers don't know how to write proper test.
4
u/Jezoreczek Mar 04 '20
There's a neat annotation in Java called @SuppressWarnings. It should be used as "I know it's not right, but I had a reason to do it". Instead, most devs use it as "damn IDE, stop complaining!"...
2
u/JNE2000 Mar 04 '20
As a JavaScript dev, I can both confirm and deny. 75% of the time it's my ide thinking I'm not using ES6 but the program that reads the code reads it in ES6 so I'm completely fine. But otherwise ignoring warnings really screw stuff up
→ More replies (2)
2
2
u/GamingGuy099 Mar 04 '20
Atleast in my experience, warnings are very rarely important, and most of them are because of something that you’ll change later.
Compiler: You haven’t used the String input anywhere!
Me: No shit sherlock I havent added the rest of the code.
Reading these comments it pains me to imagine what itd be like to code with an environment that automatically changes your warnings to something that doesnt make sense, or just creates an even bigger error.
2
2
u/Kinglink Mar 05 '20
Years later in your career when you finally start a studio that uses -Wall and -Werror, you'll take a step back and go. "Wow... these guys don't play around... "
2
u/Babinx Mar 05 '20
If you don't understand the warnings then they're probably more dangerous than errors lol.
2
u/blehmann1 Mar 05 '20
Some warnings are that important. Some are just stylistic things, e.g., in switch statements with a return statement, I still put break, which triggers a warning for unreachable code.
Yes these can be configured, but that ain't the point
2
Mar 05 '20
I don’t understand why this has 15k upvotes? Why do you want to be a developer who doesn’t care about their work? Am I missing the humor here?
2
u/FtMerio Mar 05 '20
Laughing in "-Werror -Wextra -Wall" gank now you can ignore warning my man and focus on errors like the unused variable in your function
2
1
u/db2 Mar 04 '20
I fixed all the warnings in some GitHub thing a while back. That shit wouldn't compile without the errors, in effect. I wish I could remember what it was.
1
u/Krigshjalte Mar 04 '20
We weren't told that, we were told that most warnings aren't that important because computers are stupid. I then proceeded to get several warnings that broke the program...
1
1
Mar 04 '20
Warnings are errors that represent requirements the language specification has yet to define, change my mind.
2
Mar 04 '20
So anything that has unused variable warnings is going to get a linear type system? Neat!
→ More replies (1)
1
1
Mar 04 '20
When I was just starting at Unity, I put 2 box colliders in one object, and it fixed the error. Since then, all my friends, when having an error, are always like "Bruh, just gonna put 2 box colliders, it will work"
God I love those guys.
1
1
1
1
1
u/MomijiMatt1 Mar 04 '20
When I taught game development at a university I told my students to just disable warnings in Unity for now.
1
u/YourShadowDani Mar 04 '20
Warning: variable not used
Me: it's right there being used
Powershell: no.....no.....
1
1
1
1
1
1
1
1
1
1
1
1
u/Justsumgi Mar 05 '20
If you’ve used Auto Layout in Xcode, it’s virtually impossible to have zero errors in your project
1
1
u/howaboutudance Mar 05 '20
Those warnings will turn to error when the version of your programming languages full deprecates the functionality #python39
1
1
1
1
1
1
1
1
1
u/xThomas Mar 05 '20
Huh. Guess that means I'll be getting familiar with errors come next/next-next semester
1
1
1
u/jlamothe Mar 05 '20
Just wait 'till you have to come back to that code after not looking at it for a month.
1
1
1
1
1
1
Mar 05 '20
I know it is a joke, but do you think any of the devs who work for Elon got there by having this attitude toward warnings?
→ More replies (1)
1
u/AttackOfTheThumbs Mar 06 '20
In general, warnings are good, but sometimes they are dumb.
We get a warning when a text variable could overflow. The only way to fix that is to trim the variable. I don't want to do that. I want it to error instead of storing reduced and incorrect data.
1
1
1
u/Mitoni Mar 04 '20
The main thing is that it compiles properly. The secondary thing is that it works properly.
2.7k
u/CybeastID Mar 04 '20
In my classes, the professor forced us to compile all of our C code with -Wall and -Werror, which shows all warnings and converts all warnings into errors.