Welcome to the Monastery | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I am going to comment on this from a different direction, namely *why* object-oriented programming. Understanding this makes a lot of things easier to understand. There are basically two kinds of bugs in software: those that involve doing the wrong thing with the right data, and those that involve doing the right thing with the wrong data. Of the two, the second is far harder to track down and fix because the data bacame wrong somewhere else and that has to be tracked down. For this reason state management is a central problem in programming. Looking at your code you seem close to structural programming. The idea of structural programming is you keep data together that belongs together and this makes it easier to determine when data is bad. With your hashes, this is what you are doing. It also simplifies assumptions your code has to make. The next step is to go object oriented and tie the data to behavior. Ideally state should only be changed by going through the behavior. This gives you fewer points to track down when looking for how data became bad. In Perl you use packages and bless to do this, but you can also use Moose which is a really nice framework. One reason to recommend Moose btw is that it makes the next step (after going OO) a lot easier, namely making your objects immutable. With immutable objects you have only one place to check data validity (the constructor) and so it becomes nearly possible to eliminate this whole class of bugs. This latter point gets you closer to functional programming because if your output is dependent only on your input (i.e. instead of changing an object you return a new one), you can manage state well enough to have programs which safely write programs. In reply to Re: How do I go from procedural to object oriented programming?
by einhverfr
|
|