|XP is just a number|
Programming Examples: Declarative, Imperative, Functional, Etc.by aaron_baugher (Curate)
|on Jul 25, 2012 at 13:32 UTC||Need Help??|
aaron_baugher has asked for the
wisdom of the Perl Monks concerning the following question:
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!