[Python-ideas] No implicit variable declarations

Chris Angelico rosuav at gmail.com
Sun Apr 13 09:56:18 CEST 2014


On Sun, Apr 13, 2014 at 2:21 PM, Andrew Barnert
<abarnert at yahoo.com.dmarc.invalid> wrote:
> Of course the cost is that you don't get compile-time type checking. But for many programs, that type checking is nearly useless (at least the Java kind; the Haskell kind is more useful).
>

Aside: I have periodically had bugs where I omit the first argument of
a function (in situations where, had it not been first, it would have
been marked optional). In C, those sorts of bugs are often caught by
the function signature; in Python, they can be, but only if the
function takes a fixed number of args. For instance:

void foo(target *destination, const char *msg, int blah=0, int blahblah=0)

If you omit the destination, you get an error back straight away,
because a string (const char *) can't be converted into a target. The
equivalent in Python, though:

def foo(destination, msg, blah=0, blahblah=0):

would happily assign the args one slot earlier, as long as I provided
at least one of the optionals. But this is a fairly narrow case; if
both those args were mandatory, the mere count of arguments would trip
an error. (Albeit at run-time, not compile-time, but until Python goes
to actually run the line of code, it can't know that this is the
signature anyway.)

ChrisA

PS. Neat trick with dmarc.


More information about the Python-ideas mailing list