Can you point us to an example in another language that does this? I've not seen it before, so must be unfamiliar with those languages.
feature request: ternary fallthroughs
feature request: ternary fallthroughs
|
May-06-2021, 08:01 AM
(May-06-2021, 07:37 AM)ndc85430 Wrote: Can you point us to an example in another language that does this? I've not seen it before, so must be unfamiliar with those languages. I'm not sure if it's worth repeating at this point, as i've run this basic principle into the ground... here are the facts: this is a feature that is genuinely implemented and used...some people just have a hard time understanding. please read my comments in the full example after reading this: https://stackoverflow.com/questions/4082...ugh-or-not.
May-06-2021, 08:52 AM
(This post was last modified: May-06-2021, 08:53 AM by Gribouillis.)
I vote against the fallthrough because of
import this .Readability counts! In Python when you have this structure if ...: ... else: ...you can be 100% certain that if the program runs the 'if' part, it doesn't run the 'else' part. Changing this would force the reader to examine every 'if' block to the tiniest detail. It breaks the clarity that made this language's success. No, No, No!
May-06-2021, 09:05 AM
(May-06-2021, 08:52 AM)Gribouillis Wrote: I vote against the fallthrough because of Another fool blinded by pep 8. "A foolish consistency is the hobgoblin of little minds" the language evolves for a reason. because beautiful is better than ugly. it's why we have python2, python3, and eventually python4. you can quote the docs all you want, I've been hacking since windows NT 3. change. is. inevitable. kiddo. (May-06-2021, 09:05 AM)rexrf Wrote: [quote="Gribouillis" pid='141725' dateline='1620291147'] Another fool blinded by pep 8. it is a guide, not a law. "A foolish consistency is the hobgoblin of little minds" the language evolves for a reason. because beautiful is better than ugly. it's why we have python2, python3, and eventually python4. you can quote the docs all you want, I've been hacking since windows NT 3. change. is. inevitable. kiddo.
May-06-2021, 09:29 AM
(This post was last modified: May-06-2021, 09:32 AM by Gribouillis.)
rexrf Wrote:A foolish consistency is the hobgoblin of little mindsWe don't have to take every quotation as an enlightening thought. That one was coined by Ralph Waldo Emerson, a leading figure of the transcendentalism movement, a romantic american philosophical movement in the 19th century. It is not particularly my cup of tea. There are very good reasons for the tremendous success of the Python language. To me, CLARITY is one of the main points. Let us not through away the best part of the language.
May-06-2021, 09:38 AM
(May-06-2021, 09:29 AM)Gribouillis Wrote:rexrf Wrote:A foolish consistency is the hobgoblin of little mindsWe don't have to take every quotation as an enlightening thought. That one was coined by Ralph Waldo Emerson, a leading figure of the transcendentalism movement, a romantic american philosophical movement in the 19th century. It is not particularly my cup of tea. My point is that taking every quotation literally is the flaw in your logic. Things change. things you believe to be true might suddenly become untrue. You talk about readability and that is my main point. A one line eval with additional flow control is a no brainer. It is beautiful and it is readable. you just havent seen it before.
May-06-2021, 09:42 AM
it reminds me of an old boss who hated python doggedly. I once tried to explain list / dictionary comprehensions to him and he just couldn't make heads or tails of it. despite the fact it has been implemented and enjoyed and well documented.
Fallthroughs make sense. they exist. you can read the docs. You're just being a hobgoblin
May-06-2021, 09:59 AM
Only your line doesn't work for its purpose. If you pass the string 'foo' as the first argument instead of a number, the program crashes.
With structural pattern matching you can simplify things a little.
It will be introduced with Python 3.10. In Alpha and Beta it's already implemented. I'm testing where the use of it is good and where it's bad. def get_args(default=42): # sys.argv = [str, str, str, ...] # will never match :-D # nonono match sys.argv: case _, int(value): return value case _: return default Works only, if len(sys.args) == 2 and the second arg must be an integer. If there is a match, value is converted to int and returned.Edit: The example won't work because the objects in sys.argv are str . The type is checked and no conversion happens. I guess this is an example where not to use structural pattern matching. It's just testing what is useful and looks natural and what not.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians! |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
python on a ternary computer | Skaperen | 0 | 1,997 |
Jun-20-2020, 02:21 AM Last Post: Skaperen |
Users browsing this thread: 1 Guest(s)