Responding to several messages in this thread...> > All the more reason to use = instead of <- > Definitely not!Martin and Rolf are right, it's not a reason for that; I wrote that quickly without thinking it through. An "=" user might be more likely to fall for the gotcha, if not spacing their code nicely. So the lesson learned from the gotcha is that it's good to space your code nicely, as others have siad, not which assignment symbol to use. However, I continue to use "=" for assignment on a daily basis without any problems, as I have done for many years. I remain unconvinced by any and all of these arguments against it in favour of "<-". People telling me that I "should" use the arrow need better agruments than what I've seen so far. I find "<-" ugly and "->" useless/pointless, whereas "=" is simpler and also nicely familiar from my experience in other languages. It doesn't matter to me that "=" is not commutative because I don't need it to be.> Further it can be nicely marked up by a real "left arrow" > by e.g. the listings LaTeX 'listings' package...Now that's just silly, turning R code into graphical characters that are not part of the R language.> foo(x = y) and foo(x <- y)I'm well aware of this distinction and it never causes me any problems. The latter is an example of bad (obfuscated) coding, IMHO; it should be done in two lines for clarity as follows: x = y foo(x)> Using = has it's problems too.Same goes for apostrophes. Shall we discuss putting "else" at the start of line next? cheers, Steve
On Mon, Feb 2, 2015 at 8:57 PM, Steve Taylor <steve.taylor at aut.ac.nz> wrote:> Responding to several messages in this thread... > >> > All the more reason to use = instead of <- >> Definitely not! > > Martin and Rolf are right, it's not a reason for that; I wrote that quickly without thinking it through. An "=" user might be more likely to fall for the gotcha, if not spacing their code nicely. So the lesson learned from the gotcha is that it's good to space your code nicely, as others have siad, not which assignment symbol to use. > > However, I continue to use "=" for assignment on a daily basis without any problems, as I have done for many years. I remain unconvinced by any and all of these arguments against it in favour of "<-". People telling me that I "should" use the arrow need better agruments than what I've seen so far.Fair enough, but you skipped right past the most important one: it makes code easier to read. It's very nice to be able to visually scan through the code and easily see where assignment happens.> > I find "<-" ugly and "->" useless/pointless,I never used it either, until recently when I started using magrittr. Maybe still pointless, but I find the form> library(magrittr) > > "hello" %>%+ paste("world,") %>% + paste("my name is") %>% + paste("Ista") -> hi> hi[1] "hello world, my name is Ista" quite nice. --Ista whereas "=" is simpler and also nicely familiar from my experience in other languages. It doesn't matter to me that "=" is not commutative because I don't need it to be.> >> Further it can be nicely marked up by a real "left arrow" >> by e.g. the listings LaTeX 'listings' package... > > Now that's just silly, turning R code into graphical characters that are not part of the R language. > >> foo(x = y) and foo(x <- y) > > I'm well aware of this distinction and it never causes me any problems. The latter is an example of bad (obfuscated) coding, IMHO; it should be done in two lines for clarity as follows: > > x = y > foo(x) > >> Using = has it's problems too. > Same goes for apostrophes. > > Shall we discuss putting "else" at the start of line next? > > cheers, > Steve > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
I disagree. Assignments in my code are all lines that look like this: variable = expression They are easy to find and easy to read. -----Original Message----- From: Ista Zahn [mailto:istazahn at gmail.com] Sent: Tuesday, 3 February 2015 3:36p To: Steve Taylor Cc: r-help at stat.math.ethz.ch Subject: Re: [R] the less-than-minus gotcha On Mon, Feb 2, 2015 at 8:57 PM, Steve Taylor <steve.taylor at aut.ac.nz> wrote: Fair enough, but you skipped right past the most important one: it makes code easier to read. It's very nice to be able to visually scan through the code and easily see where assignment happens.
I did not start out liking <-, but I am quite attached to it now, and even Rcpp feels weird to me now. This may seem like yet another variation on a theme that you don't find compelling, but I find that f(x=x) makes sense when scope is considered, but x=x on its own is silly. That is why I prefer to reserve = for assigning parameters... I use it to clarify that I am crossing scope boundaries, while <- never does. (<<- is a dangerous animal, though... to be used only locally in nested function definitions). In my view, this is similar to preferring == from C-derived syntaxes over the overloaded = from, say, Basic. I am sure you can get by with the syntactic overloading, but if you have the option of reducing ambiguity, why not use it? --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On February 2, 2015 5:57:05 PM PST, Steve Taylor <steve.taylor at aut.ac.nz> wrote:>Responding to several messages in this thread... > >> > All the more reason to use = instead of <- >> Definitely not! > >Martin and Rolf are right, it's not a reason for that; I wrote that >quickly without thinking it through. An "=" user might be more likely >to fall for the gotcha, if not spacing their code nicely. So the >lesson learned from the gotcha is that it's good to space your code >nicely, as others have siad, not which assignment symbol to use. > >However, I continue to use "=" for assignment on a daily basis without >any problems, as I have done for many years. I remain unconvinced by >any and all of these arguments against it in favour of "<-". People >telling me that I "should" use the arrow need better agruments than >what I've seen so far. > >I find "<-" ugly and "->" useless/pointless, whereas "=" is simpler and >also nicely familiar from my experience in other languages. It doesn't >matter to me that "=" is not commutative because I don't need it to be. > >> Further it can be nicely marked up by a real "left arrow" >> by e.g. the listings LaTeX 'listings' package... > >Now that's just silly, turning R code into graphical characters that >are not part of the R language. > >> foo(x = y) and foo(x <- y) > >I'm well aware of this distinction and it never causes me any problems. >The latter is an example of bad (obfuscated) coding, IMHO; it should be >done in two lines for clarity as follows: > >x = y >foo(x) > >> Using = has it's problems too. >Same goes for apostrophes. > >Shall we discuss putting "else" at the start of line next? > >cheers, > Steve > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.
Nobody would write x=x or indeed x<-x; both are silly. If I found myself writing f(x=x) I might smirk at the coincidence, but it wouldn't bother me. I certainly wouldn't confuse it with assigning x to itself. By the way, here's another assignment operator we can use: `:=` = `<-` # this is going in my .Rprofile x := 1 -----Original Message----- From: Jeff Newmiller [mailto:jdnewmil at dcn.davis.ca.us] Sent: Tuesday, 3 February 2015 3:54p To: Steve Taylor; r-help at stat.math.ethz.ch Subject: Re: [R] the less-than-minus gotcha I did not start out liking <-, but I am quite attached to it now, and even Rcpp feels weird to me now. This may seem like yet another variation on a theme that you don't find compelling, but I find that f(x=x) makes sense when scope is considered, but x=x on its own is silly. That is why I prefer to reserve = for assigning parameters... I use it to clarify that I am crossing scope boundaries, while <- never does. (<<- is a dangerous animal, though... to be used only locally in nested function definitions). In my view, this is similar to preferring == from C-derived syntaxes over the overloaded = from, say, Basic. I am sure you can get by with the syntactic overloading, but if you have the option of reducing ambiguity, why not use it? --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On February 2, 2015 5:57:05 PM PST, Steve Taylor <steve.taylor at aut.ac.nz> wrote:>Responding to several messages in this thread... > >> > All the more reason to use = instead of <- >> Definitely not! > >Martin and Rolf are right, it's not a reason for that; I wrote that >quickly without thinking it through. An "=" user might be more likely >to fall for the gotcha, if not spacing their code nicely. So the >lesson learned from the gotcha is that it's good to space your code >nicely, as others have siad, not which assignment symbol to use. > >However, I continue to use "=" for assignment on a daily basis without >any problems, as I have done for many years. I remain unconvinced by >any and all of these arguments against it in favour of "<-". People >telling me that I "should" use the arrow need better agruments than >what I've seen so far. > >I find "<-" ugly and "->" useless/pointless, whereas "=" is simpler and >also nicely familiar from my experience in other languages. It doesn't >matter to me that "=" is not commutative because I don't need it to be. > >> Further it can be nicely marked up by a real "left arrow" >> by e.g. the listings LaTeX 'listings' package... > >Now that's just silly, turning R code into graphical characters that >are not part of the R language. > >> foo(x = y) and foo(x <- y) > >I'm well aware of this distinction and it never causes me any problems. >The latter is an example of bad (obfuscated) coding, IMHO; it should be >done in two lines for clarity as follows: > >x = y >foo(x) > >> Using = has it's problems too. >Same goes for apostrophes. > >Shall we discuss putting "else" at the start of line next? > >cheers, > Steve > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.
Steve (and any others still paying attention to this thread), Larry Wall (author of Perl) said something along the lines of: things that are similar should look similar, things that are different should look different. Ironically one of the first places I saw that quote was in a Perl vs. Python language war and the same quote was being used by both sides. This made me think that you can learn a lot about how programmers think by what they make look similar and what they make look different (and therefore what they think are similar and different). In R, I see the assignments: foo( x <- something ) as assign to the variable x in the current (or calling) environment and foo( x = something ) as assign to the variable x in the environment created by the function call. With this distinction only "<-" makes any sense at the top level, but then I see assigning to the 2 different environments as 2 different things that should look different. Using "=" for assignment makes sense if (and only if) you consider assigning into different environments to be the same (or at least very similar) thing. Also you mentioned that foo( x <- something ) should always be written as: x <- something foo(x) and for many cases I agree, but consider the counter example of: system.time( out <- longRunningSimulationFunction(n=1e6) ) compared to: out = longRunningSimulationFunction(n=1e6) system.time(out) I would argue that the 1st version is much more useful than the 2nd. On Mon, Feb 2, 2015 at 6:57 PM, Steve Taylor <steve.taylor at aut.ac.nz> wrote:> Responding to several messages in this thread... > > > > All the more reason to use = instead of <- > > Definitely not! > > Martin and Rolf are right, it's not a reason for that; I wrote that > quickly without thinking it through. An "=" user might be more likely to > fall for the gotcha, if not spacing their code nicely. So the lesson > learned from the gotcha is that it's good to space your code nicely, as > others have siad, not which assignment symbol to use. > > However, I continue to use "=" for assignment on a daily basis without any > problems, as I have done for many years. I remain unconvinced by any and > all of these arguments against it in favour of "<-". People telling me > that I "should" use the arrow need better agruments than what I've seen so > far. > > I find "<-" ugly and "->" useless/pointless, whereas "=" is simpler and > also nicely familiar from my experience in other languages. It doesn't > matter to me that "=" is not commutative because I don't need it to be. > > > Further it can be nicely marked up by a real "left arrow" > > by e.g. the listings LaTeX 'listings' package... > > Now that's just silly, turning R code into graphical characters that are > not part of the R language. > > > foo(x = y) and foo(x <- y) > > I'm well aware of this distinction and it never causes me any problems. > The latter is an example of bad (obfuscated) coding, IMHO; it should be > done in two lines for clarity as follows: > > x = y > foo(x) > > > Using = has it's problems too. > Same goes for apostrophes. > > Shall we discuss putting "else" at the start of line next? > > cheers, > Steve > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com [[alternative HTML version deleted]]