4 ms·
I don't even view Scala as a functional language, as functions (methods) are not first class. Lambdas are encoded as objects with a single method. It's much mor
by grumpyprole 5y ago
I don't even view Scala as a functional language, as functions (methods) are not first class. Lambdas are encoded as objects with a single method. It's much more expressive than Java and so better at expressing many functional programming ideas, but it's not a functional-first language, it's an evolution of Java.
The underlying issue is that it's a complex language with many experimental and interacting features, which can and do cause a lot of distraction. This is not the fault of functional programming. Have a go at OCaml or F#, which are nice practical sweet spots.
- hocuspocus 5y agoThe JVM has had specialized bytecode for SAM types for a long time now, you cannot really get more "first-class" than that. And really it's just an implementation detail than doesn't make the language more or less functional. Scala isn't simply an evolution of Java. It offers a type system that goes beyond what you can do in F# or OCaml. The fact it's multi-paradigm and plays nice with Java's OO model doesn't make it less functional than these two.
- grumpyprole 5y ago> it's just an implementation detail than doesn't make the language more or less functional. It affects the language very much, awkward currying and tupling, needing to wrap methods in objects. Subtyping also has many complex consequences. There is limited type inference and tail call optimisation versus functional-first languages. > Scala isn't simply an evolution of Java. It offers a type system that goes beyond what you can do in F# or OCaml. It offers higher-kinded types, but F# has units of measure, OCaml has polymorphic variants. Each has advanced features not offered by the other. > The fact it's multi-paradigm and plays nice with Java's OO model doesn't make it less functional than these two. It was not designed as a functional programming language first and foremost, that is my point.
- captaincaveman 5y agoI'll also add that scala/functional engineers are also more likely to focus their energies on monads and type theory rather than product delivery. I get that it is probably more intellectually stimulating for many engineers than the project they are working on, but it also reflects in over engineering of distributed systems for simple problems. I do wonder if there is really any net gains for a company to go the functional route. I would love to see some research on this as people have been championing it for decades now, and seems suspiciously absent!
- hocuspocus 5y ago> I'll also add that scala/functional engineers are also more likely to focus their energies on monads and type theory rather than product delivery. Then how do you explain that a very significant number of "top" tech companies have teams who manage to deliver products written in Scala or other FP languages?
- captaincaveman 5y agoTeams have managed to deliver products in also sorts of languages, Cobol for example. Did the choice of language benefit the delivery, maintenance and TCO is my question. If I choose Haskell/Scala over Java (FYI as a programmer I'm not a fan of Java) what benefit will it actually bring the business, and does it out weight the negatives, over what time frame and how much risk?
- hocuspocus 5y agoThere are technical tradeoffs everywhere. But you cannot make a caricature of FP developers, supposedly not willing to spend energy on delivering products. Lots of tech companies have proved that you don't need to follow Google and constrain your workforce to a small list of vetted languages. Most teams who chose Haskell, OCaml, Scala, Rust... are productive and able to deliver products.
- captaincaveman 5y ago
- hocuspocus 5y ago> It affects the language very much, awkward currying and tupling, needing to wrap methods in objects. That is a lot less true since Scala 3. > Subtyping also has many complex consequences. Sure. But it also means I can use any library from the Java ecosystem, and that's a huge reason behind the big number of Scala jobs compared to other FP languages. > There is limited type inference and tail call optimisation versus functional-first languages. Limited type inference is typically what I (and my team) want, for the sake of self-documentation. Scala's type inference is plenty enough, and the few corner cases that were annoying in Scala 2 should be fixed in Scala 3. Tail-call optimization is done the compiler. The lack of tail-call elimination is bothering the few maintainers of functional libraries that need to implement CPS and trampolines, but not really something the average developer will have to worry about. And it should come to the JVM with Loom, eventually. > F# has units of measure Scala offers more generic ways to do the same thing. Would F# need such a feature at the language-level if it had typeclasses? > OCaml has polymorphic variants I believe most people don't want structural typing in their GADTs. > It was not designed as a functional programming language first and foremost, that is my point. I don't think Martin Odersky would agree. It's not an either/or situation. Scala was designed to be a full-fledged functional language, and OO hybrid, compatible with (and leveraging) the Java OO model, and offering a strong type system that goes beyond what you find in most FP languages.
- sideeffffect 5y ago> awkward currying Personally, even though I haven't really thought it through deeply, I feel like Scala would be better if everything were curried. > Subtyping also has many complex consequences But also substantial benefits! > There is limited type inference I wish Scala would improve in this regard. Maybe paradoxically, inference works better with code tuned for subtyping and variance. > tail call optimisation This will be fundamentally solved by Project Loom. At least on the JVM (there's also Scala on JS and on LLVM). > F# has units of measure I dearly miss those. Type Providers even more so. > OCaml has polymorphic variants Could be nice in Scala. Or maybe not, can't tell now. And there's always the risk of too many features, which makes a language worse, not better. > It was not designed as a functional programming language first and foremost This is misleading at best. It was designed to show that the distinction between OOP and FP is arbitrary, not fundamental. In other words, Scala erases the distinction, it's fully OOP and fully FP. Scala has higher order functions, ADTs, pattern matching, a module system, like SML/OCaml. But it uses keywords `class` and calls it's instances "object" like Java. And it's interoperable with Java. But theoretically there's no fundamental distinction. More languages are becoming more and more like Scala, btw. https://www.lihaoyi.com/post/FromFirstPrinciplesWhyScala.html https://www.lihaoyi.com/post/FromFirstPrinciplesWhyScala.htm... And the concept of a programming language paradigm is fake from the start anyway ;) https://www.cambridgeblog.org/2017/05/what-if-anything-is-a-programming-paradigm/ https://www.cambridgeblog.org/2017/05/what-if-anything-is-a-...
- grumpyprole 5y ago> This is misleading at best. It was designed to show that the distinction between OOP and FP is arbitrary, Possibly misleading yes, it is certainly a subjective point. I guess it reflects the struggle I had doing FP in Scala versus alternatives. I don't think I'm alone either, the Haskell community contains a lot of Scala refugees. Note that I have not looked at Scala 3.
- sideeffffect 5y ago> doing FP in Scala versus alternatives I think Scala is the language most actual functional programming on this planet takes place these days. Be it just FP or pure FP. I especially like pure FP in Scala. One can do that with Cats Effect (from the TypeLevel family of languages) or ZIO. They're both awesome, so check them out and pick what you'll like best. https://typelevel.org/cats-effect/ https://typelevel.org/cats-effect/ https://zio.dev/ https://zio.dev/ You don't even need to reach out to Scala 3 (still not as mature in its tooling support), you can have a great time with the latest Scala 2 (2.13). > versus alternatives I think of Scala as a opinionated take on ML and a module system that is tailored to JVM (and is seamlessly interoperable with Java) that just happens to have syntax heavy on braces/parentheses. Otherwise, what's not to like? :)
- barrenko 5y agoYup, Scala is to Haskell what F# is to Ocaml.
- 62951413 5y agoI remember perusing a book on ML (the language) and having aha moments such as "so this is where the '_' naming convention comes from" and "this is where pattern matching was borrowed from". Monads (aka zio/cats) are not built-in, the "lazy" keyword is a far cry from strictly lazy evaluation. I say "Scala to Ocaml" on the JVM is equivalent to "F# to Ocaml" in the .NET world (there must be some category theory joke in this topology).
- sideeffffect 5y ago> Scala is to Haskell what F# is to Ocaml That's not quite precise, IMHO. F# is an awesome language that I hold very dear, but it is a castrated form of OCaml. It has only a few features that OCaml doesn't have. For example Type Providers or Unit of Measurement. These are nice and useful features, they're not gimmicks, but they're not fundamental. On the other hand, Scala isn't a hollowed out Haskell. Haskell, admittedly, is a more powerful language and has features Scala doesn't, like a linear type system. And it's just different, non-strict, whereas Scala is strict. But Scala is also very powerful in other fundamental areas, where Haskell is weak. Scala has a superior module system, it's biggest strength IMO. Haskell's modularity story is that great AFAIK.
- sideeffffect 5y ago> I don't even view Scala as a functional language, as functions (methods) are not first class. Lambdas are encoded as objects with a single method. It's much more expressive than Java and so better at expressing many functional programming ideas, but it's not a functional-first language, it's an evolution of Java. It' technically true that Scala's fundamental building block is object, not function. But that is in my eyes more of an implementation detail. Scala is a language that blurs the distinction between FP and OOP to the point of meaninglessness. You can do FP and still organize your code into classes/objects/traits (aka modules). You can choose to do side effects. Or you can waive them and do pure FP (like in Haskell) with TypeLevel or ZIO. > it's an evolution of Java I would say that it's kanda the other way around. Scala is a beacon that almost all languages are converging towards, not just Java. https://www.lihaoyi.com/post/FromFirstPrinciplesWhyScala.html https://www.lihaoyi.com/post/FromFirstPrinciplesWhyScala.htm... > complex language with many experimental and interacting features It doesn't have that many features. Some people even call Scala simple for this reason. But the features that is has are _very_ powerful. Some maybe even too powerful for my taste (implicit conversions anyone?). And they're orthogonal so they can be composed together. Sadly, such composition can be brittle and non-beginner friendly, especially when it fails -- things like weird type errors or weird unexpected behavior at runtime, or compiletime for that matter, etc. So Scala will give you a lot of rope to hang yourself onto, if you'll be blindly taking it. But it doesn't have to be that way. You (or a senior developer) have to know what you're doing. Then you can reap significant benefits. It's good news that Scala 3 significantly improves on this front -- it emphasizes programmer's intent instead of Scala's internal mechanics. Sure, in some languages, this risk isn't even on the table (Go, etc). But having power also comes with benefits, not only the potential problems I've described above.
- grumpyprole 5y agoI'd be interested to see Scala 3, my comments/opinions apply to Scala 2 only.