Dr John Stockton wrote:
> JRS: In article <3dd97c9c$...@news.bluewin.ch>, seen in
> news:comp.lang.pascal.borland, Vinzent Hoefler
> <JeLlyFish.softw...@gmx.net> posted at Tue, 19 Nov 2002 00:49:18 :-
> >Dr John Stockton <s...@merlyn.demon.co.uk> wrote:
> >>You should (almost?) never write X = true or X = false - use X
> >>or not X instead.
> >Remove the part in the parentheses. :-) Pascal *knows* booleans and
> >handles them correctly, so there's no reason to use them incorrectly.
> Now that I have time to think of examples, consider the cases of :
> Using for example the procedure FillChar with an error in its Count, it
> is possible for an innocent nearby boolean to have its value
> accidentally set to the value of FillChar's 3rd parameter. Tests for
> exactly false & true, or one for <=true, could help.
> Sometimes, in development of a program, there may be what should end up
> as if X=Y then ... If the code giving Y were unreliable, then to
> test the conditional code for a case where Y *ought* to be false, one
> could change X=Y to X=false - that's less likely to confuse later than
> just using X, specifically because it looks funny.
> An allegedly boolean function supplied in a DLL written in another
> language, which may give a malformed boolean - to test for that fault,
> one could do
> X := function(Y) ;
> if (X=true) or (X=false) then Write('OK') else Write('ERROR') ;
> A boolean set by typecasting an enumerated type, type X = (red, green),
> for supply to a routine expecting a boolean. If the type can be changed
> to (red, amber, green), then a test against a boolean literal could be
> useful.
> A routine intended to be a severe test for debugging staff; it is
> embedded in a unit which has in its interface
> const true : boolean = 0=1 ; false : boolean = 0=0 ;
> Since true is an identifier and not a reserved word, its value is not
> necessarily boolean(1). Another test would be to sneak in
> type boolean = (true, false)
> since boolean is not reserved either.
> H'mm - in case boovar of true:; false:; else filemode := 0 end;
> I wonder whether code to set filemode is generated? I cannot test at
> present.
> Anyway, the easiest way of explaining in writing that one should not
> write "X = true" involves writing 'X = true'. We do that quite often
> here.
> --
> ? John Stockton, Surrey, UK. j...@merlyn.demon.co.uk Turnpike v4.00 MIME. ?
> Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
> Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
> Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)