Re:Goodbye, shitty "Car extends Vehicle" object-orientation ...
by fleitz on Tuesday August 23, 2011 @02:58PM
(#2917891)
IMHO it's largely a side effect of first class functions. In Java in order to pass a function you need to pass an object that has the function, or an interface with the function, so it leads to a lot of line noise and thus people don't do it much. DI doesn't look impressive in a functional language because it's so well supported, but if you look at something like a global accumulator in a functional language you'll need a monad because you need state.
eg in Java it's easier to write:
int accum = 0;
for(int i : collection){
accum +=i;
}
rather than
collection.reduce(new IReduce<int> {
int reduce(int accum, int i){
return i + accum;
}
})
I'm a bit rusty on Java so the syntax may be off but you get the idea, where as in a functional language (F#) that code is reduced to:
collection
|> Seq.reduce +
Or in an imperative language that supports function passing (C#)
eg in Java it's easier to write:
rather than I'm a bit rusty on Java so the syntax may be off but you get the idea, where as in a functional language (F#) that code is reduced to: Or in an imperative language that supports function passing (C#)