inline assignments in conditionals 
Author Message
 inline assignments in conditionals

Quote:

> Writing things that way is really unnatural, at least for English
> speakers.  It makes the intent of the code harder to understand (at
> least for me).  For example, if you were talking to a friend, you
> woudn't say:

>    "If today is Sunday, I'm going to go shopping"

> but rather:

>    "If Sunday is today, I'm going to go shopping"

> and in any case, writing the constant first only protects in the case
> where one of the compared values is a constant.  If you are doing

>    if (a == b):

> then there is no way to protect yourself against actually writing '='.

> Given that, I think not supportig inline assignment is a reasonable
> choice.  Perhaps another option would be to coin a synonymous operator
> that works in comparisons, but is distinct enough from '==' so as not
> to be used by accident?

>    if (data gets socket.recv(1024)):
>       process(data)

  I'm +1 on this (Guido's gonna hate me I bet!). I recently found a
scenario (this was in C and then I thought about how I'd do it in
python) where I wanted to do an assignment only if I reached a certain
point in a bool statement, including short-circuiting.  It just made
my life a lot easier because I didn't have to include redundant
case-code. B-sides, sometimes, you wish you could compress the two
statements.

               -- Mike

--
Michael Gilfix

For my gpg public key:
http://www.*-*-*.com/ ~mgilfix/contact.html



Thu, 14 Oct 2004 03:51:15 GMT  
 inline assignments in conditionals

Quote:

>Anyone who writes "if (x == 0)" instead of "if (0 == x)" deserves what
> he begs for.

Writing things that way is really unnatural, at least for English
speakers.  It makes the intent of the code harder to understand (at
least for me).  For example, if you were talking to a friend, you
woudn't say:

   "If today is Sunday, I'm going to go shopping"

but rather:

   "If Sunday is today, I'm going to go shopping"

and in any case, writing the constant first only protects in the case
where one of the compared values is a constant.  If you are doing

   if (a == b):

then there is no way to protect yourself against actually writing '='.

Given that, I think not supportig inline assignment is a reasonable
choice.  Perhaps another option would be to coin a synonymous operator
that works in comparisons, but is distinct enough from '==' so as not
to be used by accident?

   if (data gets socket.recv(1024)):
      process(data)

-Jeremy



Thu, 14 Oct 2004 03:33:47 GMT  
 inline assignments in conditionals
Aggh!  Of course I meant it the other way around.  :^P
It would have been a nice example too, if I hadn't completely
stuffed it up.  So for the record, "If today is Sunday" is my
preferred form (i.e. if day == 0), and I should never again
be allowed to post without proofreading first.

Jeremy

Quote:
>   I think this example is backwards. Today is the variable.  I'd
> usually say: "If today is Sunday, I'm going to go shopping". So much
> for that :)

>             -- Mike


> > Jeremy:
> > [snip]
> > > Writing things that way is really unnatural, at least for English
> > > speakers.  It makes the intent of the code harder to understand
> > > (at
> > > least for me).  For example, if you were talking to a friend, you
> > > wouldn't say:

> > >    "If today is Sunday, I'm going to go shopping"

> > > but rather:

> > >    "If Sunday is today, I'm going to go shopping"

> > Interesting.  I would never use the second construct, and I use the
> > first one all the time.  I wonder if this is a difference between
> > people whose first language is English, and some for whom it was
> > not.
> > I don't think that anybody has had any trouble understanding me
> > when I
> > say 'If today is Saturday, then we are going to the concert house,
> > otherwise we are going to hack.'  But then I have been writing
> > if 0 == x for a long time as well.  (It was great -- Borodin
> > Quartet
> > playing Sjostakovitj and Beethoven, by the way.)

> > Laura Creighton



Thu, 14 Oct 2004 05:04:30 GMT  
 inline assignments in conditionals
  I think this example is backwards. Today is the variable.  I'd
usually say: "If today is Sunday, I'm going to go shopping". So much
for that :)

            -- Mike

Quote:

> Jeremy:
> [snip]
> > Writing things that way is really unnatural, at least for English
> > speakers.  It makes the intent of the code harder to understand (at
> > least for me).  For example, if you were talking to a friend, you
> > wouldn't say:

> >    "If today is Sunday, I'm going to go shopping"

> > but rather:

> >    "If Sunday is today, I'm going to go shopping"

> Interesting.  I would never use the second construct, and I use the
> first one all the time.  I wonder if this is a difference between
> people whose first language is English, and some for whom it was not.
> I don't think that anybody has had any trouble understanding me when I
> say 'If today is Saturday, then we are going to the concert house,
> otherwise we are going to hack.'  But then I have been writing
> if 0 == x for a long time as well.  (It was great -- Borodin Quartet
> playing Sjostakovitj and Beethoven, by the way.)

> Laura Creighton

> --
> http://mail.python.org/mailman/listinfo/python-list

