[BLACKBOX] Re [BLACKBOX] Seasons Greetings from Linuxland

From: [at]} <Les>
Date: Mon, 27 Dec 2010 11:05:01 +0000

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

"The ugliness of a construct usually appears in combination with other
language features. In C, we may write, for example, x+++++y, a riddle rather
than an expression, and a challenge for a sophisticated parser!

Wirth's line x+++++y won't compile with the only C compiler I have
available at the moment.

When
   z = 0;
   x = 1;
   y = 1;

The expressions

z = x++ + y++;
z = x++ + ++y; Wirth's example
z = ++x + y++;
z = ++x + ++y;

yield values of 2, 3, 3, 4 respectively.

As Chris Burrow' said, "C just gives you so many different wonderful
ways to shoot yourself in the foot". C programmers are not obliged to
write code like this. They are free to spread the code over several
lines. They choose not to do so preferring to rely on 'C idioms'.

The problem is that in order to understand what the programmer intended
the result of this expression should be, the reader has to evaluate the
expression according to the precedence rules for operators in C. All
this to save two Linefeeds, two characters and two semicolons.

Pascal/Modula/Oberon programmers are not entirely free of this approach.

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.

It is an article of faith for 'Oberoners' that Wirthian languages are
superior to 'C' type languages and that their use makes it easier to
write bug free code.

Look at http://acm.uva.es/problemset/statsjudge2.php for some empirical
evidence about this.

The lines starting AC (Accepted, right answer, correctly presented), PE
(Presentation error) and WA (Wrong answer) are the ones to pay attention to.

More details of the nature of the programs and the meaning of the other
codes at the start of a line can be found at
http://www.cs.sunysb.edu/~skiena/392/ and the links provided. There are
some pdf files of lectures which can be downloaded; 'Week 1' has some
details.

The kinds of programs upon which these results are based do not cover
the full spectrum of programs that Wirth had in mind in designing Modula
2 and Oberon. Nonetheless the results are interesting and the sample
size is so large that the sampling error is likely to be very small.

Les May


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-324746014_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwICJUaGUgdWdsaW5lc3Mgb2YgYSBjb25zdHJ1Y3Qg
dXN1YWxseSBhcHBlYXJzIGluIGNvbWJpbmF0aW9uIHdpdGggb3RoZXJccGFyDQpsYW5ndWFnZSBm
ZWF0dXJlcy4gSW4gQywgd2UgbWF5IHdyaXRlLCBmb3IgZXhhbXBsZSwgeCsrKysreSwgYSByaWRk
bGUgcmF0aGVyXHBhcg0KdGhhbiBhbiBleHByZXNzaW9uLCBhbmQgYSBjaGFsbGVuZ2UgZm9yIGEg
c29waGlzdGljYXRlZCBwYXJzZXIhXHBhcg0KXHBhcg0KV2lydGgncyBsaW5lIHgrKysrK3kgd29u
J3QgY29tcGlsZSB3aXRoIHRoZSBvbmx5IEMgY29tcGlsZXIgSSBoYXZlIFxwYXINCmF2YWlsYWJs
ZSBhdCB0aGUgbW9tZW50LlxwYXINClxwYXINCldoZW5ccGFyDQogICB6ID0gMDtccGFyDQog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