On Sun, Apr 19, 2020 at 8:29 AM David Mertz <mertz@gnosis.cx> wrote:
On Sun, Apr 19, 2020, 7:24 AM Richard Damon <Richard@damon-family.org> wrote:
One of the key motivations of this proposal is to make nicer a call with a lot of key word arguments where the local variable name happens (intentionally) to match the keyword parameter name.

I think Stephen said that this "same name across scopes" is an anti-pattern. I mostly disagree, though obviously agree that it varies between different code.

In some sense, I think the "anti-pattern" here is not so much in the naming of variables, arguments, and parameters, but in ending up on the wring side of the "data" vs. "code" divide.

e.g.: "data" might be a dict of key"value pairs, and "code" might be an object with attributes (or a bunch of keyword parameters in a function call)

In Python, this is a very blurry line, as you can easily do things like use **kwargs (oassing data into code) and accessing __dict__ (getting data from code), not to mention fancier meta-programming techniques.

But if you find yourself passing a lot of same-names variables around, maybe you should jsut be passing around a dict?

-CHB

I've worked with large code bases where the equivalent complex object is used in many places. Not necessarily as a continuous life of an actual object, but sometimes sent as JSON, other times read from database, other times calculated dynamically, etc. 

The JSON - related example is a good one -- JSON maps well to "data" in Python, dicts and lists of numbers and strings. If you find yourself converting a bunch of variable names to/from JSON, you probably should be simply using a dict, and passing that around anyway.

and, of course,with **kwargs, you CAN make the transition from a dict to an object and back quite easily.

-CHB

--
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython