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

Re: (prefix case terminators?) Re: alias with a parameter


> > i would have written ${1-} so -u can be used.
> I'm not following that at all:  -u where?

oopps. sorry i was too fast writting this. i meant nounset option.
i want my shell to yell at me as soon as i do something wrong so
my ~/.zshenv starts with

    setopt warncreateglobal nounset pipefail

> > also: i really think that using terminators as "continuation"
> > ease the code reading
> Entirely my opinion, but I find your example much MORE difficult to read.

Thanks for the feedback! As always, i think everyone comes with cultural
biases when it comes to coding style.  when i read

    case "$var" in
        (a*) write ;;
        (b*) something ;;
        (c*) cool ;;

i would like to see/write

    # in raku
    given $var {
        when /a*/ { write }
        when /b*/ { something }
        when /c*/ { cool }

    # in rc

    switch ($var) {
        case a* ; write
        case b* ; something
        case c* ; cool

and i used to actually read/write

    # zsh

    case "$var" {
        (a*) write
        (b*) something
        (c*) cool

because i though for many years that alternative syntax will replace the
old one the way zshcompsys replaced zshcompctl. but:

* it will never happen and i have to fall back with the classic syntax
  whenever i contribute to existing codebases.
* i started replace zsh by dash or rc in my scripts whenever the
  awesomeness of zsh doesn't help a lot (which means "lot of them")

so now i try to stick to POSIX syntax whenever it's easy to do it but i
try to adapt the coding style so the code keep staying attractive to me.

> > * it's easier to spot a different terminator than ;;
> For that, I'd put the terminator on a line by itself, which I would
> also do if the case branch was more than one line or if the case
> pattern was quite long, but with short patterns and the terminators
> all ;; it seems unnecessary.

indeed. what i just did is to remove a "useless new line".

        some code

        some code
    ;; (newcase)

both to me and the interpreter and the second one looks much more
natural to me. i'm not trying to convince anyone. i was really please to
read your feedback so i try to share my opinion on it.


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