PDA

View Full Version : Comparisons of programming paradigms: Suggestions wanted



BattlePanic
January 16th, 2010, 09:19 PM
It would be interesting to see the same problem solved in different ways, each one employing a different paradigm. Object-oriented, procedural, declarative, functional

Most of the material I come across tends to focus on a specific style but doesn't provide much in the way of side-by-side comparisons. Can any of you recommend some texts or online material which compares and contrasts different programming paradigms?

Senesence
January 17th, 2010, 12:18 AM
It would be interesting to see the same problem solved in different ways, each one employing a different paradigm. Object-oriented, procedural, declarative, functional

Most of the material I come across tends to focus on a specific style but doesn't provide much in the way of side-by-side comparisons. Can any of you recommend some texts or online material which compares and contrasts different programming paradigms?

This would interest me as well.

nvteighen
January 17th, 2010, 01:11 PM
For imperative vs. functional, you can take a look on SICP (http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-1.html). There's a section in which a declarative-like language is created and contrasted to functional programming too.

CptPicard
January 17th, 2010, 01:22 PM
If there is anything I have learned from my discussions (mostly here) over the past couple of years regarding programming paradigms, it is that it is remarkably difficult to communicate about their differences using just some sort of small program snippets. The ideas are "generally applicable", so any given small piece of code will just be an incredibly narrow example that does not carry across the point of "why this idea is generally important/useful" -- there is always the disingenious counter-argument that "but I will be able to do it in an imperative language like this". The paradigm-issues are really very overarching and penetrate the entire nature of the whole program; it's hard to isolate them.

There is no substitute to doing it yourself and letting it affect your thinking... :)

BattlePanic
January 17th, 2010, 05:44 PM
Thanks for the input. I'd agree that these sorts of concepts are most easily grasped when viewing them on a scale larger than a few simple code snippets. The subject of programming paradigms could easily fill a few books.

When it comes to designing a program, with a little time and effort, I can usually figure out how I would solve a given problem. However, I usually find that I'm still curious to know how someone else might have designed and coded a different solution to the same problem.

What I would love to find is a book that starts by presenting a non-trivial, complex problem and dedicates the rest of the book to presenting several different programming solutions to that problem from start to finish.

supershin
January 17th, 2010, 06:27 PM
That would be very interesting.

There should be procedural vs object oriented(OO) comparisons availble. Though it usually is like Turbo pascal vs C or java. I guess the main difference is the objects since C/java can be used to make procedural programs. Though java is built on the OO concept so I won't say it can make a 'pure' procedural program.

As for declarative and functional, haven't really used these but wiki says functional is a type of declarative, which is apparently an umbrella term.

EDIT: Apparently SQL is declarative, so if the problem is to get info from an array/table, do a sort/filter op and display it. Then sure you could program using these 3 paradigms.

Now came across this link
http://en.wikipedia.org/wiki/Comparison_of_programming_paradigms

I guess if you want a program that uses all those paradigms the characteristics of the problem must be such that
it can be solve by the paradigm. You aren't going to use sql to create a video game are you.

grayrainbow
January 17th, 2010, 06:31 PM
Nowadays almost nobody use let's say pure procedural or pure functional style for complex programs, they are usually mix of few paradigms. Object oriented programming does not fit in the group, couse it's kinda useless by itself, and by definition objects use some other style for their internal workings. That's in contrast with logic programming, which is by itself extremely declarative, alto so declarative that some people wont call it computer programming at all, but quite interesting subject IMO :) .

Of course all that does not hold for some very special complex beasts like OS kernel and some device drivers.

phrostbyte
January 17th, 2010, 08:58 PM
Here a function which generates the Fibonacci sequence in Haskell (functional language):



fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)


Notice how this is basically the mathematical definition for the Fibonacci sequence. But it's also a compilable Haskell program. Haskell's declarative approach is very similar to the language of mathematics.

CptPicard
January 17th, 2010, 09:06 PM
Fibonacci sequence is a pretty good demonstrator. The above is the "naive definition" -- the thing can be approached functionally in a lot of different ways (in particular see the "canonical zipWith" example... it demonstrates how functional programming often exposes structure of the problem):

http://www.haskell.org/haskellwiki/The_Fibonacci_sequence

Imperatively, you either have the two-state-variable or the naive recursive definition...