
On Wed, Jan 31, 2007 at 13:36:02 +0200, Yitzchak Gale wrote:
Bulat Ziganshin wrote:
FP way is to represent everything as function, imperative way is to represent everything as algorithm.
Magnus Therning wrote:
Neither way may be "natural", but imperative thinking is extremely common in society, I'd say much more than "functional" thinking. Just think of cooking recipes, IKEA instructions, all the algorithms taught in math classes in grade school.
Those are not imperative thinking - they are sequential thinking. There is nothing non-functional about describing an algorithm in sequential form.
Sequential thinking would be related to procedural programming, that is ordering of statements are important but there's no state. Functional programming is declarative, no order and no state. So, to be strict I'd say that sequential form _is_ non-functional. At least if FOLDOC is correct and I read and understood things properly. I'm assuming that imperative implies state _and_ order.
Imperative means requiring that the steps always be followed exactly. People do not follow the steps of a recipe exactly - they just use the recipe to understand what needs to be prepared. Same with your other examples.
When cooking we have a state--the kitchen/workbench/dish. We have a sequence of steps--the recipe. Yes, it's possible to re-arrange that sequence, cooks do that all the time, based on experience. But that's just optimisation. The optimisation done by a C-compiler doesn't change the nature of the language from imperative to procedural or declarative, does it?
That's why I think that the oposite is true - declarative style is more natural. Just describe what you want to be computed. If that is best described as a sequence of steps, fine, if not, not. But in either case, you are not forcing a CPU to follow the steps blindly.
The world has state! Just see what a "stink" that has created in the pure functional language camp! Your arguments have actually strenthened my conviction that we as humans find imperative to be more "natural" than both sequential and declarative. :-) Just too bad that in this case "natural" doesn't correspond with "best" :-( /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus