Very detailed and serious comparison of functional and imperative programming styles
secretGeek .:dot Nuts about dot Net:.
home .: about .: sign up .: sitemap .: secretGeek RSS

Very detailed and serious comparison of functional and imperative programming styles

Very detailed and serious comparison of functional and imperative programming styles

Alright, it's not a detailed and serious comparison of functional and imperative programming styles.

It's just a modification of a picture that accompanied an article in american scientist magazine, written by Brian Hayes.

I've been thinking about functional programming since i read 'functional programming for the rest of us', last week. fascinating topic for your geeky-minded kid like me.

'Currying' and 'Pattern-Matching' look like two pieces of syntactic cleverness that could be baked straight into any .net language.


Very detailed and serious comparison of functional and imperative programming styles




'Wesner Moise' on Mon, 26 Jun 2006 05:09:10 GMT, sez:

Functional styles can have variables... it's just that there is a limit of one assignment per variable.



'lb' on Mon, 26 Jun 2006 05:15:28 GMT, sez:

>a limit of one assignment per variable

if you can only assign to it once then maybe it's not exactly "vary-able" ?

it's more of a 'result' or a 'value' (or a function?) ?

i know i'm no expert on this stuff at all,... i've only read the articles listed above... in 'functional programming for the rest of us' he refers to this kind of variable as a 'symbol'



'optionsScalper' on Wed, 28 Jun 2006 02:17:14 GMT, sez:

Secret Dude,

". . . 'Currying' and 'Pattern-Matching' look like two pieces of syntactic cleverness that could be baked straight into any .net language. . . ."

Already there in F#. lambdas, closures, etc., etc.

But, I totally agree. This is the most detailed comparison that I have seen in years. Your choice of colors in your exhibit is likely the feature which makes this whole explanation useful.

BTW, F# allows for imperative AND functional program constructs in the same body of a program. Two-for-the-price-of-one kinda stuff.

---O

p.s. A few other .NET languages get into this stuff too, but I'm only an evangelist for this F# stuff ( http://cs.hubFS.net ). If you are a serious student of FP, then a useful text is Chris Okasaki's "Purely Functional Data Structures".



'lb' on Wed, 28 Jun 2006 02:30:18 GMT, sez:

phew... an F# dude read this post and didn't totally flame me... pure luck maybe.

still sweating on dipping my toe into a big ocean of misunderstanding...

and i know that .net framework 3 will lean on FP ideas more, but i don't really know where...



'ags' on Thu, 29 Jun 2006 09:47:01 GMT, sez:

.net framework 3? Can't call it *that* anymore!



'Wesley Shephard' on Thu, 29 Jun 2006 14:08:51 GMT, sez:

F# was the incubation ground for many of the functional pieces that will be in the next major framework version (whatever they will call it). F# had to build it on top of the CLR, while the new CLR will have support for such functional ideas baked in. Mmmmm. Baked lambdas.



'WaterBreath' on Thu, 29 Jun 2006 15:47:33 GMT, sez:

This is a nice illustration of the syntatic and executional differences between functional and declarative programming languages. What we need next is a nice illustration of when and why functional can be better than declarative.

The first thing a curmudgeonly programmer who loves him some declarative programming will see is a runaway call stack. This example looks ok for 4 iterations. But what if the scenario called for a thousand, or a million? That's a million context switches: a million parameter lists, a million code pointers, etc.

Not being particularly experienced with functional programming, I would assume this runaway scenario is avoided either explicitly by some other language feature not shown here, or implicitly by the compiler/optimizer. This type of information is "need-to-know" for people wanting to know "what can a functional language do for me?"



'lb' on Thu, 29 Jun 2006 21:09:40 GMT, sez:

re:
>.net framework 3? Can't call it *that* anymore!

i was careful to say 'framework' as opposed to just .net 3...

what i mean is... the next major version of the .net libraries and .net clr...

not "the next big package from microsoft that has a .net sticker on it".



