in reply to Philosophy of a "new" method
All of them are right, or wrong, or perhaps only some of them, sometimes, ...
It all depends on your programming style and what you want to do with the object.
Are all your objects perfect structural clones of each other with only the internal data changing? Then go for the "define the whole structure in the new method" format.
Does the structure and content of the object depend on various external conditions which cannot be determined at creation time of the object? Then provide a new method which returns a bare bones blessed data-structure only.
These are of course the two extremes: there are many intermediary forms possible, such as using an init-method to create structure and/or provide data for the object.
Or --my favourite-- use something modern like Moose and don't sweat the details yourself.
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|