Are the critiques in "All the things I hate about Python" valid?

Chris Angelico rosuav at gmail.com
Tue Feb 20 08:58:03 EST 2018


On Wed, Feb 21, 2018 at 12:53 AM, Antoon Pardon <antoon.pardon at vub.be> wrote:
> In C++ I can do something like:
>
>   SomeClass MyVar;
>
> And after that the kind of possible assignments to MyVar are constraint. It
> makes the runtime throw an error when somewhere the program tries to assign
> something to MyVar that isn't allowed by SomeClass.
>
> You can't put such constraints on names in Python.
>
> In C++ I can do some like:
>     Some_Class: MyVar;
>
> And after that, It will be impossible to assign a value to MyVar that
> doesn't meet the
> constraints imposed by the constructor/copy operator. You have put
> somekind of
> contract on the name MyVar, that limits the kind of things assignable to
> it. You
> can't put such constraints on a name in Python.

Okay. Now create a constraint on a name in C++ such that it can only
accept integers representing A.D. years which, on the Gregorian
calendar, are leap years. (Using a dedicated integer-like type is
permitted.) It must accept all multiples of four, except those which
are multiples of one hundred, unless they're also multiples of four
hundred.

That's what Steve asked for. Can you do it? Or is the C++ type system
not flexible enough for that?

ChrisA



More information about the Python-list mailing list