[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: if vs. when vs. and: style question

From: Emanuel Berg
Subject: Re: if vs. when vs. and: style question
Date: Tue, 24 Mar 2015 00:19:11 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Marcin Borkowski <> writes:

> assuming (e1) and (e2) are some expressions, all
> three forms:
> (if (e1) (e2))
> (when (e1) (e2))
> (and (e1) (e2))
> are semantically equivalent. Which one is better
> style (and when)? I would guess that =when= is
> better iff (e2) is a =progn= (since we can drop the
> =progn= altogether, and this seems to be the point
> of =when=), and =and= might be considered better
> (well, maybe) by some people when both (e1) and (e2)
> are very short (though I personally would avoid
> that, since =if= seems easier for a human to
> understand at a first glance). Am I right?

I don't think `and' should be used to evaluate and
return =stuff= (I mean evaluate as in side-effects),
rather, use it as the familiar gate of binary logic,
thought here it isn't binary but can be of whatever
arity. But no rule without exceptions, of course...

To me `if' + `progn' is better than `when' because
I am more familiar with those constructs and also, if
I ever have to change something, which happens all the
time, I will not have to bother thinking "is this
still a `progn'? if it isn't, should I remove the
`when'? if I don't, will anyone wonder why I used
a `when' instead of `if'? Less thinking, more coding
I'd say with plain `if' and then whatever is needed
from there to get it done.

But I can't say I'd hit the ceiling if anyone used
`when', with or without the need for a `progn' in the
equivalent `if' clause. Using `and' for no reason I'd
consider worse because that could be really confusing.

underground experts united

reply via email to

[Prev in Thread] Current Thread [Next in Thread]