I've been reading lately about different programming styles: declarative, imperative, procedural, functional, and object oriented, among others. I'm having trouble seeing the distinctions between them and getting a grasp of the differences. The comparisons I've found so far aren't much help: this Wikipedia page on imperative_programming, for instance, includes these statements:

So....procedural programming is imperative, but it's also a step towards declarative, which is not imperative.... My head hurts.

I understand some of the concepts, like how purely functional programming doesn't allow side effects, and I understand how objects work. But with these other terms, there seems to be a lot of overlap, and I'm starting to suspect that a certain amount of semantic nit-picking is being done to fill Computer Science textbooks.

So, finally to my question: Does anyone know of a comparison of programming styles that uses Perl for examples? Do any of the Perl books out there include such a thing? I'm picturing a simple task like a random number guesser (pick a number between 1-10, and it tells you whether you guessed right or not) written in the different styles. There would be an OO version, a functional version, a procedural version, and so on, all performing the same task, so it would be easy to see the differences. I assume Perl can be written in any of these ways, though it may lend itself more to some than others.

If nothing like that exists, I think it'd make a good meditation. I'd write it myself, but I don't understand the subject well enough yet. I'm not even sure what style I program in!

Aaron B.
Available for small or large Perl jobs; see my home node.


In reply to Programming Examples: Declarative, Imperative, Functional, Etc. by aaron_baugher

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.