On Sat, Apr 18, 2020 at 10:21:46AM +1200, Greg Ewing wrote:
> On 18/04/20 1:56 am, oliveira.rodrig...@gmail.com wrote:
> >This should be valid syntax:
> >
> >```python
> >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,
> >)
> 
> Not sure I like that. The only thing telling you that the
> args without = are keyword args rather than positional args
> is the "*", which is easy to miss amidst all that other stuff.


I agree with Greg here. This is a modal interface: the use of a `*` 
shifts from "positional argument mode" to "auto-fill keyword mode".

Modal interfaces are generally harmful and should be minimized. This 
doesn't just apply to GUIs but to text interfaces too, and code is an 
interface between what I, the coder, wants and the computer.

https://wiki.inkscape.org/wiki/index.php/Modal_interfaces

Modes are okay when they are really big (e.g. "I'm in Python programming 
mode now") but otherwise should be minimized, with an obvious beginning 
and end. If you have to have a mode, they should be *really obvious*, 
and this isn't. There's a really fine difference between modes:

    my_super_function_with_too_many_parameters(
        args, bufsize, executable, stdin, stdout, stderr, 
        preexec_fn, close_fds, shell, cwd, env, kwargs,
        universal_newlines, startupinfo, creationflags, 
        restore_signals, start_new_session, *, pass_fds,
        encoding, errors, text, file, mode, buffering, 
        newline, closefd, opener, meta, private, dunder, 
        invert, ignorecase, ascii_only, seed, bindings,
        callback, log, font, size, style, justify, pumpkin,
        )

If you miss the star in the middle of the call, there's no hint in the 
rest of the call to clue you in to the fact that you changed modes.

In function definitions we can get away with it, because it is in one 
place, the function signature, but even there it is easy to miss unless 
you look carefully:

https://docs.python.org/3.8/library/subprocess.html#subprocess.Popen

But we call functions far more often than we define them, and here a 
mode shift is too easy to miss, or neglect.


-- 
Steven
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/TPNFSJHPWQWZFO7VM6COQN6ZPOWWKG2X/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to