Scala: Suggestion for an idea for a hands on session
functional-programming, scala
Solution
A wonderful example is developing a little interpreter for a dynamic mini-language.
The basic java implementation requires the classical interpreter design pattern, whereas a functional scala-approach can use many wonderful functional idioms like
- case classes
- pattern matching
- higher-order functions
or maybe even monads in order to produce very clean and easily understandable code.
Just compare
class Number implements Expression {
private int number;
public Number(int number) { this.number = number; }
public int interpret(HashMap<String,Integer> variables) { return number; }
}
with
case NumberLiteral(i) => Integer(i)
See the interpreter examples at the scala page.
Problem
I want to give a Scala presentation and I want to do it by taking an application and evolve it from something which uses java idioms to something that uses the power of scala (traits, pattern matching, implicit convertions, functional programming). I'm especially interested in something that demonstrates a design change, rather than syntactic sugar. Something where the end scala code is evidently easier to maintain and extend. So any ideas? (I'm not asking for code examples, just the rough ideas of what example to use and what design principles can be demonstrated).