Skip navigation

School Of Redundancy School

I watched a short presentation on subtext the other day, which focused on the difficulty with reading Boolean expressions. Under it’s influence, I made a slightly more verbose, nested expression out of a simpler one:

    if opts.p and opts.u:
        pass
    else:
        if opts.p or opts.u:
            parser.error("please specify a user and pass")

Where’s the wisdom in that? I think it lay in the else, which explicitly subordinates the second conditional to the first. I could have made it:

    if not (opts.p and opts.u):
        if opts.p or opts.u:
            parser.error("please specify a user and pass")

I hate parenthesis in Python conditionals — don’t know why.

Advertisements

Post a Comment

You must be logged in to post a comment.
%d bloggers like this: