Home - RobertMakyla/scalaWiki GitHub Wiki
Scala - scalabla language, which grows with people's demands.
Object Oriented programming
... was so successful and is so popular, because all but some trivial programs need some structure. It was natura to enclose some structure and provide some functionality to it in some containers (objects)
Scala is Object Oriented in a pure form
Unlike in Java, even 1+1
is using Int.+()
method. Any value is an object and opration is a method/function call.
Functional Language
map/fold/forEach instead of loops which are error-prone
Option rather than null (To avoid NPE, java started using @Nullable and if not then we assume null is impossible)
Functions as values
I can pass them as parameters, store in variables, define it anywhere
- clearness, more flexibility
Functions have no side effects. Data should be immutable
- reduces concurrency problem
Looking just as String, Java is a functional language. Because Strings are immutable in Java (s.replaceAll(";", "") yields new string object, not modifying the old one)
- scala is better than java - it has many immutable types: lists, tuples, maps, sets
##Other Scala pros
Scala is High level language
I am coding what it is rather than how to construct it. To filter some Map, in Java it's 10 lines, in Scala just 1
- concise - zwięzłość
Scala is statically typed
Statically typed languages - safe but too verboose, too much (unnecessary) declaring Dynamically types languages - no declating but unsafe, programmers don't know what the type is
- Scala is statically typed - so type is always verifiable, but no need for declarations cause it's computed by compilator :)
Scala gives choice
Imperative style (mutable data, side effects) and/or Functional style (immutable data, no side effects).
- That's why I can use existing Java libraries, but also I can start programming in a functional way.
Scala is compatible
- runs on JVM
- no need to rewrite existing java programs, just add scala part :)