4 ms·
Believe it or not, but java can be written functionally: you have to use an interface (and a few classes) to implement a list and you can use objects as functio
by speek 18y ago
Believe it or not, but java can be written functionally: you have to use an interface (and a few classes) to implement a list and you can use objects as functions... but it's not usually something people get into.
- eru 18y agoIt can be done. But it's not pretty. Cumbersome and verbose.
- gaius 18y agoAnd the libraries are full of side effects.
- speek 18y agoWho needs libraries for non-destructive programming in java? You can just use an interface for a list of T (ILoT), a representation of an empty list (MtLoT), and a ConsLoT which has a first (which is of the type T) and a rest (which is of the type ILoT). Bam, you've got a list implementation ( new ConsLoT(new T(arg1, arg2, argN), new ConsLoT(new T(argA, argB, argN), new MtLoT)); ). Function objects are a little different though (http://en.wikipedia.org/wiki/Function_object#Functors_in_Java http://en.wikipedia.org/wiki/Function_object#Functors_in_Jav...).
- eru 18y agoWhy are you so fixated on lists? There is more to functional programming than that.
- jrockway 18y agoWhy bother? Round hole, square peg. You will spend 99% of your time fighting against the language, instead of writing code.
- brl 18y agoNot only will you fight against the language, but the functional style code you produce will be awkward and unreadable by other Java programmers. If this doesn't matter because you are working alone, then why would you choose Java in the first place?