PEP 841: Adding Frozen Syntax to Make Immutable Types Optimizable

I strongly agree on the fact that one should always use immutability by default and mutability if needed. The biggest impact however would be encouraging tuples usage instead of lists, which are data structures considerably more used.

however, the biggest downside for me on this proposal is readability.

For example, I know how to write code in python and Rust. I can read some java, kotlin, typescript or elixir code and very quickly and inutitevely understand what is going on. Now with languages were special syntax instead of words is the norm, like C, C++, I find it absolutely unreadable. Words have meaning, operators much less if you don’t have context. I highly doubt that C++ code is inerenthly more complex than rust code.

My point is: python IS designed to be redabable, just like english.

The fact that many libraries have taken the IMO discutable choice of abusing operators overloading (e.g pandas, numpy) instead of explicit methods is not something I’m not a fan of.

now with new tools (polars…) there’s a shift in the other direction, thankfully, but the last thing I would like is python stdlib itself adding more and more special syntax just to save a few words. I really struggle to see how f{} is more convenient to write than frozenset(). Especially in python compared to other languages, since you don’t have to reach for curly brackets as often.

And about optimizations, python biggest runtime slower in my experience is function call overhead, not a few constants having to be created. This could provide some marginal improvements, but if that’s a concern, you have much higher priority to check at the start of your program: do you import slow modules (i.e dataclasses), do you use slots whenever possible? Etc..

1 Like