help-gnu-emacs
[Top][All Lists]
Advanced

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

RE: [External] : Re: operations on path lists


From: Drew Adams
Subject: RE: [External] : Re: operations on path lists
Date: Wed, 8 Feb 2023 02:48:12 +0000

> Let us look at `when' little:
> 
> - you place `when' when you need `nil' as last resort

I don't.  I do just the opposite.  I use `when'
and `unless' only when the code doesn't use/depend
on the return value.  (I'm guessing that's what
you meant by needing nil as a last resort, though
they always return nil.)

Before Elisp borrowed `when' and `unless' from
other Lisps (e.g. Common Lisp), the idiom,
especially for a single condition, was to use `or'
in (or condition do-something) instead of `unless',
and likewise for `and' and `when'.  That that,
usually at top level in a function body.  I still
have some of those `or' sexps, as does standard
Emacs code.

> - what if you change your mind in future and wish to modify function
>   to return "" as last resort?

I don't use `when' for its return value (which,
again, is always nil).  I might use `if' or `and'
(or `case' or `cond'...).

>   you have to restructure it.

Yes, I mentioned this in my reply to EB yesterday.
That's the advantage of doing what you prefer to
do, e.g., use `cond'.  At the cost of losing any
indication of the meaning/intention of any given
`cond' clause and the return value.

`cond' is a very versatile control structure that,
consequently, gives you little means to express
intention, other than with comments.  One `cond'
clause looks like any other - could do or mean,
and return, anything at all.

> - without parenthesis highlighting sometimes it becomes very difficult
>   to understand what did `if' author intended to say?

I don't grok that.  But then, I don't use `if'
unless there are both a then and an else part.
I take the time to rewrite, yes, as needed,
to communicate to myself (as reader) just what
the code means to do.

> - multiple `if' statements one ofter other do not look nice and
>   readable,

That's not very common IMO.  Maybe a couple
levels sometimes.

> Some people write long functions, if, then, when, it is not nicely
> indented, restructuring is difficult, what did author want to say?
> Hard to think of it.

Probably depends on what you're used to.  But
if each of `if', `when', `unless', `and', and
`or' is used in a way that says what's intended
then it's pretty easy to understand.  There's
no guessing about whether the return value of
a given `if' is used etc.  (For me, it always
is, or I wouldn't use `if'.)

reply via email to

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