'lb' on Thu, 29 Jun 2006 21:12:00 GMT, sez:

>a runaway call stack

yep, i'm certain they do stuff about this...

a nice little description of what they do, and how would be fun to read.

>curmudgeonly programmer who loves him some declarative programming

love it.

>Mmmmm. Baked lambdas

I like mine curried!



'Wesley Shephard' on Fri, 30 Jun 2006 15:32:08 GMT, sez:

The runaway call stack is avoided by "tail recursion" optimization. If the recursion is the *last* thing being done on a call path (which it is in the example program here), there is no reason to maintain the stack frame anymore.

So instead of pushing a stack frame, we call the recusive call in the context of the old stack frame, and when it returns there is only that single stack frame (the initial call) to pop off.



'WaterBreath' on Fri, 30 Jun 2006 16:19:15 GMT, sez:

> we call the recusive call in the context of the old stack frame

Kind of like a GOTO... But _after_ compile, so it's not "considered harmful". ;)

> when it returns there is only that single stack frame (the initial call) to pop off

Very interesting. So sounds like this type of example would compile down very similarly to a traditional explicit loop. Good to know. I am still curious about more complicated scenarios--things less arithmetical--but I suppose I can look into that for myself. =)

Anyway, thanks!



'mqb' on Wed, 08 Nov 2006 19:58:22 GMT, sez:

> If the recursion is the *last* thing being done on a call path (which it is in the example program here)

Not to be too pedantic, but technically in this example tail recursion isn't applicable. The last operation being performed is a multiplication, not a recursive call. (n*factR(...)).

There are ways of transforming recursive calls that are not properly tail recursive to improve performance and to avoid over-exercising the stack. I am not entirely certain if the compiler(s) will do this transformation automatically.



'Invisigoth' on Thu, 12 Apr 2007 20:53:27 GMT, sez:

or you could make it TR by doing this:

fact(n) = fact_aux(1,n)

fact_aux(m, n) = if n == 0 then return m
else fact_aux(m*n, n-1)

you can probably convert any recursive function to be TR



'hellfeuer' on Mon, 25 Jun 2007 16:28:58 GMT, sez:

re: f#

it was not really the "incubation ground" for the functional pieces to add to the .net framework...
its merely a port of the OCaml programming language to the .net framework
SML.net is similair, and meant for the SML/NJ language (which is very similair to Ocaml)
i'm



'hellfeuer' on Mon, 25 Jun 2007 16:29:29 GMT, sez:

whooops.. i dunno how that "i'm" got ther..




name


website (optional)


enter the word:
 

comment (HTML not allowed)


All viewpoints welcome. But the right to delete any post for any reason is reserved. Don't make me do it. Comments may be republished, emailed to your loved ones or printed and used as toilet paper. Who reads this legal bit anyhow?

TimeSnapper is a life analysis system that stores and plays-back your computer use. It makes timesheet recording a breeze, helps you recover lost work and shows you how to sharpen your act.

TimeSnapper won last year's Developer Competition at Larkware.com, and is used by over 10,000 people.

Articles

