News for hackers. Stuff that matters.
Re:Scala: Where it came from, Where it's going by lmm on Tuesday March 17, 2015 @03:54PM (#9220863)
:+= and +:= are very unidiomatic. No they're not banned entirely and maybe they should be, but I think that would make certain people even more upset. But what you're supposed to use is x :+ y and x +: y; with either one x ends up before y, and if you got them the wrong way around then it won't compile. Likewise ::: versus :: - if you get it wrong, it won't compile (at least if you're using wartremover and/or strict compiler flags. Again, it would be nice to remove these misfeatures entirely - but given how much fuss there is about enterprise use and backwards compatibility, Scala has chosen to put a lot of effort into ensuring that old code still compiles).
Re:Scala: Where it came from, Where it's going by azinman2 on Wednesday March 18, 2015 @02:42AM (#9223968)
You missed my point. Symbols are cryptic.
Re:Scala: Where it came from, Where it's going by lmm on Wednesday March 18, 2015 @06:51AM (#9224613)
It's very rare that you'd need to read the difference between x :+ y and x +: y, or x :: y and x ::: y. All of those give very similar results (a list of x followed by y), so it's good that they look similar. If you know one and not the others, the very fact that they look similar is a big hint that they're doing something similar.
Re:Scala: Where it came from, Where it's going by azinman2 on Wednesday March 18, 2015 @07:07PM (#9229239)
I disagree 100%.

Prepend and append are very different. And you do need to know, because for many scala collections one is O(N) and the other is O(1) [1], plus the importance of knowing order.

The difference between x :: y and x ::: y could mean List(List(1), 2, 3) versus List(1, 2, 3).

[1] http://docs.scala-lang.org/overviews/collections/performance...

Re:Scala: Where it came from, Where it's going by lmm on Thursday March 19, 2015 @04:29AM (#9230779)
> Prepend and append are very different. And you do need to know, because for many scala collections one is O(N) and the other is O(1) [1], plus the importance of knowing order.

You know the order, at least in idiomatic code; "x :+ y" x comes before y, "x +: y" x comes before y. (There's a misfeature where you can sometimes write x +: y as y +: x, but don't do that; use brackets if you need to (x +: y))

O(N) versus O(1) is sometimes important but it is a detail IMO; anyone who cared about the distinction would already be reading the code very carefully, it's precisely the sort of thing that a casual reader should be able to gloss over.

> The difference between x :: y and x ::: y could mean List(List(1), 2, 3) versus List(1, 2, 3).

Exactly. Which the type system will catch; if you're using wartremover that will be an immediate error (inferred type containing Any), if not then you'll see an error as soon as you try to actually use the result.

Re:Scala: Where it came from, Where it's going by azinman2 on Thursday March 19, 2015 @05:06PM (#9234598)
To me :+ versus +: isn't obvious compared to saying .prepend or .append, which is my point. I shouldn't have to look that up.

As far as :: versus :::, depending on type inference it can be a much more later error that is confusing. The type error messages are cryptic compared to what it could say. Worse, if you then take it and serialized it to JSON or something then you won't even get a compile error, so it may not be for a while that you even realize there's and error and that can be hard to trace down depending on your code.

I really am failing to see why you're defending this. It's like trying to defend programming without a debugger because you have printf. Why not make things clearer, always? Why can't error messages be easier to understand and more human friendly? Shouldn't that be the goal?

Re:Scala: Where it came from, Where it's going by lmm on Saturday March 21, 2015 @05:25AM (#9242247)
.prepend wouldn't be able to use the : magic; once you're used to it "x :+ y"/"x +: y" is more intuitive than "x append y"/"x prepend y" because in the first example x always ends up before y.

> As far as :: versus :::, depending on type inference it can be a much more later error that is confusing. The type error messages are cryptic compared to what it could say. Worse, if you then take it and serialized it to JSON or something then you won't even get a compile error

Which is why you should use wartremover and strict compile flags ( https://tpolecat.github.io/2014/04/11/scalac-flags.html ), so that won't happen. (It would be nice to make these things completely illegal by default, but not nice enough to break backward compatibility over)

> I really am failing to see why you're defending this. It's like trying to defend programming without a debugger because you have printf. Why not make things clearer, always? Why can't error messages be easier to understand and more human friendly? Shouldn't that be the goal?

I think people really underestimate the value of conciseness. The difference between a function or class that fits on one screen and one that doesn't is really huge. For commonly-used operations, I'd rather pay the upfront cost of learning the symbols and be able to read shorter code forever.

Of course there's a tradeoff, and I do think certain scala libraries lean too far to the symbolic side. Sometimes I like to think about a programming language that didn't allow any symbols (e.g. you'd write arithmetic like "(1 plus 2) times 3"). But the extra characters aren't free.