Hmmm... I disagree with Chris.
I'm definitely -1 on a magic dangling 'foo=' after variable names. And something less than -1 on the even more magic "Lisp symbol that isn't a symbol" ':foo'.
Those are just ugly and mysterious.
However, I don't HATE the "mode switch" use of '*' or '**' in function calls. I've certainly written plenty of code where I use the same variable name in the calling scope as I bind in the call. Moreover, function *definitions* have an an analogous mode switch with an isolated '*'.
I'm only -0 on the mode switch style. Another thing to learn isn't really work the characters saved. But it's not awful.
On Fri, Apr 17, 2020, 9:29 AM Chris Angelico email@example.com wrote:
On Fri, Apr 17, 2020 at 8:52 PM Alex Hall firstname.lastname@example.org wrote:
But this means the reader could miss the star, especially with a very
large function call over multiple lines, and if that reader happens to use that particular function A LOT and know the parameter order without having to look they would pretty easily believe the arguments are doing something different than what is actually happening.
Thank you for giving an actual scenario explaining how confusion could
occur. Personally I think it's a very unlikely edge case (particularly someone comparing argument order to their memory), and someone falsely thinking that correct code is buggy is not a major problem anyway.
I propose using two asterisks instead of one as the magical argument
separator. `**` is more closely associated with keyword arguments, it's harder to visually miss, and it avoids the problem mentioned [here]( https://email@example.com/message/XFZ5VH...) which I think was a valid point. So a call would look like:
function(**, dunder, invert, private, meta, ignorecase)
All of these mode-switch proposals have the fundamental problem that you then cannot mix shorthand and longhand forms - once you go shorthand, suddenly everything has to be shorthand. I don't like that. The original proposal was entirely self-contained and has a very simple interpretation. Consider this example of actual production code (same one as I posted earlier):
return render_template("index.html", twitter=twitter, username=user["display_name"], channel=channel, channelid=channelid, error=error, setups=database.list_setups(channelid), sched_tz=sched_tz, schedule=schedule, sched_tweet=sched_tweet, checklist=database.get_checklist(channelid), timers=database.list_timers(channelid), tweets=tweets, )
Aside from the first parameter, everything is keyword args, and there is no particular order to them. The render_template function doesn't define a set of parameters - it takes whatever it's given and passes it along to the template itself. If I could use the "name=" shorthand, I could write this thus:
return render_template("index.html", twitter=, username=user["display_name"], channel=, channelid=, error=, setups=database.list_setups(channelid), sched_tz=, schedule=, sched_tweet=, checklist=database.get_checklist(channelid), timers=database.list_timers(channelid), tweets=, )
Each individual entry can use the shorthand, and it has a well-defined meaning. The order doesn't define which ones can and can't use shorthand.
What's the advantage of a mode switch? This seems perfectly clear to me without any sort of magical cutoff.
ChrisA _______________________________________________ Python-ideas mailing list -- firstname.lastname@example.org To unsubscribe send an email to email@example.com https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://firstname.lastname@example.org/message/3HZIDW... Code of Conduct: http://python.org/psf/codeofconduct/