Scala overview

a feature

1. Scalable programming language
2. Pure object-oriented language
3. Functional languages
4. Seamless java interoperability
 
Two functional programming ideas
1. What is functional programming
"It's just writing programs with pure functions"
Pure functions, or the purity of functions, have no side effects.
A side effect is a change in state.
For example: global variables are modified, exceptions are thrown, IO read and write, and functions with side effects are called.


 
In the above example XplusY_V1 has no side effect on X, it is a pure function.
XplusY_V2 has side effects on X.
2. Referential transparency
Always get the same output for the same input.
3. Pure function
A function f is pure if both the parameter x of f(x) and the function body are referentially transparent.
4. Example: Violation of referential transparency.


 
The append function violates referential transparency.
5. Immutability
For referential transparency, no value can change.
6. Functions are first-class citizens
Everything is computation, in functional programming there are only expressions, variables and functions are expressions.
7. Expression evaluation strategies: strict evaluation and non-strict evaluation.
8. Lazy evaluation.
It is not evaluated when it is defined, it is evaluated only when it is used for the first time.
9. Recursive function
Recursion implements looping and tail recursion.
 
Three functional programming advantages.
1. High production efficiency: For programs with the same function, the length of Lisp code is only one-seventh to one-tenth that of C language.
2. Easy to reason about.
3. Parallel programming
4. Multi-core computing, cloud computing.
 
The Rise of Four Functional Programming
Moore's Law
multi-core processor
Cloud computing era

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326980289&siteId=291194637