Lies in education [was Re: The "loop and a half"]

Marko Rauhamaa marko at pacujo.net
Fri Oct 13 10:25:38 EDT 2017


Paul Moore <p.f.moore at gmail.com>:

> To put it another way, in C const is a property of the variable being
> declared, not the value assigned to it. In Python, variables aren't
> declared, and constness is an inherent property of the value (or its
> type). One interesting question which this does raise is whether
> there's a place for "const" in type annotations - I suspect not,
> because it's either trivial (the type is immutable) or too hard to
> define (you'd need to recursively know for all methods whether they
> mutate the value).

I don't think that's the core issue.

User-defined classes (or, rather, objects) are often mutable. The
question is who gets to modify them and what modifieds them (methods can
have surprising side effects).

"Const" would convey some of that information. However, why "const" out
of the myriads of restrictions?

The nice thing about Python is that I don't get to formally declare
those things, and that makes my life easier. I don't have to worry about
finding the right combination of these formal comments -- because I
can't!


Marko



More information about the Python-list mailing list