SQL Style Extensions for C# SQL Style Extensions for C#
The Movie Hollywood (And My Wife) Doesn't Want You To See: Weekend at Jacko's The Movie Hollywood (And My Wife) Doesn't Want You To See: Weekend at Jacko's
Sysi: the ultimate administrators toolkit Sysi: the ultimate administrators toolkit
Movie: Priest Academy Movie: Priest Academy
Inspirational Rat Story Inspirational Rat Story
A face-melting DSL that allows programming ON the iPhone (and iPad) A face-melting DSL that allows programming ON the iPhone (and iPad)
The secretGeek Disaster Recovery plan The secretGeek Disaster Recovery plan
Save KNVTn! Before it's too late Save KNVTn! Before it's too late
The Ultimate Agent of WERF Destruction The Ultimate Agent of WERF Destruction
The new prisoner's dilemma The new prisoner's dilemma
Original Premise for a road movie Original Premise for a road movie
What's a better game than Devshop? What's a better game than Devshop?
DevShop: The Cool Game that Makes Development Look Fun DevShop: The Cool Game that Makes Development Look Fun
Should be purple Should be purple
Kitchen Agile Kitchen Agile
Perhaps Perhaps "Go" is the new Visual Basic
zen-coding: turn those CSS selectors upside down zen-coding: turn those CSS selectors upside down
Debugging: It's all about finding Albuquerque. Debugging: It's all about finding Albuquerque.
The Real-Time online JQuery Editor The Real-Time online JQuery Editor
HTML5, a 3 minute guide HTML5, a 3 minute guide
Developer Codpieces Developer Codpieces
Agile for one: The Personal Story 'Wall' In Action Agile for one: The Personal Story 'Wall' In Action
Never work with thick people. Never work with thick people.
Cosmo: project status panel Cosmo: project status panel
Windows Search in Japan Windows Search in Japan
Project Management Zen Project Management Zen
Continuous Integration, Plugins and Going Too Far Continuous Integration, Plugins and Going Too Far
The Rules of Stand Up The Rules of Stand Up
Sydney International Airport: Stupid, Criminal, or Criminally Stupid? Sydney International Airport: Stupid, Criminal, or Criminally Stupid?
God No! ...The ReBuilder God No! ...The ReBuilder
Matt, The Office Mortar Matt, The Office Mortar
'Outlook style' rules for Subversion 'Outlook style' rules for Subversion
Really deep linking: Url + regex Really deep linking: Url + regex
hExcel -- A Hexagonal Spreadsheet hExcel -- A Hexagonal Spreadsheet
Is the remote control a thing of the past? Is the remote control a thing of the past?
The Utterly Thorough Guide To Awesome Application Compatibility on Windows 7. The Utterly Thorough Guide To Awesome Application Compatibility on Windows 7.
Astounding Hyperlinked Noticeboard Astounding Hyperlinked Noticeboard
Three Questions About Each Bug You Find Three Questions About Each Bug You Find
Recursing over the Pareto Principle... Recursing over the Pareto Principle...
Sometimes, The Better You Program, The Worse You Communicate. Sometimes, The Better You Program, The Worse You Communicate.

Archives .: secretGeek :: Complete Archives
TimeSnapper -- Automated Screenshot Journal TimeSnapper.com    
Version 3.3: true productivity boost

Next Action NextAction
Managing the top of your mind

World's Simplest Code Generator (html edition) World's Simplest Code Generator

25 steps for building a Micro-ISV 25 steps for building a Micro-ISV
3 minute guides -- babysteps in new technologies: powershell, JSON, watir, F# 3 Minute Guide Series
Universal Troubleshooting checklist Universal Troubleshooting Checklist
Top 10 SecretGeek articles Top 10 SecretGeek articles
ShinyPower (help with Powershell) ShinyPower
Now at CodePlex

Realtime CSS Editor, in a browser RealTime Online CSS Editor
Gradient Maker -- a tool for making background images that blend from one colour to another. Forget photoshop, this is the bomb. Gradient Maker


[powered by Google] 


How to be depressed How to be depressed
You are not inadequate.



Recommended Reading

The Best Software Writing I
The Business Of Software (Eric Sink)

Recommended blogs

Jeff Atwood
Reginald Braithwaite
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Rhys Parry
Joel Pobar
OJ Reeves
Eric Sink
Joel Spolsky
Des Traynor

Aggregated Links

programming.reddit.com
dzone
dot net kicks

Human Link Machines

interesting finds
a continuous learner's weblog
arjan's world
n links today
new and notable
morning coffee
learning .net
weekly link post
(my del.icio.us account)

LinkedIn profile
 
home .: about .: sign up .: sitemap .: secretGeek RSS .: © Leon Bambrick 2006 .: privacy

home .: about .: sign up .: sitemap .: RSS .: © Leon Bambrick 2006 .: privacy