1 Dec 2020 1 Dec '20
On Tue, Dec 1, 2020 at 10:25 AM Marco Sulla Marco.Sulla.Python@gmail.com wrote:
On Mon, 30 Nov 2020 at 23:26, David Mertz email@example.com wrote:
Somehow "dire" doesn't strike me as the right word.... Maybe you were looking for "conceivably useful in niche cases."?
Well, I think const can be useful for:
- multiprocessing. Now, for example, dict is passed between processes
using MappingProxyType, which is slow.
- avoid side effects. I expect that my object will not change and I
want to be sure I'll not change it by mistake. Mistake that I made a lot of times.
- contract. A function marks a parameter as const will guarantee that
the object will not be changed. It's something complementar to annotations.
- possible future speed improvements. For example, if an iterable is
const, you can skip a lot of checks about mutability on iteration and make it more fast.
Are you assuming that "const" means "will not be rebound" or "is immutable"? Or both?