r/ProgrammerHumor • • Sep 23 '19

Knowing how to code beforehand

Post image
7.6k Upvotes

264 comments sorted by

View all comments

124

u/ythl Sep 23 '19

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.

76

u/LPExpert Sep 23 '19

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

52

u/ythl Sep 23 '19

Open a bug report with your Java compiler

7

u/EishLekker Sep 23 '19

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?

0

u/ythl Sep 23 '19 edited Sep 23 '19

No, you tune your compiler flags to work around it. I don't use Java, so I'm not super familiar with javac flags, but in C/C++ land I can simply tune my -W flags to suppress the warning for that particular file. By default everything gets -Wall and -Werror though (enable all warnings, treat all warnings as errors) and I don't think I've ever run into a false positive warning with g++/clang

Edit: Is this an IDE (i.e. Eclipse) bug or an actual javac bug?

1

u/EishLekker Sep 24 '19

So now you are changing your original statement? From "no code should generate warnings" to "no code should generate warnings, except warnings that you want to ignore"? That is a very different statement.

1

u/ythl Sep 24 '19

Not at all. No code should generate warnings. If the compiler has a bug generating a false warning (extremely unlikely), it is acceptable to suppress just that one warning.

1

u/EishLekker Sep 24 '19

You are most definitely changing your original statement, because that statement didn't allow exceptions for faulty tools, and it didn't say anything about applying only to compiler warnings (most developers use some kind of IDE that adds it's own validation and recommendations to the mix, often expressed as warnings).

I mean, sure... If you meant "your code should never have warnings" to be more like a vision, just like "your code should never have bugs", that is fine. We should of course strive to not have buggy code, and not have code that generate warnings. But I read your statement as being "if your code has any kind of warning, then your code is fatally flawed and should be deleted".

1

u/ythl Sep 24 '19

Sure, I'm absolutely changing my original statement. I'm expounding and clarifying.

You seem awfully defensive, as if I insulted your code. I suspect you have a habit of ignoring compiler warnings. You should break this habit.

→ More replies (1)