Version française
Home     About     Download     Resources     Contact us    
Browse thread
Avoiding shared data
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Oliver Bandel <oliver@f...>
Subject: getting used to FP-programming (Re: Ant: Re: Ant: Re: [Caml-list] Avoiding shared data)
Hello Martin,

On Sat, Oct 01, 2005 at 11:36:08PM +0200, Martin Chabr wrote:
> Hello Oliver,
> 
> I am trying to find a programming style within the
> spectrum of possibilities which OCaml supports. This
> programming style should be easy to produce, easy to
> read and efficient in runtime.
> 
> Sometimes a nested system of "for" or "while" loops
> appears simpler to me than a system of recursive
> calls. Sometimes such systems of recursive calls
> remind me of undisciplined goto jumps.
[...]
> general, for the real world problems, it is much
> worse. I cite the author:
> "That was a brief overview of tail recursion, but in
> real world situations determining if a function is
> tail recursive can be quite hard." I believe him.

I doubt it is.
Or maybe if the people write functions that are some
pages of code long. But it's better to keep the functions short,
and FP makes this very easy.

[...]
> I think that some problems, like simple operations on
> lists, can be easier described by pattern matching and
> recursion, whereas for others it appears more natural
> to take loops.

Yes, but when you are used to FP-style and recursions
the amount of problems one would rather use the
for/while loops for, gets smaller.

I just dome days ago saw this on an example-code I wrote
in a discussion on the berlin' Linux-User-Groups mailing list
(I'm doing some marketing for OCaml;-))
I first thought, well the better version is with loops.
But I tried the recursive definition and it was astouningly
easy to read. :)

So IMHO it's how often you tried the different programming style,
what makes you thinking different about this.

> 
> I also think that what looks simple or not depends on
> the person. I myself have spent half of my life with
> imperative languages.

Mee too for many years, and "depends on the person" could also be said
as: "depends on the experience of the person", and as I more and more
get used to FP constructs, I see the problem solving diferently than
some time ago.

Ciao,
   Oliver