[Python-ideas] If branch merging

Andrew Barnert abarnert at yahoo.com
Mon Jun 8 04:44:24 CEST 2015


On Jun 7, 2015, at 19:18, Steven D'Aprano <steve at pearwood.info> wrote:
> 
> As you read down the left hand column, you see "if a == b" and you can 
> mentally say "that block only occurs if a == b" and move on. But when 
> you get to the alif block, you have to stop reading forward and go back 
> up to understand whether it runs or not.

Thanks for putting it this way. I knew there was a more fundamental problem, but I couldn't see it until your message.

The proposal is closely analogous to trying to define a Boolean predicate in a list GUI instead of a tree. And that means it has the exact same problems that the early MS Office and Visual C++ Find in File dialogs had. Besides the obvious fact that mixing conjunctions and disjunctions without grouping (via nesting) is insufficiently powerful for many real-life predicates (which is exactly why the proposal needs the assignment-like add-on), even in the simple cases where it works, it's not readable (which is why the examples had at least one mistake, and at least one person misread one of the other examples). If your eye has to travel back upwards to the last also, but the alsos are flush against the left with the elifs instead of nested differently, you have to make an effort to parse each clause in your head, which is not true for a flat chain of elifs.

At any rate, as two people (I think Stephen and Nick) suggested, the second half of the proposal (the as-like binding) nearly eliminates the need for the first half, and doesn't have the same problem. The biggest problem it has is that you want the same syntax in other places besides if conditions, which is a better problem to have.


More information about the Python-ideas mailing list