First I think this is a great question. I also think it demands a sort of discussion that I haven't seen on this thead yet, namely why object oriented programming exists at all.
The single biggest problem in computer programming is state management. All bugs fit into three classes: doing the wrong thing with the wrong data, doing the wrong thing with the right data, and doing the right thing with the wrong data. Almost always by the time you see a bug the proximal issue is doing the right thing with the wrong data, so debugging involves backward tracing the program to see hos the data was set up incorrectly in the first place.
Over the years, many strategies have developed to manage this problem, including procedural, structural, and object oriented programming. Functional programming is another set of strategies broadly compatible with procedural, structural, and object oriented programming, but it exists on a different axis. While functional programming tells you what your program can or cannot do with the data (do not mutate it in place, for example), the other strategies have to do with organizing your data so you can more easily maintain things.
A progression may be worth looking at. With simple scripting, your variables are scoped to your script, it runs linearly or perhaps to specific points with goto statements. This works fine for trivial things but breaks down when even a little complexity is added.
Procedural programming encapsulates your script's logic behind procedures and as much state as possible is local to the procedure. This helps with the complexity but as your data becomes complex it becomes very easy for mistakes to occur.
So the next is to make variables into more complex data structures. This allows far more complexity. Perl provides a number of basic data types from which complex structures can be built. Most importantly this allows a programmer to determine what variables belong together. But everything has to know the insides of every data structure so interfaces become very brittle
Object oriented programming is basically where you take data structures and associate them with behavior. This allows you to hide the internals and thus exercise greater control over program state. This gets to when to use object oriented programming (either imperative or functional) in Perl: when your application is complex enough that this helps manage state. There's both programming and performance overhead but that helps avoid perpetual problems in software development.
Object oriented programming allows you to write programs that are far more robust and easy to maintain than you can reasonably do without it. You should use it whenever and wherever it is helpful in this regard, namely any time a program goes well beyond the trivial stage.
In reply to Re: When to Use Object Oriented approach in Perl? (RFC)
by einhverfr
in thread When to Use Object Oriented approach in Perl? (RFC)
by thanos1983
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |