Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: A tip: a technique to limit the # of global variables



IMO, just have internal vars start with '_', and use this:

| # do not complete functions/parameters that start with '_' or '.' unless explicitly matched
| zstyle ':completion:*' prefix-needed true

Greg

>>>>> On October 11, 2019 Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:

> On Fri, 11 Oct 2019 at 10:27, Roman Perepelitsa
> <roman.perepelitsa@xxxxxxxxx> wrote:
>> 
>> On Fri, Oct 11, 2019 at 10:21 AM Sebastian Gniazdowski
>> <sgniazdowski@xxxxxxxxx> wrote:
>> >
>> > Hello,
>> > when writing a plugin one often needs to keep a state during the Zsh
>> > session. To do this it is natural to use global parameters. However,
>> > when the number of the parameters grows one might want to limit it.
>> 
>> What are the advantages of having fewer global parameters? Why is it
>> better to have this:
>> 
>> typeset -gA PLGMAP=(foo 42 bar hello)
>> 
>> Than this:
>> 
>> typeset -gi PLGMAP_foo=42
>> typeset -g  PLGMAP_bar=hello
>> 
>> Roman.

> I think that it's about not "cluttering" the global namespace with the
> parameters. Zplugin had 37 global parameters, now it has only 16. Even
> a situation when a curious user enters print $ZPLG<TAB> and sees fewer
> entries is positive. This hides implementation, on the other hand, but
> one can decide what to hide when writing, i.e. what isn't meaningful
> for a curious user.

> PS. The message should go to zsh-users, hence I'm moving it there.

> --
> Sebastian Gniazdowski
> News: https://twitter.com/ZdharmaI
> IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
> Blog: http://zdharma.org



Messages sorted by: Reverse Date, Date, Thread, Author