[Python-ideas] "Immutable Builder" Pattern and Operator

Gerald Britton gerald.britton at gmail.com
Mon Jan 23 10:52:25 EST 2017


[snip]



>I propose `x .= y` -> `x = x . y`, for any `y`.



[snip]



I think you mean "any y that is a member of x"



Also, note that this syntax means that x will be rebound to the result of
calling x.y, whatever that is (frequently, None, for mutating methods)

In general, you can't count on methods to return references to their
instances, even though it's handy for fluent coding, so this side effect
may be unexpected to some



That's a problem with your original example:



>long_name = mkbuilder()

>long_name = long_name.seta(a)

>long_name = long_name.setb(b)

>y = long_name.build()



What do the methods seta and setb return?  If they don't return "self"
you've got a problem. I think.



FWIW why can't you just write:



x.y



or for your example:



long_name.seta(a)



?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <[Python-ideas] "Immutable Builder" Pattern and Operator

	
  • Next message (by thread): [Python-ideas] "Immutable Builder" Pattern and Operator
  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

  • More information about the Python-ideas mailing list

    Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

    Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant