Re: [BLACKBOX] Re [BLACKBOX] Seasons Greetings from Linuxland

From: [at]} <Chris>
Date: Tue, 28 Dec 2010 10:24:43 +1030

----boundary-LibPST-iamunique-619680857_-_-
Content-type: text/plain

> -----Original Message-----
> From: BlackBox [mailto:BLACKBOX{([at]})nowhere.xy
> Sent: Monday, 27 December 2010 9:35 PM
> To: BLACKBOX{([at]})nowhere.xy
> Subject: [BLACKBOX] Re [BLACKBOX] Seasons Greetings from Linuxland
>
>
> The code
>
> PROCEDURE IsDigit(ch: CHAR): BOOLEAN;
> BEGIN
> RETURN (ch <= '9') & (ch >= '0')
> END IsDigit;
>
> is regarded as good 'style'.
>
> Yet it suffers from the same problem as the C code above. To
> understand
> what the programmer intended the reader has to evaluate what
> follows the
> RETURN.
>
> The code
>
> PROCEDURE IsDigit(ch: CHAR): BOOLEAN;
> VAR
> b: BOOLEAN;
> BEGIN
> b := FALSE;
> IF (ch >= '0') & (ch <='9') THEN
> b := TRUE;
> END;
> RETURN b;
> END IsDigit;
>
> is regarded as bad 'style', but the intention of the programmer is
> more easily understood.
>

To understand what the programmer intended in your example he has to
evaluate what follows the IF statement so what is the difference?
Unfortunately, he then also has to analyze an additional three statements in
order to ascertain what the procedure is actually doing.

I suspect you are alluding to the fact that some programmers do not have a
good understanding of Boolean algebra.

The following hypothetical examples are intended to show what a programmer
could concoct if he has muddled thinking regarding boolean logic and is a
newcomer to languages with a boolean data type like Pascal, Modula-2 and
Oberon. The statements are all supposed to be equivalent (I guess if any
aren't I have managed to prove a point!). Draw your own conclusions ...

----------------------

IF (a # FALSE) THEN
  b := FALSE
ELSE
  IF (a = FALSE) THEN
    b := TRUE
  END
END;

----------------------

IF (a # FALSE) THEN
  b := FALSE
ELSIF (a = FALSE) THEN
  b := TRUE
END;

----------------------

IF (a = TRUE) THEN
  b := FALSE
ELSIF (a = FALSE) THEN
  b := TRUE
END;

----------------------

IF a THEN
  b := FALSE
ELSIF ~A THEN
  b := TRUE
END;

----------------------

IF a THEN
  b := FALSE
ELSE
  b := TRUE
END;

----------------------

b := TRUE;
IF a THEN b := FALSE END;

----------------------

b := ~a;

----------------------

Regards,
Chris

Chris Burrows
CFB Software
http://www.cfbsoftware.com


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-619680857_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwID4gLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS1c
cGFyDQo+IEZyb206IEJsYWNrQm94IFttYWlsdG86QkxBQ0tCT1hATElTVFMuT0JFUk9OLkNIXSBP
biBCZWhhbGYgT2YgTGVzIE1heVxwYXINCj4gU2VudDogTW9uZGF5LCAyNyBEZWNlbWJlciAyMDEw
IDk6MzUgUE1ccGFyDQo+IFRvOiBCTEFDS0JPWEBMSVNUUy5PQkVST04uQ0hccGFyDQo+IFN1Ympl
Y3Q6IFtCTEFDS0JPWF0gUmUgW0JMQUNLQk9YXSBTZWFzb25zIEdyZWV0aW5ncyBmcm9tIExpbnV4
bGFuZFxwYXINCj4gXHBhcg0KPiBccGFyDQo+IFRoZSBjb2RlXHBhcg0KPiBccGFyDQo+IFBST0NF
RFVSRSBJc0RpZ2l0KGNoOiBDSEFSKTogQk9PTEVBTjtccGFyDQo+IE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S0tLS0tLS1ccGFyDQpccGFyDQpSZWdhcmRzLFxwYXINCkNocmlzXHBhcg0KXHBhcg0KQ2hy
aXMgQnVycm93c1xwYXINCkNGQiBTb2Z0d2FyZVxwYXINCmh0dHA6Ly93d3cuY2Zic29mdHdhcmUu
Y29tXHBhcg0KXHBhcg0KXHBhcg0KLS0tLVxwYXINClRvIHVuc3Vic2NyaWJlLCBzZW5kIGEgbWVz
c2FnZSB3aXRoIGJvZHkgIlNJR05PRkYgQkxBQ0tCT1giIHRvIExJU1RTRVJWQExJU1RTLk9CRVJP
Ti5DSFxwYXINCn0=
----boundary-LibPST-iamunique-619680857_-_---
Received on Tue Dec 28 2010 - 00:54:43 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:26 UTC