FEEDBACK WANTED: Type/class unification

Delaney, Timothy tdelaney at avaya.com
Wed Aug 22 20:42:18 EDT 2001


> While on this subject, would it be an idea to make built-in types
> callable, so that you just call an object without caring whether it
> was a function/method or a simple type? Thus:
> 
> x = 10
> 
> def y():
>     return 10
> 
> x()
> y()

But surely then you would code this as

x = 10()

def y():
	return 10()

print x()
print y()()()()()()

;)

Seriously, this is a bad idea for the reason given on the last line of code
... what happens when y() changes to return something else which is callable
- you get no indication of a semantic error. Or more likely the other way -
you currently have y() returning something which is callable, but that
changes to return something which currently is not callable (the API
therefore changes). With the current system that will be caught - if
everything were callable, it would not.

A fequent mistake is passing the result of calling a function instead of
passing the reference to the function instead. Making everything callable
would no longer flag this as an error, or would flag it is the wrong type of
error (insufficient parameters passed for example, instead of "not a
callable object").

Tim Delaney




More information about the Python-list mailing list