[Python-ideas] Improving fn(arg=arg, name=name, wibble=wibble) code

Anders Hovmöller boxed at killingar.net
Fri Sep 14 05:04:14 EDT 2018

> I don't think it's off-topic. The ugliness of the line you're talking about stems in large part from that it's in a heavily indented complex section. The distinction between positional and keyword args in this case is superficial.

Indenting 4 levels (32 spaces) is a problem, but adding an extra 77 non-space characters is superficial? Is this your position?

> Remembering your comments about string interpolation, it sounds like you write a lot of templating code and craft large JSON blobs for REST APIs. I agree that keyword arguments are critical in those situations for avoiding tedious and error-prone positional matching.

Well no they are not. You wouldn't have positional arguments because you'd create a dict and pass it.

> When I have similar situations I tend to avoid the `f(a=a)` annoyance by creating kwds dicts and passing them around with ** unpacking.

Which everyone does. But how would you create that dict? 

> It avoids creating extra lists, which might make it more efficient. It also emphasizes the recursion, which wasn't obvious to me when I first glanced at the code.

Sure. All good improvements. No argument from me.

> No, I didn't bother switching to keyword arguments, because I didn't feel it helped. My screen was big enough to verify the order as I wrote the arguments.

This makes me very frustrated. You could rely on the machine to verify the arguments, but you spend extra time to avoid it. You're explicitly avoiding to send a machine to do a machines job. Why? I'm arguing you're doing it *because it produces shorter code*. This is exactly my point. We should send a machine to do a machines job, and if the language pushes people to send a man to do a machines job then this is bad.

> If you feel like you're repeating yourself, the easiest way to avoid frustration is to simply stop. Don't fall for the sunk cost fallacy, despite the effort you've put into this proposal.

Well ok, you should have started with that. I'll just send what I've written so far :)

/ Anders

More information about the Python-ideas mailing list