[Python-ideas] No implicit variable declarations
Ryan Gonzalez
rymg19 at gmail.com
Mon Apr 14 01:22:52 CEST 2014
On Sun, Apr 13, 2014 at 2:56 AM, Chris Angelico <rosuav at gmail.com> wrote:
> 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:
>
No you don't! If you're stuck in C89 for one reason or another, all you get
is a warning(which most programmers ignore anyway). C++ is much more strict
in that regard.
> 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.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
--
Ryan
If anybody ever asks me why I prefer C++ to C, my answer will be simple:
"It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was
nul-terminated."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140413/29ea5da2/attachment-0001.html>
More information about the Python-ideas
mailing list