Training, Open Source Computer Languages

This is page http://www.wellho.net/solutions/perl-is- ... guage.html

Our email: info@wellho.net • Phone: 01225 708225

 
Python and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Lua, etc
 
Is Perl truly an OO language?

"""I seem to remember on the training course that you told us how perl is not object oriented. I can see obvious differences between perl and C++, such as the inability to setup private or protected member functions & data, or simply that I am using subroutines instead of classes etc. Perhaps I am being overly pedantic here, but was wondering what exactly is the difference between PERL and an object oriented language such as C++... or maybe more appropriately - what makes PERL 5.x NOT an object oriented language?? Is object orientation not more of a concept rather than a syntax?"""

Let me start with an answer to the last part of the question first.

"IS OBJECT ORIENTATION NOT MORE OF A CONCEPT RATHER THAN A SYNTAX?"

Yes, it's more of a concept.

- The most important aspect of OO is the concept.
- Languages provide facilities to assist with (or enforce)
     the use of the concept.
- The syntax of the language is just the outer key through
     which you instruct the language.

In other words, it doesn't really matter one iota what the actual syntax of the language is - whether it uses operators like "->" or "." to run a method, whether it uses syntax like '@ISA = ("clothing");' or 'extends clothing' or '(clothing)' to extend a class, etc. It's what the language can do internally - the fact that it provides facilities that at least assist - that really matters.

I SEEM TO REMEMBER ON THE TRAINING COURSE THAT YOU TOLD US
HOW PERL IS NOT OBJECT ORIENTED.

Languages store data in variables in two different ways. Traditional languages have a named variable and it the location that the variable points to you'll find the value that the variable holds. Perl 5 is a "traditional" language in that sense. Languages that are described as "fully object oriented" hold their information in variables that are pointed to (or referenced by) the name - a slightly more complex setup. What does this mean?

It means that if you copy a variable in a language that's not fully Object Oriented, you're probably going to be duplicating the data ... so that changing the copy won't change the original. But if you copy a variable in a language where all the data structures are objects, then you're adding another name to the same piece of data, meaning that a change to the data through one name will be reflected in a change as seen through the other name. Let's see an example in Perl (where a list is NOT an object) and Python (where a list IS an object):

@graham = ("Perl","PHP","Python");
@current = @graham;
$current[1] = "Tcl/tk";

print "@current\n";
print "@graham\n";

We run that in Perl and we have changed @current but NOT @graham:

earth-wind-and-fire:~/mar05 grahamellis$ perl pe1
Perl Tcl/tk Python
Perl PHP Python
earth-wind-and-fire:~/mar05 grahamellis$

The code in Python reads like this:

graham = ["Perl","PHP","Python"]
current = graham
current[1] = "Tcl/tk"

print current
print graham

And when run you'll find that the data has changed under both names

earth-wind-and-fire:~/mar05 grahamellis$ python py1
['Perl', 'Tcl/tk', 'Python']
['Perl', 'Tcl/tk', 'Python']
earth-wind-and-fire:~/mar05 grahamellis$

With Perl, you CAN write code and objects that behave the way that python does intrinsically, and that's object oriented programming in Perl. It works very well, but it doesn't mean that every structure in that resulting Perl program is going to be an object.

WHAT'S THIS ABOUT PUBLIC AND PRIVATE AND PROTECTED?

With an object oriented approach to programming, code and information is separated into objects, each of which belongs to a particular class. In order to keep code maintenance easier, the number of ways that you can access one class from another is limited. Some Object Oriented language such as Java give you the ability as you're defining a class to mark things as being private so that they cannot be accessed from outside - i.e. they enforce the standard. Other such as Python work much more on the basis of trust - things aren't declared as private, but there's actually nothing there to stop you breaking the "rules" if you want to.

Both of these approaches have their merits; the trusting approach (which Perl's objects use) for a project that's being written and maintained by a small team of trusted professionals, and the enforced approach which would be mandatory in something like a major pan-banking system.

PERL / OBJECT ORIENTATION??

In Perl 5, you can define, use and write objects. I recommend you do so to help you reuse code, but it's not essential that you do and for smaller one-off data utility and conversion roles in may not gain you anything. The facilities added to Perl 5 to assist with OO are a little perverse in structure (so you'll benefit from a training course to learn about them), but they work extremely well, and offer some OO facilities that are actually beyond what's offered by Java. (C++ has a similar perversity, forced on it by a need to be compatible with C).

Perl 6 is truly object oriented. Like Python, all data structures are objects.


See also Object Orientation in Perl - course

Please note that articles in this section of our web site were current and correct to the best of our ability when published, but by the nature of our business may go out of date quite quickly. The quoting of a price, contract term or any other information in this area of our website is NOT an offer to supply now on those terms - please check back via our main web site

Related Material

