Python Forum
feature request: ternary fallthroughs
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
feature request: ternary fallthroughs
#16
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:
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.
Reply


Messages In This Thread
feature request: ternary fallthroughs - by rexrf - May-05-2021, 12:57 PM
RE: feature request: ternary fallthroughs - by deanhystad - May-05-2021, 08:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python on a ternary computer Skaperen 0 1,615 Jun-20-2020, 02:21 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020