[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: giving `setq-local' the same signature as `setq'
From: |
Drew Adams |
Subject: |
RE: giving `setq-local' the same signature as `setq' |
Date: |
Thu, 19 Mar 2015 10:25:19 -0700 (PDT) |
> > You can do the same for `let*', if you like:
> > (let ((foo fooval))
> > (let ((phlop phlopval))
> > (let ((toto totoval))
> > ...)))
>
> Now you've just lead yourself into a trap. This is similar to
> one-var-per-setq:
> (let* ((foo fooval)
> (phlop phlopval)
> (toto totoval))
> ...)
No, one var per `let' would be as I showed it - 3 `let's for 3 bindings.
Using `let*' with multiple vars is analogous to using `setq' with multiple
vars. `setq' assigns and `let*' binds, but they both let you give values
to multiple variables. Or to only one variable at a time - your choice.
> This is similar to multi-var-per-setq:
> (let* (foo fooval
> phlop phlopval
> toto totoval)
> ...)
No, that is simply malformed code.
> >> It also gives an anchor to quickly navigate to the variable
> >> to get its value.
> >
> > How so? Please elaborate.
>
> With C-M-n and C-M-p you can navigate to the big fat paren by which the
> variable resides (after setq).
OK.
> >> In a setq list of 10 items, by item 5 it is already unclear which is the
> >> variable and which is the value. In my opinion, it's not worth
> >> complicating the code maintenance just to save a few chars.
> >
> > This is why it is good that you have the choice.
>
> You're wrong here. I don't have the choice. Just yesterday I was debugging
> my AUCTEX config. It wasn't pleasant to navigate 5-variable setq
> statements, some of which took the whole page.
That problem is independent of this discussion, unless you are referring
to the convenience of your using `C-M-p' to move to individual assignments.
One can write bad code, with 473 `setq's in a row or with a single `setq'
that has 473 assignments. Being able to group assignments in a single
`setq' does not require anyone to use many assignments in a row.
> > I find it clearer to let `setq' do the grouping, instead of implicit or
> > explicit `progn'. But I put each var & value pair on a separate line:
> >
> > (setq foo fooval
> > phlop phlopval ; Maybe this one needs a comment.
> > toto totoval)
> >
> > I don't do this to save characters (e.g. for typing). I do it to make
> > the code clearer and maintenance less error prone and easier. For me,
> > at least.
>
> Imagine that you want to comment out `phlop phlopval', which is a
> multi-line statement. If it was bounded by parens, you could do it in an
> easy and error-free way. Otherwise, you have to manually select the region.
Actually, `phlop phlopval' is a single line, and can be commented out simply.
But I take your point. Yes, the style I prefer can mean extra typing.
To me it's worth it, for the sake of clearer code (IMO). But you don't
need to write code the way I prefer. And you don't need to maintain my
code.
If you work with a team to create and maintain code, then it can help to
decide what the team prefers, in terms of coding style. That's not
limited to this discussion about `setq'.
What is germain to this discussion is that different teams can choose
what they want, wrt using separate `setq's for multiple assignments.
What you propose is that for the sake of "consistency" there must be,
in effect, only one team: the choice should be made for Emacs Lisp as
a whole, instead of letting those who use it decide.
I prefer that Emacs Lisp be consistent with, well, LISP in this regard.
Multiple assignments for `setq' have been around since the 60s in Lisp
(but no, they were not in Lisp 1.5). At least two of us like it that way.
- giving `setq-local' the same signature as `setq', Jordon Biondo, 2015/03/18
- Re: giving `setq-local' the same signature as `setq', Stefan Monnier, 2015/03/18
- Re: giving `setq-local' the same signature as `setq', Richard Stallman, 2015/03/19
- Re: giving `setq-local' the same signature as `setq', Jordon Biondo, 2015/03/19
- RE: giving `setq-local' the same signature as `setq', Drew Adams, 2015/03/19
- Re: giving `setq-local' the same signature as `setq', Oleh Krehel, 2015/03/19
- RE: giving `setq-local' the same signature as `setq', Drew Adams, 2015/03/19
- Re: giving `setq-local' the same signature as `setq', Oleh Krehel, 2015/03/19
- RE: giving `setq-local' the same signature as `setq',
Drew Adams <=