bug-bash
[Top][All Lists]
Advanced

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

Re: Are there any plans for more readable, modern syntaxes for If statem


From: Robert Elz
Subject: Re: Are there any plans for more readable, modern syntaxes for If statements?
Date: Fri, 13 Mar 2020 21:52:59 +0700

    Date:        Fri, 13 Mar 2020 06:59:56 -0500
    From:        John McKown <john.archie.mckown@gmail.com>
    Message-ID:  
<CAAJSdjidSYg1yoWC7UbbLUUDF3ug9ekDtkOP7Er-JOjrLoDssQ@mail.gmail.com>


  | I do things like:
  |
  | test <some relational test> && { true_command1;true_command2; : ; } || {
  | false_command1; false_command2; false_command3; }

That's OK, and at times I have been tempted that way, but it really is
easier to just do

        if <some relational test>
        then
                true_command1
                true_command2
        else
                false_command1
                false_command2
                false_command3
        fi

Not only do you not need to remember that the ':' command (or "true") is
important, but the exit status of all of this will be whichever of
true_command2 or false_command3 that was executed, which can be
used in other tests later.

The cost of typing a few extra words to make things clearer, and having
the code not look quite so "look what I can do ma" (ie: less "cool") is
worth it to be more clear, and less likely to have bugs.

kre




reply via email to

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