Clear questions and runnable code
get the best and fastest answer
Who's a thief?by Ovid (Cardinal)
|on Jul 01, 2002 at 14:43 UTC||Need Help??|
cjf asked, in regards to why not much OO seems to be done in Perl:
Why is this? Is Perl not suited for AI applications? Is it too slow? Is Perl OO programming too messy? Is it because Perl's considered 'just a scripting language' and not meant for serious projects?
Not every problem is approached the same way. If you have a system where the data rapidly changes, object-oriented programming is often a good choice. However, if the data is relatively static but the functionality rapidly changes, then you might find a straight-forward procedural design better than an object-oriented one.
That is to say, not every problem should be approached the same way and just as we acknowledge that Perl is not a great tool for programming device drivers, it's also not the most optimal tool for artificial intelligence. Because AI often involves creating a lot of rules, searching through those rules, backtracking through them (the bane of regexen, remember?), it tends to require a fast programming language to drive it. Consider the little snippet I wrote about thieves. Rather than make you rush off to another link, I'll reproduce it here.
Imagine that I want to know what a given person might steal. I might assume that they will steal stuff given the following conditions:
If I were programming in Prolog, I might have the following program:
It's fairly easy to read, once you know Prolog. :- is read as "if" and a comma is read as "and" (if outside of parentheses).
I can then ask what a given person might steal:
?- steals(badguy,X). X = gold Yes ?- steals(merlyn,X). No
Now, try to program that in Perl. I've seen Prolog::Alpha, but it needs quite a bit of work, and apparently there is a Language::Prolog::Interpreter, which I know nothing about and couldn't seem to download. Just glancing through their code bases, however, lets you know that this requires a lot of work.
Rather than trying to copy another language, though, how would you write the above program in Perl? Then, just to ensure that you have an extensible solution, try adding a rule the the thief will only steal stuff if he or she knows the stuff exists in a city at least 50 miles from where the thief lives. That's not hard in Prolog.
My point, which I alluded to in the first paragraph, is that some languages are better suited for some problems than others. AI, I suspect, is not Perl's strong suit.
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.