2 ms·
Language syntax is always a highly personal matter, subject a coder's preferences. That being said, I'm not very fond of the latest changes that have been impl
by michaelanckaert 5y ago
Language syntax is always a highly personal matter, subject a coder's preferences. That being said, I'm not very fond of the latest changes that have been implemented in the Python language. The "walrus operator" being the latest example.
As always, there is very good reasoning behind this PEP. And ultimately, when growing a language and becoming more "professional", complexity is added to the language or syntax.
From a personal point of view, I can get behind the following syntax change
value = my_object?.value
instead of doing
if my_object:
value = my_object.value
else:
value = None
or even
value = my_object.value if my_object else None
But looking into other examples given in the PEP, things can get quite messy and "ugly".
mangle_from_ = policy?.mangle_from_ ?? True
I love Python and will continue to use it, both personally and professionally. I just hope the Python developers try to draw a line somewhere. Sometimes a design is good enough and further evolution / development should not be done, because every change can be justified in some way or another.
- setr 5y agoThese have existing exactly the same in C# for a bit, and they’re fantastic bits of sugar — null checking comes up everywhere so its a low-impact high-volume benefit; looking at it as a one-off is pointless (see fstrings as a similar change) > mangle_from_ = policy?.mangle_from_ ?? True This scenario is the largest gain — nested nullable references is a massive pain, especially when you go deeper. It’s trivially superior to nested ternary or if statements. IMO the benefits easily make it a worthwhile sugar to add — the only concern is whether it fits the python “aesthetic”; which to me is a flat no, but at the same time it seems like the walrus operator will be the defining moment of that aesthetic era coming to an end