Thanks very much for the detailed explanation and examples! I understand the differences much better now.
I think part of my problem was that I assumed these were all different choices at the same level, when they aren't. Now I see declarative/imperative at one level, with procedural/functional/object-oriented at a higher level. In other words, your procedures/functions/objects may contain code that is imperative or declarative or (most likely) some mix of the two.
I think the other problem was that I got hung up on the definition of declarative as (from the Wiki page), "describing what the program should accomplish, rather than describing how to go about accomplishing it." It seems to me that unless you're writing machine code at the lowest level, that's always the case to some extent. For instance, if I write:
my $x = 3;I don't care how or where perl stores the value of $x, whether it stores it as a string or integer or floating point value, how many bytes it takes, or how it marks it as belonging to the current scope. I only care that when I write $x again, perl will replace it with 3, and that it will disappear at the appropriate time when the current scope ends. So although that seems like a straightforward imperative command, there's also a lot that's declarative about it.
I can see the distinction between that and purely declarative commands, though, so maybe I'm just being too picky.
I've been working through Higher Order Perl and Paul Graham's On Lisp, both of which get into functional programming, and it looks excellent. It's just plain harder than the other methods, though, at least for me. Maybe that's because my background was heavily imperative: BASIC 7.0, then 8502 and Z80 machine language and assembly, then shell, some C, and then to Perl. I suppose had I started with something like Lisp, it would come more naturally. I think it's worth struggling through the learning curve, though.
Aaron B.
Available for small or large Perl jobs; see my home node.
In reply to Re^2: Programming Examples: Declarative, Imperative, Functional, Etc.
by aaron_baugher
in thread Programming Examples: Declarative, Imperative, Functional, Etc.
by aaron_baugher
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |