zsh-workers
 help / color / mirror / code / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Bug with unset variables
Date: Wed, 25 Nov 2020 02:46:40 -0600	[thread overview]
Message-ID: <CAMP44s1RLs-ASYFyvjvj7eGta5_WnsXSH_8jAXf-Zufk569E1Q@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7Z+Brh5KfwUJakoaKfQ39WQbYoRELyfpu3YO1Ro-Ewvfg@mail.gmail.com>

On Mon, Nov 23, 2020 at 6:52 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> On Mon, Nov 23, 2020 at 3:39 PM Felipe Contreras
> <felipe.contreras@gmail.com> wrote:
> >
> > My argument is about the consistency from user's perspective.
>
> Consistent from what user's point of view?

Any user.

> One coming to zsh from
> other languages or one long familiar with zsh?  Because zsh
> development has consistently (ahem) sided with the latter.

Users can get accustomed to inconsistent behavior.

The fact that some users have become accustomed to X doesn't mean X is
consistent.

> > This is the example I gave to Roman, which went completely unresponded:
> >
> >   func () {
> >     [[ -n "$1" ]] && var=$1
> >     dosomething ${var-other}
> >   }
> >
> >   func () {
> >     typeset var
> >     [[ -n "$1" ]] && var=$1
> >     dosomething ${var-other}
> >   }
>
> In the first case, $var is a global, so the behavior of ${var-other}
> is unknown.  It's not possible to write deterministic code.

You are looking at the half of the picture that is irrelevant.

The behavior of "func foobar" is deterministic, and you know what it will do.

> In the second case, there's a knowable behavior of ${var-other}.  That
> behavior doesn't match your expectation, but it's well-defined.

Nobody is saying it's not well-defined, we are talking about *consistency*.

Only *one* change was added to B, and the behavior changed in *two* ways.

> To make the first function deterministic, it is necessary to write:
>
> func () {
>   unset var
>   [[ -n "$1" ]] && var=$1
>   dosomething ${var-other}
> }
>
> Whether one should expect "typeset var" to imply "unset" is how we
> ended up in this discussion.

The only difference from A to B is that B has a line that says
"declare 'var' as a local variable". That's a fact.

And the behavior of the function changes in two ways (other than what
was told to do). That's also a fact.

It is a fact that the code is doing more than what it was told to do.

If you have an operator called "declare_local_variable", and you do this:

  declare_local_variable var

You run the code, and you find that declare_local_variable does indeed
declare a local variable, but it *also* sets your cat on fire.

You investigate, and you find out the documentation clearly states
that declare_local_variable sets your cat on fire, so the behavior is
"well-defined". But it's not what it says on the tin.

Any normal person would expect such behavior to be enabled by:

  declare_local_variable var
  set_cat_on_fire

And not have to type:

  delcare_local_variable_but_dont_set_cat_on_fire var

Or worse:

  declare_local_variable var
  put_out_fire_from_cat

It doesn't matter how well explained it is in the documentation, or
how many people are accustomed to this behavior, it's still doing
*more* than one thing.

Now, you can call the fact that it's changing the behavior in more
than one way any way you want. When most operators in most languages
do one thing--and one thing only--and this operator does *two* things,
I call that inconsistent.

Maybe there's a better way to describe this fact. Maybe Git's notion
of logically separate changes [1] helps (e.g. you should not mix
whitespace cleanups with functional changes). But the fact is that in
virtually all languages (and bash and ksh) there's an idiom to declare
a local variable and *only* declare a local variable (not do anything
else).

Can we at least agree on that? In zsh typeset does *two* things.

Cheers.

[1] https://git-scm.com/docs/SubmittingPatches

-- 
Felipe Contreras


  reply	other threads:[~2020-11-25  8:47 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-11 15:57 Felipe Contreras
2020-11-11 16:13 ` Roman Perepelitsa
2020-11-11 16:56   ` Felipe Contreras
2020-11-11 17:02     ` Roman Perepelitsa
2020-11-11 18:03       ` Felipe Contreras
2020-11-11 18:16         ` Roman Perepelitsa
2020-11-11 20:42           ` Felipe Contreras
2020-11-12  0:20             ` Mikael Magnusson
2020-11-12  1:10               ` Felipe Contreras
2020-11-12  8:45             ` Roman Perepelitsa
2020-11-12 10:47               ` Peter Stephenson
2020-11-12 18:48                 ` Bart Schaefer
2020-11-12 19:49                 ` Felipe Contreras
2020-11-12 18:46               ` Felipe Contreras
2020-11-12 19:10                 ` Roman Perepelitsa
2020-11-12 21:08                   ` Felipe Contreras
2020-11-13  8:51                     ` Roman Perepelitsa
2020-11-14  0:52                       ` Felipe Contreras
2020-11-14  5:41                         ` Roman Perepelitsa
2020-11-16 19:41                           ` Felipe Contreras
2020-11-16 20:22                             ` Roman Perepelitsa
2020-11-17 20:28                               ` Felipe Contreras
2020-11-18 22:45                                 ` Daniel Shahaf
2020-11-22  1:20                                   ` Felipe Contreras
2020-11-23  4:00                                     ` Daniel Shahaf
2020-11-23  6:18                                       ` Felipe Contreras
2020-11-19  2:59                                 ` Bart Schaefer
2020-11-22  1:50                                   ` Felipe Contreras
2020-11-17 20:54                             ` Bart Schaefer
2020-11-22  1:49                               ` Felipe Contreras
2020-11-23  6:48                                 ` Bart Schaefer
2020-11-23  7:26                                   ` Felipe Contreras
2020-11-23 20:26                                     ` Bart Schaefer
2020-11-23 23:39                                       ` Felipe Contreras
2020-11-24  0:52                                         ` Bart Schaefer
2020-11-25  8:46                                           ` Felipe Contreras [this message]
2020-11-27 15:44                                             ` Daniel Shahaf
2020-11-27 20:49                                               ` Felipe Contreras
2020-11-27 20:59                                                 ` Daniel Shahaf
2020-11-27 21:33                                                   ` Bart Schaefer
2020-11-27 23:37                                                     ` Daniel Shahaf
2020-11-27 23:45                                                       ` Bart Schaefer
2020-11-28  0:24                                                       ` Bart Schaefer
2020-11-28  7:32                                                         ` Bart Schaefer
2020-11-28 12:05                                                         ` Felipe Contreras
2020-11-12 19:26                 ` Bart Schaefer
2020-11-12 21:48                   ` Felipe Contreras
2020-11-13 22:17                     ` Bart Schaefer
2020-11-14  0:58                       ` Felipe Contreras
2020-11-11 18:36         ` Bart Schaefer
2020-11-11 21:08           ` Felipe Contreras
2020-11-11 17:02     ` Peter Stephenson
2020-11-11 18:05       ` Felipe Contreras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMP44s1RLs-ASYFyvjvj7eGta5_WnsXSH_8jAXf-Zufk569E1Q@mail.gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).