Don’t ignore warnings

Compilers generate warnings for a reason. Visual Studio may allow you to turn them off, but maybe you should reflect on the poor quality of many Microsoft products before following in *that* line of footsteps. They get away with it because of the nasty rope they have around end users necks.

16 Comments

More details! More details!

;)

Yeah. I have a level 1 coder working on my team and I have encourage him to actually fix the problems instead of ‘fixing’ the notifications..

I wish that there were more Pragmatic Programmer’s in the world.

http://www.pragmaticprogrammer.com/ppbook/index.shtml

I’ve decided my next PC will by a Mac, I’m a .net developer but I don’t code at home and the 2 games I play (wwiiol & eq2) are both mac compatible so nothing here is holding me.

In the programmer courses I have taken, a compiler error was ground for failing the project.

lots of compiler warnings are really harmless unless you are trying to optimize your resources. Things like:

“Warning Local Variable X is declared but never used.”

only take up an unused stack spot and cause no harm otherwise.

MS’s problem is not always with MS, it’s with the application programer. It’s up to the app programer to write robust code, which most don’t. Most don’t handle exceptions robustly. Most don’t think about security in a robust fashion. Most don’t optimize CPU cycles.

The language can only do so much.

In short I blame the guy who writes the app before I blame the compiler. The guy who writes the app ususually blames MS because that’s a great way to pass the buck. I do it all the time. :]

Eigenman: “Warning Local Variable X is declared but never used.”

Except when the next coder comes alone and inherits the code. Typical response is “WTF? Was this supposed to be used or was the previous code just freakin lazy. If they were unwilling to even remove a simple issue like this, what other crap am I gonna find?”

Yes. Technically it is just a bit of unused memory but it confuses the intent of the code.

Eigenman: “In short I blame the guy who writes the app before I blame the compiler.”

Exactly. It’s all about taking pride in what you write.

My point exactly is don’t blame the compiler – don’t ignore it and say “stupid compiler”. There’s a reason it’s telling you that.

To take Eigenman’s example; lets say you decide the “unused local variable” is harmless.


int formula(int a, int b)
{
int x1 = 3 * a ;
int x2 = 4 * b ;
return x1 + x1 ; // Add x1 and x2
}

My point about Visual Studio isn’t hating on it, just that VS users seem to love turning off warnings. Yes, there are situations where it is genuinely valid to turn certain warnings off, but you should resist to the death.

Genetic Algorithm\Protein Folding\LargeProtein Folding.cpp:6 [Warning] “RAND_MAX” redefined

Baahh it’s all the other errors i’am more worried about :D

Heh, warnings like that are the compiler’s attempt to interpret intent. Help it out, it’ll pay you back manyfold :)

yeah I agree with you KFS1, it’s sloppy and I would NEVER turn off the warningings in the compile line or in pragmas. But I think that it is far to ez to blame MS when apps don’t work right. But that’s another topic.

Today I got that same warning and it went like this:

Try{
call some web service
}
Catch(System.ArgumentException argex){

Call ws differently due to this exception.

}

Warning: argex is never used!!!

NOT TRUE MR COMPILER YOU!! :]

I don’t understand where you’re getting the “blame microsoft” bit from? Microsoft have had a development history of bad practices, and it has shown in many of their products, from Windows 3.11 to the security nightmares in Outlook and IE.

They’ve been improving, but you have to remember that history when you’re looking at publicised Microsoft code, such as header files and APIs. And therein is my point: Just because you can see warnings disabled in Microsoft files doesn’t mean its a good idea. Microsoft may have decided to turn it off because some really old, bad code behaves incredibly badly.

Take, for instance, Microsoft’s use of hungarian notation (int iIntValue). This was an exceedingly good idea when Microsoft went, more or less, out of their way to ignore various conventions and break others, and then wanted to turn off all the warnings that the compiler would throw out.

But when you use a strongly typed language like C++ or C# its incredibly pointless, and counterproductive.

Also – I don’t see you using argex in the above.

If you don’t make use of “argex”, you’re only interested in that type of exception, then don’t give it a name.

catch (System.ArgumentException) {
}

(Well, that looks a bit like java so it might not work, I don’t know what the java convention for that is, but you can do it in C++/C#)

oh I see you are talking about warnings M$ has turned off unbeknownst to you the API caller. for that you can definitely blame M$ ;]

I do think M$ apps get hacked more because there are more M$ apps to hack. Unix used to be hacked a lot too when it was the OS of choice not because it sucked but because it was a big target.

If MAC OS becomes the OS of choice some day I am 100% sure it will get hacked as well.

about the argex. you may be right. it was .NET and I didn’t think of that.

See how the app programer tends to screw up more? :]

I’ll try it tomorrow.

There are significantly more non-MS apps to be hacked if you are talking about online.

My reference to Microsoft here is only of their track record. Don’t take my word for it being bad, read “Writing Solid Code” – a <i>Microsoft</i> publication. Microsoft have a legacy of bad coding practices, which they have then evangelized to other developers in order to help sell their new API (MFC, ATL, WTL…) This includes their habbit of creating code which creates warnings, which they then disable and encourage others to do the same.

Part of the spirit behind C# is to create a language that prevents all of the little badnesses that various MS coders over the years have snuck into the MS codebase and created an evil legacy.

When I joined CRS, the server code was compiled with -Werror (count all warnings as error). This switch was followed by a long list of warnings which were subsequently turned off.

I’ve turned on -Wall and removed all of the exclusions, and then fixed all of the warnings it generated.

You’ll note how the servers are infinitely more stable? And how several of the major feature releases — STOs and buddies — have been rock solid.

The only involvement Microsoft has here in this topic, though, is that they encourage the habbit of turning off warnings, because their own code base is so riddled with legacy nastiness that its really their only option, but because some of this (header files etc) is very visible, other programmers pick up these habbits when developing their own Windows apps, and that’s where the problems occur.

That seems to be your point to, so I’m not sure why you’re arguing with me :)

I’m not arguing. Just a communications glitch. I haven’t really gottten that deep into all the stuff M$ does down low in the API and now I know. I certainly haven’t had to do what you have had to do. Although I have turned that -Werror switch on before for a face detection system I made that needed to be lighting fast and noticed that it was an insane amount of errors and so turned that switch back off again. Kudos for you to be persitent enough to go and actully fix all the errors. And yes it definitely shows. I’m a staunch defender of the RATs systems.
:]

Leave a Reply

Name and email address are required. Your email address will not be published.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <pre> <q cite=""> <s> <strike> <strong> 

%d bloggers like this: