In general, should I configure my compiler to handle warnings as errors?

Is there a short-term annoyance about fixing warnings that you could leave with dividends to pay dividends in the long run? What types of runtime errors can usually be avoided by doing this?

+4
source share
5 answers

My opinion is that there are warnings for some reason; ignore them at your own risk. While some are really picky, for the most part they do it for a good reason. I would prefer that they be fixed, and a good clean compiler.

+4
source

It depends on what you think is a “warning that you can leave." Also in light of any future modifications to your code.

The longer I think about it, the fewer “warnings I can leave” remain.

+2
source

I usually fix all warnings, but don't set them as errors ...

+1
source

In general, yes.

I am sure there are many exceptions. Third-party header libraries that won't compile this way, but that you don’t want to touch, are the largest of them that I can think of. (Even then, I sometimes used #pragmas around the #include line to suppress warnings in some headers, so I can save warnings as errors in the rest of the code.)

Another exception are small projects; a simple rule for me - if I need a Makefile, then this is no longer a small project, and I want to receive an anal message about warnings, documentation and unit tests.

+1
source

This is why I think you should treat warnings as errors:

When you have a long chain of methods where something can turn out null:

var amount = _client.SnatchLeftoverOrders( _username, _password, "pepperoni").Where( o => o.Ingredients.Any("mushrooms").Where( o => o.Ownersname.ToUpper == _incomingName ).Amount(); 

Or something like this - there are many places where zero exceptions can occur.

The code is much simpler when you put these lines in a try / catch than add FirstOrDefaults () and then paste in! null

If you have a catch, you have to do something with the Exception object or this is an error (if you treat warnings as errors.

This is not a way to win the “polished programming” medal, but it simplifies things. There is too much stuff for nannies in programming these days.

0
source

Source: https://habr.com/ru/post/1346729/


All Articles