Pass-by-reference : Could a C#-like approach work in Python?
Stephen Horne
$$$$$$$$$$$$$$$$$ at $$$$$$$$$$$$$$$$$$$$.co.uk
Thu Sep 11 07:37:06 EDT 2003
On Thu, 11 Sep 2003 08:25:11 +0200, Peter Otten <__peter__ at web.de>
wrote:
>... and that is the whole point of my example: You can easily bypass the
>rebinding in a manner that is hard to find (if fun() and nested() contained
>some real code)
Oops - for some reason I read "cause" as "catch". Still, you made your
point even though I didn't realise you intended to make it - and it
was a very compelling point.
Actually, the 'builder' solution to the issue that I mentioned before
isn't as good as I initially thought. Here is how I wrote it...
: builder = Builder ()
:
: builder.Do_Setup_Stuff_1 ()
: builder.Do_Setup_Stuff_2 ()
: builder.Do_Setup_Stuff_3 ()
:
: container.Add (builder.Build ())
:
: builder.Do_Setup_Stuff_3_Slightly_Differently ()
:
: container.Add (builder.Build ())
The problem here is that it would be too easy for the caller to forget
to use the Build method - depending on what the 'container' actually
does, that may mean the builder gets used instead of the object.
Easily fixed, though - the builder and container are most likely part
of the same set of functionality, and therefore written to work
together. So the Add function should take the Builder object as its
parameter and call Build method itself. If it is given anything other
than a builder, the method won't exist and will fail immediately.
More information about the Python-list
mailing list