[Tutor] ?4uplz-> function

Jeff Shannon jeff@ccvcorp.com
Mon, 08 Oct 2001 12:08:37 -0700

>From: "David Meltzer" <asdffdsa@bellatlantic.net>
>Date: Fri, 5 Oct 2001 17:04:27 -0400
>Subject: [Tutor] ?4uplz-> function
>hilo2u and thanks for reading this,
>i would like to find a way to create a def that behaves more like a
>keyword such as 'print' in that i would not need to use a parenthesis.
>so perhaps you know a way to make the illegal legal

No, this can't be done.  There's a *reason* that it's illegal.  Much of
that reason, is that it is almost always a really bad idea.

Among other things, it makes it very ambiguous as to what is intended as
a parameter to the statement/function, and what isn't.  Especially if
you've got a complex expression, say,

printit var1 func var2 var3

Even if we know that both printit and func are statement/functions, we
can't tell how this should be parsed--it could be any of the following:

printit(var1, func(var2, var3))
printit(var1, func(var2), var3)
printit(var1, func(), var2, var3)
printit(var1, func(var2)), var3
printit(var1, func(), var2), var3
printit(var1, func()), var2, var3
printit(var1), func(var2, var3)
printit(), var1, func(), var2, var3

And so on and so on.  How does the python parser know which you mean??
And more importantly, how does someone reading your code know which you
mean?  Especially since there may be variable numbers of arguments...

And really... what would it be saving you??  How difficult is it to add
a couple more parens??

(This sometimes-use-parens-but-sometimes-don't mess is one of the things
that I hate *most* about Visual Basic--I would be mortified to see the
same mistake work its way into Python.)

Jeff Shannon
Credit International