Guido wrote: >Does Java have them? I know very little Java, but all the other object-oriented languages I use support in-out and out parameters. For example: C++: void foo(int ¶m) {param += 5;} void bar(int ¶m) {param = 10;} // C++ does not distinguish between in-out and out parameters. // call them int x = 2; foo(x); // x is now 7 int y; bar(y); // y doesn't need to be initialized. It is now 10. // Unfortunately, the C++ function definition doesn't indicate // whether the argument needs to be initialized before the call. C#: void foo(ref int param) {param += 5;} // passed value can be used void bar(out int param) {param = 10;} // passed value cannot be used // call them int x = 2; foo(ref x); // x is now 7 int y; bar(out y); // y is now 10. Ada: procedure foo(param : in out Integer) is begin param
:= param + 5; end; procedure bar(param : out Integer) is begin param := 10; end; -- call them Integer x := 2; foo(x); -- x is now 7 Integer y; bar(y); -- y is now 10 Python: def foo(paramWrapper): paramWrapper[0] += 5 # Alternative: def foo2(param): return param + 5 def bar(paramWrapper): paramWrapper[0] = 10 # call them x = 2 wrapper = [x] foo(wrapper) x = wrapper[0] # x is now 7 # Three lines of it just to call foo in such a way that # it can modify the value of the variable passed in. # Alternative: x = 2 x = foo2(x) # Have to mention x twice just to let foo2 modify its value. # Also, all the arguments to be modified get mixed in with # the real function result if there is one. wrapper = [None] bar(wrapper) y = wrapper[0] # y is now 10 # bar is not quite as big of !
a
deal. The new value could # have been returned as one of (possibly many) results. Proposed Python 3.0: def foo(¶m): param += 5 def bar(¶m): param = 10 # call them x = 2 foo(x) # x is now 7 y = None bar(y) # y is now 10 I have always considered this the most glaring omission in Python. If it will never happen, fine, it will always be a wart, but in-out and out parameters are common in object-oriented languages and make the code much more readable. Since we are considering optional type indications on parameters, I thought this would be a good time to explicitly allow a function to change the argument value by adding something to the parameter. It could look like foo(¶m) or foo(ref param) or foo(inout param) or foo(param:inout) or whatever. I don't really care. The code for both the function definition and the call would be
clearer. #Rudy
|
|
Join Excite! - http://www.excite.com
The most personalized portal on the Web!
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com