On 24 Sep 2004 at 16:50, Frank Heckenbach wrote:
Prof A Olowofoyeku (The African Chief) wrote:
On 24 Sep 2004 at 6:27, CBFalconer wrote:
[....]
This brings up the more general subject of the attitude to warnings. Pascal is not C. In C many, if not most, warnings indicate a serious situation where the probability of bad code is high, if not certain. Pascal has so many more internal checks that warnings tend to be just that, and the probability that the code does what is intended is much higher.
Thus the Pascal programmer should be prepared to evaluate and accept warnings on compilation. This attitude is probably not fatal, as it would be in C. In particular an unused parameter falls into this classification.
May I suggest another approach? Both Delphi and FreePascal have "warnings" and "hints". Warnings are for serious things that can hide bugs, while hints are for less serious things. Can we assign some of these things to "hints", and then have a switch to turn hinting on and off?
I'm not sure this would really help. In the end, what would it mean?
It means that not every problem generates a warning, since some will only generate hints. It also means that, in the light of this long thread, one can turn off hints, while leaving warnings, and hopefully provide a solution to those who sometimes want warnings and sometimes don't (assuming they will be satisfied with hints instead of warnings).
Is it ok to compile with one hint per 100 lines of code?
That is a matter for the programmer. Programmer emptor. In my experience, Delphi generates hints when the code is not dangerous, but might be inefficient or superfluous (as in my examples). So, a million hints are perfectly fine - your program will not do anything unexpected - but it might be wasting memory, or otherwise be doing unnecessary things, hence running (marginally?) slower, or getting unnecessary (marginal?) bloat in the size of your executables. I tend to ignore hints - but sometimes it is easier to just remove the superfluous code so that the hint goes away.
When you say, warnings are for things that can hide bugs, the same goes for these hints.
Not necessarily. I have seen so many redundant assignments that generate hints that do not hide any bugs (such as those in my example). I am yet to see only a generated hint in a situation where there is a possible bug (in the sense of the program possibly behaving incorrectly, crashing or otherwise behaving unexpectedly).
Not using a parameter usually indicates a bug
Agreed.
-- it only makes sense in special situations (fixed parameter forms).
If callback routines are an example of this, then yes.
Example;
function bar : integer; begin writeln ('bar'); end;
Generates this, when compiled with Delphi: E:\temp\warn.pas(6) Warning: Return value of function 'bar' might be undefined
Well, according to the standards this is an error even. I don't see any reason in weakening this to a warning.
Presumably it will not generate an error in BP/Delphi mode? (else you lose compatibility). In Delphi mode it should only generate a warning.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/