4 ms·
> operators (not named functions) are to programming > languages as icon-only buttons are to web pages; > they are completely unusable. I see ( ) ; . you a
by jxy 10y ago
> operators (not named functions) are to programming
> languages as icon-only buttons are to web pages;
> they are completely unusable.
I see ( ) ; . you are using already. Latin letters are gibberish to people who don't use it.
- rvense 10y agoI wrote some Scala just today: val list = a +: l :+ b And I knew I had to put in a comment because that stuff always makes my eyes cross over when I come back to it.
- pmontra 10y agoI don't know Scala and I have no idea of what +: :+ means, which at first is not a good sign (think about onboarding.) Then I remembered that many mainstream languages have the a ? b : c construct which maybe was equally puzzling when it was introduced by CPL in 1963.
- billrobertson42 10y agoScala can be extended by users with stuff like that.
- pekk 10y agoThe fact that C-style ternary is hard to pick up doesn't really excuse this kind of thing in new languages.
- rvense 10y agoThey're operators that cons an element on to a list. They're both defined on the List class, but differ in associativity because they start/end in a colon. "a +: l" calls the +: method on l with a as its argument and returns a list with a added to the start, "l :+ b" calls the :+ method on l with b as its argument and returns a list with b added to the end. "a +: l :+ b" (parsed as "(a +: l) :+ b") therefore returns a copy of l with a added to the start and b added to the end. This is user definable, you can make operators whichever way you like (and start them with : if you want them to be right associative). It's very flexible and you do sort of get used to libraries using it, but I'm not entirely sure that getting used to something always means it's good. (TBH though, I use the ternary operator constantly and think nothing of it.)
- jxy 10y agoもっと練習 ⍝ Practice more NB. ⍝ is a symbol for comment. /* NB. is for comment, too. */ // Anything inside /* */ is comment, too. # // starts a comment, too.
- talideon 10y agoDon't know Scala, but I'd assume that `+:` is prepend to list and `:+` is append to list.
- rvense 10y agoYou'd be correct. But they're just method calls, both defined on the class of l. It is a little weird.
- jfb 10y agoI can see the argument for terseness in source, particularly in domains where the terseness in code reflects well-understood shorthand in the actual problem space. But stuff like that makes me itch, to be honest.
- rvense 10y agoThe alternative would be something like l.prepend(a).append(b) Horrible. Ghastly. Can't see anybody tolerating a language that looked like that.. /s
- jfb 10y agoWhat? Mutating a list? DISGUSTING!
- speedkills 10y agoIt's not mutating, its returning a new list with elements prepended and appended.
- yawaramin 10y agoIt gets even worse. Because Scala has infix syntax for method calls, you can do l prepend a append b
- snoman 10y agoDon't know Scala but why wouldn't it be a.append(l).append(b) ?