|The stupid question is the question not asked|
GotToBTru's scratchpadby GotToBTru (Prior)
|on Jun 15, 2010 at 13:25 UTC||Need Help??|
Why I Frequent the CB
Funny Story (and true!)
Take rectangular sheets of metal and form a strip by fastening the narrow ends to each other. Then bend the strip into a circle (diameter 30' or more) and fasten the ends to form a band. Now you have a tank. Make the tank deeper by stacking two more bands on it. Now fill said tank with liquid manure. Lots of liquid manure.
As it says on your cereal box, there will be some settling of contents. The layer of liquid on top will be mostly water, and not of much use in fertilizing.*Bright idea* - remove one sheet from the top band to form a spout and pour off some of that liquid. Except sharp corners at the bottom of that spout form stress concentrations, and one of the sheets below tears like paper, and that tear continues into the sheet below it. The bands are only kept circular by fasteners, and now relieved of that restraint, the walls of the tank revert to nearly straight. The entire contents of the tank empties in a fairly rapid fashion.
OO versus Procedures
One example of the difference is what is called data encapsulation. In an OO program, there (should be) no data outside of a context. In a procedure, I might have a variable called $user_name. Any code I have that can see that variable might also modify it. That can be okay, but it also can be a problem. It can make it hard to determine what part of my code changed something. Also, just because I called it $user_name, I could store ANY string in that variable, just for convenience sake. Heck, in Perl, I could reuse it to store a hash reference if I wanted. Why would I? No idea. But I could.
In an OO program, the user will have a name, but it will be an attribute, "name" of a class, "user". The ONLY way to modify and display the name will be to call the code in the user object to do it. If I want sometimes to display the full name, and sometimes the full name and title, and sometimes just the first name, I write the code to format that in the way I like once, and that functionality is now available to any other program that uses my user object. If I have users in my RPG, or in my music collection program, or in my website business, or whatever. Every time, I get every clever function that I have invented for displaying or using user names without having to copy code from one procedure to another, and without having to remember .. did I do that differently here than there? Will making them the same break something? I finally figure out how to handle names like Beyonce, Dr. Jose Juan Carlos Espinosa del Reyza III, and Seven of Nine. Now, every program knows how to deal with them and will do so consistently.
Okay, couldn't you do this with packages, or by being consistent in your programming? Much of it, you could. But it would not be enforced. At anytime, you could say "I'll do this just once because I'm in a hurry." Using OO, I am using the features of the language to enforce good programming practice. That makes it much easier to share what I've done with others.
XML to Hash
On the Subject of Off Topic
If Perlmonks decides to get more formal in its definition of off-topic, I'd suggest the following:
Link to use as starting point for CSS/JS to color user names to reflect their age relative to me (based on the cb_author id):CSS to display level
Code code for coding
Stuff to Check Out