Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: RE: Equals: why the "=" (attribution) vs. "==" (Boolean) syntax distinction ???


From   Joe Canner <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: RE: Equals: why the "=" (attribution) vs. "==" (Boolean) syntax distinction ???
Date   Tue, 27 Aug 2013 17:56:11 +0000

It's also worth pointing out that using == for Boolean comparison is common in other programming languages.  This doesn't help the beginning Stata user who isn't also a programmer, but it does help those who move around between different languages.

There are some languages (mostly older) that do not make this distinction, but in these languages you lose the flexibility of being able to do a Boolean comparison on the right side of an assignment statement.  When memory and/or CPU cycles are at a premium this can be an important issue.

FWIW, some languages (not sure about Stata) also allow an assignment = in an -if- statement, e.g. if (x=y+z) {...}.  In this case, TRUE is returned if the assignment is performed without error and FALSE otherwise.  This is an obscure, but occasionally useful, usage which contributes to code flexibility and programmer happiness.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: Tuesday, August 27, 2013 1:25 PM
To: [email protected]
Subject: Re: st: RE: Equals: why the "=" (attribution) vs. "==" (Boolean) syntax distinction ???

Not without a little sympathy, but....

It's for Stata's convenience, which ultimately means yours too. As = means assignment and == asserts equality,  Stata needs a way of keeping them straight.

As Joe implies, the alternative is some rule that tells you that = means one thing in one place and another thing in another place. It's not clear to me that anyone who gets tripped up by existing syntax would not get tripped up by that. ("The first = means this, but the second has a _quite_ different meaning....")

I've also encountered many positive reactions to this syntax when users see that Stata is making a logical distinction between logically different things.

Perhaps here the taste and logic of the language designer seem to be triumphing over the taste and convenience of the beginning user, but that's the way it goes. Heck, more advanced users have some rights too!

I didn't know there were hard data anywhere on frequency of users' mistakes.


Nick
[email protected]


On 27 August 2013 18:10, Joe Canner <[email protected]> wrote:
> How about the following?
>
> . gen a=b==c
>
> How would Stata interpret this (valid) statement if there was no distinction between = and ==?
>
> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of Lucas 
> Ferreira Mation
> Sent: Tuesday, August 27, 2013 1:00 PM
> To: statalist
> Subject: st: Equals: why the "=" (attribution) vs. "==" (Boolean) syntax distinction ???
>
> sort of a philosophical question (and I could not find any previous discussion on this topic in the list):
>
> why does Stata the language differentiate between "=" and "==" ?
>
> I was teaching a Intro to Stata Class and the students were asking about it. I explained the difference between attribution equal (=) and Boolean check equal (==).
>
> Although they got the concept, the question remains:
>
> why be explicit about this distinction in the language syntax?
>
> Thinking about it, it seems to me that the occurrences of "equal"
> (attribution vs. Boolean) aways appear in distinct places in the syntax, so it does not seem prone to mistakes.
>
> On the other hand, forgetting "==" it the single most common mistake beginner users make, and even more advanced users ofter forget.
>
> Anyway, I just wanted to know if there are other reasons I'm unaware of.
>
>
> Lucas
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index