1. 15
  1. 7

    I’m increasingly of the opinion that it’s better to have gotchas than two subtly ways to do something.

    1. 3

      Yeah. They talk about this as removing a “wart”, but nothing is actually being removed from the language! You cannot eliminate a gotcha by adding to the language: anyone who knows to use the late binding syntax has already sidestepped the gotcha. The advantage of this proposal isn’t that it removes a wart or fixes a gotcha, it’s that it improves convenience for those who already know Python’s default value behavior.

      1. 2

        I am hopeful that once this gets added, the previous default-argument syntax will get increasingly flagged by linters and such, reserving that syntax exclusively for optimization, and preventing newbies from accidentally stepping on it.

    2. 4

      I can’t help but think that what they call Late bound argument default is required only because of the design mistake of initializing the parameter default value at the definition time. If this proposal gets us the normal default values for parameters (even if under a slightly surprising syntax), I would be really happy.

      (This is the current proposal)

      def append_to(element, to=None):
          if to is None: to = []
          return to


      def append_to(element, to=:[]):
          return to
      1. 3

        Beyond that, Eric V. Smith wondered about how late-bound defaults would mesh with Python’s function-introspection features.

        I thought this would be the main discussion point around argument defaults in Python, since isn’t this the main reason for the idiosyncratic behavior of the mutable defaults in Python? I believe this is a very insidious gotcha in language design in general. If you ask people whether a language would be better off with, say, default arguments, or named arguments or exception specifications or overloading etc., everyone would at least say “why not!”. But only when you later want to manipulate functions via introspection or higher-order functions that you realize anything that makes your functions more complicated than the lambda abstraction is actually an impediment to abstraction.