Brian Candler wrote:
> Haris Bogdanovic wrote:
>> I know Ruby programming well but I wanted to add funtional paradigm in 
>> my
>> programming as it is very usefull.
> 
> If you know Ruby well - and you obviously understand functional 
> programming, because you know it is "usefull" (sic) - then just start 
> writing functional programs. To do this, make sure that:
> 
> 1. you don't modify any objects. Only use methods which return new 
> objects.
> 
> 2. once a local variable is assigned, you don't reassign it.
> 
> However Ruby won't enforce (1) unless you litter your code with 'freeze' 
> statements, and it can't enforce (2) at all.

Well then ... just as "it's possible to write FORTRAN programs in any
language", it's *possible* to write "functional" programs in any
language. But as you point out, a pure functional style "goes against
the grain" in Ruby, if it doesn't or can't enforce (or even diagnose)
"non-functional" code.

Programming is as much, or more, about communication among the
programmers and between the programmers and the users as it is about
communication between the programmers and the "machine." So if you have
to spend time saying, "this is functional code", you've already lost
something, and introduced opportunities for mis-translation.

In short, I suspect that a more practical solution might be a language
that has object orientation and functional coding styles both baked in
right from the start. I'm not an expert on all the dozens of "obscure"
languages out there, so I can't give any names. But I know they exist.

> Go and look at Erlang. Massive real-world systems are built out of this, 
> with incredible reliability, using only functional programming and CSP. 
> It's also very straightforward to pick up and use, and has a very 
> comprehensive standard library.
> 
> Remember also that functional languages allow all sorts of compile-time 
> optimisations which are impossible in Ruby, so there is the potential 
> for much higher performance. For example, OCaml generates code which is 
> reputedly only half the speed of the equivalent C code.

Did you mean "twice the speed?" Is OCaml faster or slower than C? And why?