Choosing your language
  [3785] Programming languages - what are the differences between them? - (2012-06-27)
  [3764] Shell, Awk, Perl of Python? - (2012-06-14)
  [3619] Ruby v Perl - a comparison example - (2012-02-21)
  [3558] Python or Lua - which should I use / learn? - (2011-12-21)
  [3169] Rekeying a table - comparison in #Ruby #Perl and #Python - (2011-02-14)
  [2866] Ruby - how does it compare and where is it the right language? - (2010-07-11)
  [2700] The same very simple program in many different programming languages - (2010-03-31)
  [2536] All the Cs ... and Java too - (2009-12-13)
  [2535] When should I use Java, Perl, PHP, or Python? - (2009-12-13)
  [2507] Admission - (2009-11-19)
  [2048] Learning to program in PHP, Python, Java or Lua ... - (2009-02-19)
  [2001] I have not programmed before, and need to learn - (2009-01-19)
  [1990] Speaking all the languages - (2009-01-12)
  [76] Learning to program in - (2004-10-07)

Perl - Creating your own Classes
  [4607] Classes and object - first steps in Perl 6 - (2016-01-02)
  [3833] Learning to use existing classes in Perl - (2012-08-10)
  [3098] Learning Object Orientation in Perl through bananas and perhaps Moose - (2010-12-21)
  [3059] Object Orientation in an hour and other Perl Lectures - (2010-11-18)
  [2969] What does blessing a variable in Perl mean? - (2010-09-24)
  [2877] Further more advanced Perl examples - (2010-07-19)
  [2834] Teaching examples in Perl - third and final part - (2010-06-27)
  [2169] When should I use OO techniques? - (2009-05-11)
  [1925] Introduction to Object Oriented Programming - (2008-12-06)
  [1864] Object Oriented Perl - First Steps - (2008-11-01)
  [1664] Example of OO in Perl - (2008-06-03)
  [1435] Object Oriented Programming in Perl - Course - (2007-11-18)
  [1320] Perl for Larger Projects - Object Oriented Perl - (2007-08-25)
  [983] Blessing in Perl / Member variable in Ruby - (2006-12-14)
  [975] Answering ALL the delegate's Perl questions - (2006-12-09)
  [246] When to bless a Perl variable - (2005-03-15)
  [227] Bellringing and Programming and Objects and Perl - (2005-02-25)

Perl - More Objects
  [4366] Changing what operators do on objects - a comparison across different programming languages - (2014-12-26)
  [4356] Object factories in C++, Python, PHP and Perl - (2014-12-19)
  [4098] Using object orientation for non-physical objects - (2013-05-22)
  [4096] Perl design patterns example - (2013-05-20)
  [3941] Building an object based on another object in Perl - (2012-12-03)
  [3581] Perl - calls to methods that use => - what do they mean? - (2012-01-16)
  [3377] What do I mean when I add things in Perl? - (2011-08-02)
  [3098] Learning Object Orientation in Perl through bananas and perhaps Moose - (2010-12-21)
  [3097] Making Perl class definitions more conventional and shorter - (2010-12-20)
  [2972] Some more advanced Perl examples from a recent course - (2010-09-27)
  [2876] Different perl examples - some corners I rarely explore - (2010-07-18)
  [2811] Igloos melt in the summer, but houses do not - (2010-06-15)
  [2717] The Multiple Inheritance Conundrum, interfaces and mixins - (2010-04-11)
  [2651] Calculation within objects - early, last minute, or cached? - (2010-02-26)
  [2427] Operator overloading - redefining addition and other Perl tricks - (2009-09-27)
  [1949] Nuclear Physics comes to our web site - (2008-12-17)
  [1819] Calling base class constructors - (2008-10-03)
  [1665] Factory method example - Perl - (2008-06-04)
  [1664] Example of OO in Perl - (2008-06-03)
  [1435] Object Oriented Programming in Perl - Course - (2007-11-18)
  [1320] Perl for Larger Projects - Object Oriented Perl - (2007-08-25)
  [1217] What are factory and singleton classes? - (2007-06-04)
  [930] -> , >= and => in Perl - (2006-11-18)
  [831] Comparison of Object Oriented Philosophy - Python, Java, C++, Perl - (2006-08-13)
  [656] Think about your design even if you don't use full UML - (2006-03-24)
  [592] NOT Gone phishing - (2006-02-05)
  [588] Changing @INC - where Perl loads its modules - (2006-02-02)
  [531] Packages in packages in Perl - (2005-12-16)
  [246] When to bless a Perl variable - (2005-03-15)
  [227] Bellringing and Programming and Objects and Perl - (2005-02-25)

resource index - Perl
Solutions centre home page

You'll find shorter technical items at The Horse's Mouth and delegate's questions answered at the Opentalk forum.

At Well House Consultants, we provide training courses on subjects such as Ruby, Lua, Perl, Python, Linux, C, C++, Tcl/Tk, Tomcat, PHP and MySQL. We're asked (and answer) many questions, and answers to those which are of general interest are published in this area of our site.

© WELL HOUSE CONSULTANTS LTD., 2019: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/solutions/perl-is- ... guage.html • PAGE BUILT: Wed Mar 28 07:47:11 2012 • BUILD SYSTEM: wizard