Should constants be introduced to Python?

bartc bc at freeuk.com
Fri Nov 17 13:48:46 EST 2017


On 17/11/2017 15:14, Marcin Tustin wrote:
> I'm against this because Python's strength is its simplicity.

If it was simple once, then it isn't any more.

Perhaps you mean consistency, in having only one class of identifier 
which can always be assigned to.

> All the benefits of this can be achieved with linting.

The significance of true constants can go beyond that, assuming the 
proposal is not merely for some 'write-protect' flag on an ordinary 
variable.

Proper constants allow reduction of expressions using them at 
compile-time. They allow lightweight enums that do the same.

They allow the possibility of an efficient 'switch' statement.

And that's just for numeric constants. If applied also to constant defs, 
classes and imports, they introduce extra scope for compile-time optimising.

-- 
bartc



More information about the Python-list mailing list