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   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: RE: Equals: why the "=" (attribution) vs. "==" (Boolean) syntax distinction ???
Date   Tue, 27 Aug 2013 16:27:40 -0400

Strictly speaking, == is not a Boolean operator, those are &, |, and ! I'm
pretty sure.

I've always liked the == because it is consistent with the other comparitors
with respect to number of characters:

  ==
  >=
  <=
  !=

so logically, they are all "=" with a prefix to differentiate.

On the other hand, I've never much cared for using "=" to make an assignment,
the C++/R convention of using "<-" seems more symbolically  consistent with the
action than does the signifier for equality.

Just goes to show that taste varies.

cheers,
J



On 8/27/2013 3:13 PM, Nick Cox wrote:
There are situations in which Stata tolerates either syntax, e.g.
-test-. But those are captured deliberately. Programmers do things
like that all the time, e.g. support different spellings, etc.

I suspect the main answer to Lucas is deep, deep down:

1. Compromising on consistency for the sake of convenience or
plausibility is the start of a long slippery slope.

2. In designing a language, you don't limit what programmers might
write because of what users most want to type because of what springs
to their mind. As I understand it, syntax and semantics are best kept
disjoint.
Nick
[email protected]


On 27 August 2013 19:59, Lucas Ferreira Mation <[email protected]> wrote:
Joe, Nick, tks for the feedback on this. Personally I also don´t mind
the distinction.

on "gen a=b==c" : is this the only case (and is a particular syntax of
gen) where the situation is slightly ambiguous?   Even in this case,
the precedence of the attribution equal makes it unambiguous. Or the
syntax of this specific command could make parenthesis  mandatory, ex:
"gen a=(b=c)".

If this is the only case, and all other commands have conditions after
the "if",  why bother? I agree the similarity with other languages is
an advantage. However, in less "regular" languages, like R this, a==b
vs. a=b distinction is necessary, but in Stata the language is so
regular that there is not much room for confusion.


I don´t have data on mistakes, I was (imprecisely) referring to my
impressions from teaching a few courses and also from my own learning
curve. I never counted, but this is definitively the most frequent
mistake students make (the other very common is forgetting to wrap
strings in " ", gen x=blab).

In this last course there were 3 types of students:
- non programmers (excel, spss, ...): were puzzled by the conceptual
distinction, but got used to it.
- SAS programmers : in general were amazed by Stata syntax, to the
point of almost converting. But then got annoyed with this "=" vs.
"==" distinction. And complained that error messages in Stata are
uninformative and Stata is difficult do debug.
- a few R programmers: were fine, and happy to have "less options".
One or two ways to do things instead of 10 different ways in R.

anyway, tks for the feedback and an interesting discussion
regards
Lucas

On Tue, Aug 27, 2013 at 3:05 PM, Nick Cox <[email protected]> wrote:
Agreed on the major point that == are standards across many languages.

The last FWIW is a standard Mata device. Those who use it wouldn't
call it obscure, although it's the sort of thing that should make you
slow right down when reading it.

More generally, no one delights that Stata syntax can be tricky, but
you can't have a rich language without the possibility that it's not
all transparent to the beginning user.
Nick
[email protected]


On 27 August 2013 18:56, Joe Canner <[email protected]> wrote:
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/

*
*   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