5 ms·
What's an example of something they made more approachable? One of my first impressions of Scala, which I have barely seen, and do not know, is that there is a
by Buttons840 5y ago
What's an example of something they made more approachable?
One of my first impressions of Scala, which I have barely seen, and do not know, is that there is a lot of syntax. Has anything been done to help with that? I don't think syntax matters much, but it's one of the only impressions I have of the language and wanted to ask about it.
- OOPMan 5y agoThat's an interesting take, as someone that's used Scala for a while I feel like there actually isn't that much syntax. I guess my perception is warped :-)
- valenterry 5y agoI agree. But Scala still does certain things different, so to a Java or python dev it _looks_ as if there is a lot of syntax. Just like Haskell looks strange when you look at it for the first time.
- tormeh 5y agoI don't think people object to the language syntax itself, but rather the unfamiliarity and randomness of language conventions. Haskell/Perl/K/Scalaz is full of line noise I can't be bothered to learn, for example
- patrickthebold 5y agoScala has a lot of 'sugar': f(...) becomes f.apply(...) matching calls unapply with some various binding. Some parenthesis are optional: Some(1,2,3) is Some((1,2,3)) optional . so a + b is a.+(b) colon changes associativity, so a +: b is b.+:(a) for expressions become, map, flatMap, filter, withFilter and forEach, according to various rules. def f[A: B]() adds an implicit parameter of type B[A] I'm sure there's more but that's the top of my head. Of course it's not actually a long list, but none of that is obvious for a newcomer.
- nikitaga 5y agoThe fact that you can make any instance callable like a function by adding an `apply` method to it isn't just "syntax sugar", it's a pretty fundamental mechanic of FP-OOP fusion that Scala is built around. Same for `unapply`. At any rate none of this "sugar" was a problem to anyone I know who learned Scala. There are harder things about it than learning basic syntax.
- dyadic 5y agoIt’s a long time since I used scala and none of this was ever a direct problem, but it was all extra complexity. I think there’s a split between people that appreciate sugar and people that find it not worth the additional complexity. That problem does lessen with familiarity, but knowing a lot of complexity makes me wary of unknown complexities. It adds an overhead which takes energy that could be better utilised elsewhere.
- nikitaga 5y agoIf you don't need that "complexity" (I wouldn't call it that), you can use a pure FP or a pure OOP language that will be simpler, smaller, but more restrictive and less expressive. That's a matter of preference of course. But Scala's syntax and language features are great when you actually make use of them to accomplish your goals, especially so with Scala 3. The syntax isn't excessive or frivolous or nonintuitive. It's a pretty straightforward encoding of the desired feature set of the language.
- patrickthebold 5y agoWhy do you consider it fundamental? Are there examples where it fundamentally does more than saving you from typing out the canonical method name? (This is for `apply`, I agree that match with unapply is actually language syntax and not sugar.)
- nikitaga 5y agoBecause it enables an equivalence between functions and objects. Not a technical one that's hidden deep in the implementation, but a practical one that's apparent to library authors and users. If you want to make any object `foo` callable with first-class application syntax, i.e. `foo(bar)`, you add an `apply` method to that `foo`. You don't need to bother extending Function, you don't need to come up with a method name and call that. When you call `foo()`, you don't know if `foo` is a function or an object, and you don't care. You can find out easily with a half decent editor of course, but the point is, you're free to mix objects and functions as you wish, the language does not get in your way. And for all that it provides, it's a complete non-issue in terms of learning curve. It's a basic language feature that you learn once and are never impeded by thereafter.
- peq 5y agoScala is one of the smallest typed languages in terms of syntax. See slide 13: https://www.slideshare.net/Odersky/preparing-for-scala-3#13 https://www.slideshare.net/Odersky/preparing-for-scala-3#13 With scala 3, syntax has been simplified even more, e.g.: No more braces necessary. Top level declarations. Extension Methods.
- stock_toaster 5y ago> No more braces necessary Optional braces seems like a weird feature to me. I would prefer consistently. I think a language should either be "bracey" or not. Just pick one!
- harveywi 5y agoI personally wanted to be able to use underscores instead of braces.
- oxnrtr 5y agoJoking? Scala 3 added 20 keywords (14 of them contextual), many of them with entirely new syntactic constructs behind it.
- cbolton 5y agoI think "lots of syntax" means many rules to learn, rather than many characters to type. So this change means even more syntax.
- phillipcarter 5y ago> Scala is one of the smallest typed languages in terms of syntax. Eh, that slide isn't really worth looking into. None of the languages there have a uniform way to represent the grammar. If you look at the C# and Scala grammars you'll find that the Scala one is highly compacted, whereas the C# grammar is intentionally not compact. They're encoded in different formats.