Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: OOP's setter/getter method - is there a way to avoid them?

by sundialsvc4 (Abbot)
on Oct 27, 2015 at 13:22 UTC ( [id://1146105]=note: print w/replies, xml ) Need Help??


in reply to OOP's setter/getter method - is there a way to avoid them?

It might be time to stop reading books, so to speak, and get into the water.   There’s a little bit of room for theory in this business (which is really not “computer science” at all ...), but it is mostly practicum.   And OOP – which, by the way, is not “30% slower” – is mostly a practical way of looking at things so that you can write more-maintainable source code.

Always remember that production applications may consist of a million or more lines of source-code, most of which you did not write and have never looked at, and never will.   By placing strictures upon the language, and thus upon ourselves, we enable the computer to do the one thing a piece of silicon does best.   The computer never “overlooks” anything.   It does process all those lines of code, and, if we reduce what we are looking for (namely, our own mistakes) into something that a yes-or-no machine can detect, that’s a huge win for us.   “Getters and setters” are in the OOP implementation by design.   Methods are the buttons.   Properties are the dials and knobs.   Everything that is concerned with this chunk of data has been moved into the class definition, and can be nowhere else.

So, the definition of a class (and of its clearly-identified ancestors and “friends”) is known to encompass all of the source-code that can directly manipulate a particular piece of data.   And, unless we are specifically concerned with that class’s definition, we can safely ignore the details, knowing that we do not have to concern ourselves with them in order to correctly write code that does the right thing.   Furthermore, we know that if we do make certain very-common types of misakes ... ;-) ... the computer itself will catch it and refuse to compile our code.   If we need to change something, we need to change it in only one place and we also know that there cannot be any other place where “a corresponding change must be made at exactly the same time, or else.”

Perl’s OOP-design, which was mostly grafted-onto an existing language, is very much shaped by the fact that it is a dynamic interpreter, not a static compiler.   Therefore, it is not “pure.”   But, no practical language really is.

Replies are listed 'Best First'.
Re^2: OOP's setter/getter method - is there a way to avoid them?
by Anonymous Monk on Oct 27, 2015 at 23:12 UTC

    It might be time to stop reading books, so to speak, and get into the water.

    Take your own advice or stop giving it out

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1146105]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-03-28 14:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found