A Hint About Warnings

Compiler Hints and Warnings are an important indicator of the quality of the code you are compiling.  It dismays me that I have often seen a ton of compiler warnings on commercial component suites when I compile them.  It makes you question the care taken when writing the code.

Compiler Hints and Warnings should be treated as potential coding errors.  Each one should be addressed to ensure it will not cause a errant behaviour at run-time, and the code in question is properly structured.  It is good to see I am not alone in this view.  So take a hint (pun intended), and clean up your hints and warnings.

Sometimes this isn’t so easy.  For instance, if  component requires a given unit, for example Vcl.ImgList, as the TcxCustomTreeList does, it will add the unit to the uses clause automatically.  You might then get a  warning like  W1000 Symbol ‘TImageIndex’ is deprecated: ‘Use System.UITypes.TImageIndex’. Unfortunately, adding System.UITypes and removing Vcl.ImgList just results in the IDE re-injecting Vcl.ImgList back into the uses clause and reporting the same warning.  I really don’t want to turn off this warning globally so the best option that I know of is to add {$WARN SYMBOL_DEPRECATED OFF} to the interface section of the unit in question.  While this solution may not be ideal, it allowed me to “address” the warning so new compiler hints and warnings that may actually indicate a flaw in the code do not get lost in a multitude of messages.  Clean code is less likely to be flawed code.

5 Responses to “A Hint About Warnings”

  1. Bruce McGee Says:

    Completely agree.

    Whenever possible, I avoid third party hints and warnings by compiling my apps against their DCUs instead of the source code.

  2. Fronzel Neekburm Says:

    It’s horrible when you work on a legacy project where no one cared about hints and warnings, even like “Method result may be undefined!”. You just get a bunch (dozens, hundreds) of warnings, hints and esoteric recommendations.

    Wouldn’t it be great to filter by type (Warning, Error, Hint, …) and Unit or even namespace (*cough*)?

  3. IanB Says:

    I totally agree - I obsessively get rid of all hints and warnings; to me the code is not compiling ‘correctly’ if you have any remaining and, nine times out of ten they are a glaring finger pointing out something horrible going on in the background. :)

  4. Taz Higgins Says:

    Keeping hints and warnings out of your code means you don’t miss new ones. This keeps your code good and clean and reduces problems

  5. Stefan Glienke Says:

    A cent for every time that someone asked me “hey, can you help me find this or that bug?” and it turned out that he should have checked the compiler messages to find the error on his own but “did not see it amongst the dozen of other messages” … /facepalm

Leave a Reply