`-> (lac)

--
Michael Gilfix

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html



Thu, 14 Oct 2004 04:43:35 GMT  
 inline assignments in conditionals
Jeremy:
[snip]

Quote:
> Writing things that way is really unnatural, at least for English
> speakers.  It makes the intent of the code harder to understand (at
> least for me).  For example, if you were talking to a friend, you
> wouldn't say:

>    "If today is Sunday, I'm going to go shopping"

> but rather:

>    "If Sunday is today, I'm going to go shopping"

Interesting.  I would never use the second construct, and I use the
first one all the time.  I wonder if this is a difference between
people whose first language is English, and some for whom it was not.
I don't think that anybody has had any trouble understanding me when I
say 'If today is Saturday, then we are going to the concert house,
otherwise we are going to hack.'  But then I have been writing
if 0 == x for a long time as well.  (It was great -- Borodin Quartet
playing Sjostakovitj and Beethoven, by the way.)

Laura Creighton



Thu, 14 Oct 2004 04:37:00 GMT  
 inline assignments in conditionals
"jaf"

Quote:
> Aggh!  Of course I meant it the other way around.  :^P
> It would have been a nice example too, if I hadn't completely
> stuffed it up.  So for the record, "If today is Sunday" is my
> preferred form (i.e. if day == 0), and I should never again
> be allowed to post without proofreading first.

No.  That'd take a lot of the fun out of it!  ;-)

--

Emile van Sebille

---------



Thu, 14 Oct 2004 05:22:03 GMT  
 inline assignments in conditionals


Quote:

> > Writing things that way is really unnatural, at least for English
> > speakers.  It makes the intent of the code harder to understand (at
> > least for me).  For example, if you were talking to a friend, you
> > woudn't say:

> >    "If today is Sunday, I'm going to go shopping"

> > but rather:

> >    "If Sunday is today, I'm going to go shopping"

> > and in any case, writing the constant first only protects in the
case
> > where one of the compared values is a constant.  If you are doing

> >    if (a == b):

> > then there is no way to protect yourself against actually writing

'='.

Unnatural and partial as it is, it is a recommended best
practice to protect yourself from accidentally writing '='
when you meant '==' in C or C++.

I don't have any objection to implementing assignment
in expressions. I have a real objection to doing it in such
a way that it makes silly mistakes easier, however.

John Roth



Thu, 14 Oct 2004 08:15:25 GMT  
 inline assignments in conditionals

Quote:

> >    "If today is Sunday, I'm going to go shopping"

> > but rather:

> >    "If Sunday is today, I'm going to go shopping"

> I don't think that anybody has had any trouble understanding me when I
> say 'If today is Saturday, then we are going to the concert house,

Not at all - this is exactly how I say things.

Quote:
> otherwise we are going to hack.'  But then I have been writing
> if 0 == x for a long time as well.

The one doesn't follow the other. "If today is Sunday" corresponds to "if x
is 0" - "today" is the variable, "Sunday" is a constant.

Tim Delaney



Fri, 15 Oct 2004 09:11:02 GMT  
 inline assignments in conditionals
        ...

Quote:
>> >    "If Sunday is today, I'm going to go shopping"

>> I don't think that anybody has had any trouble understanding me when I
>> say 'If today is Saturday, then we are going to the concert house,

> Not at all - this is exactly how I say things.

>> otherwise we are going to hack.'  But then I have been writing
>> if 0 == x for a long time as well.

> The one doesn't follow the other. "If today is Sunday" corresponds to "if
> x is 0" - "today" is the variable, "Sunday" is a constant.

Take another typical English usage then.  "If Bush is the President of the
US ...".  Which one is the "variable" now, and which one the "constant"?
Clearly, who is President varies over time, just as what is 'today', while
'Bush' in this context refers to a specific individual (it may be ambiguous
which one, of course:-).

The distinction in connotation is not variable vs constant -- it is about
what term is supposed to be in doubt:

    "If Bush is the President of the US ... " (rather than being, e.g.,
        the President of General Motors)

    "if the President of the US is Bush ... " (rather than being, e.g.,
        Gore)

Actually my feeling is that the first form would be quite acceptable
in the second connotation as well, while the latter form would be
totally unacceptable in the former connotation (i.e., the latter form
unambiguously indicates we're musing about different individuals
covering the "President of the US" role; the former form might
indicate that, too, although it's quite OK to indicate the different
case of musing about different roles for one given individual).  But
I doubt i can "prove" it.  Natural language just doesn't fit well into
hard-and-fast formulas, despite the unending efforts of grammarians,
pundits, and purists -- it IS, after all, part of the biology and
sociology of human beings, notoriously funny and fuzzy subjects.
(Which explains why it's so unappropriate as a basis for designing
programming languages, but that's an issue deserving longer discourse).

Yours for descriptive-rather-than-prescriptive linguistics,

Alex



Fri, 15 Oct 2004 15:37:51 GMT  
 inline assignments in conditionals

Quote:
> Aggh!  Of course I meant it the other way around.  :^P
> It would have been a nice example too, if I hadn't completely
> stuffed it up.  So for the record, "If today is Sunday" is my
> preferred form (i.e. if day == 0), and I should never again
> be allowed to post without proofreading first.

Don't see why I should be the only one to make a fool of myself (dammit).

regards
 Steve
--

Steve Holden: http://www.holdenweb.com/ ; python Web Programming:
http://pydish.holdenweb.com/pwp/



Fri, 15 Oct 2004 19:56:08 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. No Assignment in Conditional/PROPOSAL: Assignment expression

2. "multiple assignment in conditional"

3. conditional signal assignment

4. Conditional assignments using generate

5. Conditional Signal Assignments inside Processes?

6. Against assignment in conditional nor while

7. RFC: Assignment in Conditional

8. Variable scoping affected by inline assignment

9. Newbie inline assembler assignment questions

10. Newbie inline assembler assignment questions

11. Newbie inline assembler assignment questions

12. porting inline Watcom asm to MSVC inline asm

 

 
Powered by phpBB® Forum Software