Originally posted by Luke_Wolf
View Post
- if expressions return values.
C++/C#/Java have the ternary operator
Code:
A x = (condition) ? b : c;
Code:
val x = if (condition) b else c;
- A class can return this.type so that "return this" returns the derived sub type. C#/Java require super complex use of generics to get a similar effect.
- Pattern matching. This is a key feature of the language.
- Native partial functions.
- Native function currying.
- for comprehensions. Scala's "for" is like a language native query engine. It works with any type with map and flatMap. If you use flatMap a lot, this is really nice. Standard types that define flatMap and are commonly used in for comprehensions are Option, List, Map, and Future.
- Option rather than null. Scala handles null for Java interop, but the Scala ecosystem uses Option instead of nullable values. C++/Java/C# are all primarily null based. Java 8 has Optional, but it's not used everywhere. F# and Haskell use Option (or Maybe). Also Scala's pattern matching and for comprehensions are ideal for supporting Option.
Lastly, I can't think of anything that C# or Java actually do better.
Comment