May-05-2021, 08:11 PM
(This post was last modified: May-05-2021, 08:11 PM by deanhystad.)
There are problems with your example and your references. The main problem is fall through does something completely different in C++ than what you propose. In C/C++ the case statement has fall through as a built in feature, and the fall through tag tells the compiler to not issue a warning. If I were proposing a Python fall through feature I might start by referencing that it adds a "C case" like fall through behavior to Python if/else/elif.
Another problem is that your example does not read well at all, even now that I think I understand what you are trying to do. I would do your example like this:
However I do not think fallthrough reads well in an if statement. I also don't think you can come up with many examples where using fallthrough is better than reorganizing the if logic. Unless you can come up with some better examples I don't think you'll gain much support.
EDIT
A lot of discussion snuck in while I was writing the above. Are you thinking of this fall through as only used in a ternary operation? If so, your example really stinks. That is not what I was getting from your examples at all.
Another problem is that your example does not read well at all, even now that I think I understand what you are trying to do. I would do your example like this:
def get_args(): if len(sys.argv) > 1 and sys.argv[1]: return int(sys.argv[1]) print("expected a number as an arg") exit(1)The need for the C++ [fallthrough] attribute is an indictment of what a bad idea fall through is in a case statement. Millions of hours have been wasted tracking down bugs caused by this "feature". If case fall through worked as you propose, requiring an explicit statement to make it happen, it would have caused a lot fewer problems and it would make the code a lot easier to read.
However I do not think fallthrough reads well in an if statement. I also don't think you can come up with many examples where using fallthrough is better than reorganizing the if logic. Unless you can come up with some better examples I don't think you'll gain much support.
EDIT
A lot of discussion snuck in while I was writing the above. Are you thinking of this fall through as only used in a ternary operation? If so, your example really stinks. That is not what I was getting from your examples at all.