[racket] Boolean expressions [Was: static variables question]

From: Gary Baumgartner (gfb at cs.toronto.edu)
Date: Sun Feb 19 01:30:04 EST 2012

On Sat, Feb 18, 2012 at 09:02:41PM -0500, Stephen Bloch wrote:
> I see a lot of my students doing this -- in whatever language -- because they think of Booleans as a way to decide which of two things to DO, rather than as legitimate values in their own right.  In fact, the whole world of expressions is a bit of a foreign country -- a sort of "adjunct" to the more-legitimate world of statements.
> if (blah == true) {
>    return true;
>    }
> else {
>   return false;
>   }

Yes, I talked with my 3rd-year PL students about this, with examples in Racket.
 Then an assignment had them take what I called "Π-expressions [s-expressions
 representing Python code, spit out by a little Python programm walking an AST
 produced by complier.ast], and find exactly those two style issues above [and
 also string literals "True"/"False", which 1st-years are using for booleans,
 and then it occurred to us that identifier 'true' is a common problem due to
 Python's not quite fully lexical scoping]. Yet some students still used these
 forms in earlier parts of the assignment and didn't notice nor remember and
 go back [at least the ones I trust not to claim that instead of laziness]!

> For those of us forced to teach in Java, CheckStyle has two modules, SimplifyBooleanExpression and SimplifyBooleanReturn, that catch things like this.
> Stephen Bloch
> sbloch at adelphi.edu

Python's PEP 8 style guide mentions the comparison problem, but only "== True"
 and "is True": nothing about inequality nor false literal, and not selection.


On a more productive note: in Racket code I define and use 'implies' a lot,
 often conjoined, for predicates. It's mainly of declarative value, which is
 perhaps why it's uncommon in implementation despite how common it is in
 specification. And for boolean expressions in general I also use 'neither'.
 Are these something that others [would] use and so could be added to Racket's

Posted on the users mailing list.