News for hackers. Stuff that matters.
Re:Why Does “=” Mean Assignment? by chasedehan on Tuesday April 10, 2018 @06:46PM (#16806300)
In R, it is actually distinguished that way, example:

a <- a + 1

a + 1 -> a # also works, but REALLY bad practice

But, so does

a = a + 1

Granted, there are a bunch of R haters (especially from people with formal CS educations), I think this convention makes a lot of sense. While most will disagree about the '<-' I like it from a code reading sense in that you know that it is an assignment right away. Coming from a mathematical perspective before learning to code, this makes a lot more sense in the 'assignment' fashion.

In case you are wondering, the difference between <- and = in R is in scoping. For example, in the following function call:

foo(x = 'value')

x is declared in the scope of the function, whereas:

foo(x <- 'value')

x is now declared in the user environment. Granted, that is not good practice, but that is why there is a difference.

Re:Why Does “=” Mean Assignment? by Myrmornis on Tuesday April 10, 2018 @11:10PM (#16807732)
> Granted, there are a bunch of R haters (especially from people with formal CS educations), I think this convention makes a lot of sense.

To be clear, the assignment syntax is great, it's other things that are the target of R haters' hate! Like a high-level language without hash tables.

Re:Why Does “=” Mean Assignment? by lionel- on Wednesday April 11, 2018 @05:42AM (#16809464)
You can use environments for hash tables.
Re:Why Does “=” Mean Assignment? by thalesmello on Tuesday April 10, 2018 @07:26PM (#16806618)
`->` is a bad practice? I like to use it at the end of a long `%>%` pipe. Reading the whole thing feels a lot more natural.
Re:Why Does “=” Mean Assignment? by chasedehan on Wednesday April 11, 2018 @11:32AM (#16812172)
The first time I ever saw that you could do that was in a blog post about stringing at the end of the a series of pipes. I thought it was pretty neat (and actually used it a couple times), then had problems when I couldn't figure out why my code was messing up.

for example, this assigns a ggplot to 'plot': df %>% na.omit() %>% ggplot(aes(x=x, y=y)) + geom_line() -> plot

That is really confusing in that the way most people would read it is that it is something to be plotted. However, the assignment does occur and is masked. having 'plot <- df %>%' as the first line makes it clear that a new object is being created.

We actually had to modify our style guide to prevent the '->'

Re:Why Does “=” Mean Assignment? by lionel- on Wednesday April 11, 2018 @05:41AM (#16809461)
It is bad practice because you are hiding the side effect.