Python handles globals badly.

Antoon Pardon antoon.pardon at
Wed Sep 16 10:51:08 CEST 2015

Op 16-09-15 om 03:13 schreef Steven D'Aprano:
> On Mon, 14 Sep 2015 06:30 pm, Antoon Pardon wrote:
>> Op 12-09-15 om 05:48 schreef Steven D'Aprano:
>>> I believe I already acknowledged that assignment-as-expression was fine
>>> if it avoided the = versus == error, from the perspective of avoiding
>>> errors. But from the perspective of a clean and logical programming
>>> model, perhaps not so much. Assignment is imperative, not functional, and
>>> requiring it to return a result is somewhat unclean.
>> I thought practicallity beats purity? AFAICS python doesn't use such a
>> clean and logical programming model and it isn't given much critique over
>> it. So I don't think it is fair to critique assignment as an expression
>> because of this aspect.
> Python is a remarkably clean and consistent language.

Which is beside the point. Python may generally be a remarkable clean
and consistent language, we were not discussing the language in general
but a specific aspect. Arguing against C because it doesn't makes a
clear seperation between questions and actions (because the assignment
is an expression) while python doesn't either (but in other places) strikes
me as disingineous.

>> But we are not talking about all commands, we are just talking about
>> assignments. Sure an assignment has a side effect. But so has ls.pop(). So
>> something having a side-effect and a value is not unheard of even within a
>> python context.
> Sure, I already said that some commands might return a value.
> But assignment? Assignment is a pure command. There's nothing to return.
> Having `x = 23` return 23 is, well, weird. If we start from the premise
> that a return result is generated from a *calculation* or a *query*, we
> have to ask what is being calculated or asked?

You are stating your opinion as fact. Suppose I write the following class

class SetGet:
    def __init__(self, value):
        self.val = value

    def get(self):
        return self.val

    def set(self, value):
        self.val = value
        return value

So now I can write the following

index = SetGet(0)
while index.set(index.get() + 1) < 10:

So how would you answer your question as to what is calculated or asked
in the while condition here? The answer would be similar if we had just
allowed an assignment in the condition.

> And one other reason why I dislike it: it makes for a verbose and messy
> interactive experience. Take Ruby:

We are not talking about likes and dislikes. This discussion started
by you stating the the assignment as an expression in C was a design
flaw in the language. I can understand people preferring the assignment
not to be an operator. But when people start suggesting that assignment
as an operator is some kind of design flaw, which they use to criticise
a specific language, personal likes and dislikes are not important.

Antoon Pardon

More information about the Python-list mailing list