[Python-3000] in-out parameters

Jim Jewett jimjjewett at gmail.com
Thu May 4 22:38:02 CEST 2006


On 5/4/06, Rudy Rudolph <rudyrudolph at excite.com> wrote:
>
> // C++ does not distinguish between in-out and out parameters.
> // call them
> int x = 2; foo(x); // x is now 7
>

It is important to avoid this obfuscation.

C's &addr is slightly better, but still pretty error prone with
collections, like a string or array.


> Python:
> def foo(paramWrapper):
>     paramWrapper[0] += 5
>

or use named fields of an object

    def foo(data):
         dataobject.param3 +=5

or return a tuple if you need a multiple-values-return

    x=foo(x)
    val1, val2, val3 = foo(val4, val1, val5)

At best, adding an out parameter is the equivalent of adding in-place
operators

    a += 1
vs
    a = a + 1


-jJ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20060504/32064fd7/attachment.html 


More information about the Python-3000 mailing list