Do I *have* to use 'OOP' to use modules?

M

Merrilee Larson

Hi...

I'm not sure why, but I can't stand OOP. That's it!

Sooo....is it possible to be fully productive using Perl5 in a non-OOP
fashion? Can I still use modules, etc? Or would I be severely restricting
myself?

I'm *not* a student or professional programmer wannabe -- just an avid
middle-aged geek looking to write/speak some programming language well. My
goal is to fool around developing websites.

To date I'm not a bad hand with bash/ksh; html/css/js. I've tried PHP -- too
verbose for me. C -- too terse. C++/java -- no thanks. I'm also looking at
Lisp/Scheme et al. TIA...
 
I

Ian Wilson

Merrilee said:
Hi...

I'm not sure why, but I can't stand OOP. That's it!

Perhaps you're just waiting for an epiphany?
Sooo....is it possible to be fully productive using Perl5 in a non-OOP
fashion? Can I still use modules, etc? Or would I be severely restricting
myself?

Your question is expressed in an overly bipolar fashion, the truth
probably lies somewhere "fully productive" and "severely restricted".

I think you would probably be OK. You mention web-sites being a primary
focus, The CGI module has both an OO and a procedural interface.
 
C

Charlton Wilbur

ML> Sooo....is it possible to be fully productive using Perl5 in a
ML> non-OOP fashion? Can I still use modules, etc? Or would I be
ML> severely restricting myself?

Perl itself is largely paradigm-agnostic, but a lot of the really
useful modules offer object-oriented interfaces.

That said, insisting on not using object-oriented approaches in
programming is like insisting that you'll never turn left while
driving: you can still get where you want to go, but you're setting
yourself up for a lot of silly useless complexity. If you insist on
avoiding OO, you can still be productive in Perl; but avoiding OO is
severely restricting yourself independent of what language you choose.

Charlton
 
M

Merrilee Larson

Perhaps you're just waiting for an epiphany?

Maybe... but I seriously doubt it!

Your question is expressed in an overly bipolar fashion, the truth
probably lies somewhere "fully productive" and "severely restricted".

Do you mean to say that C programmers are *less* productive, as a rule,
than C++ programmers?
I think you would probably be OK. You mention web-sites being a primary
focus, The CGI module has both an OO and a procedural interface.

Good to know! Is that typical of most modules, or only a selected few? Is
there a (slick) way of determining this?
 
U

Uri Guttman

ML> Do you mean to say that C programmers are *less* productive, as a rule,
ML> than C++ programmers?

it all depends on the coder as usual.

ML> Good to know! Is that typical of most modules, or only a selected few? Is
ML> there a (slick) way of determining this?

slick? rtfm is about as slick as you can get. and if you don't like OO
(which makes little sense as perl OO is very simple to write for the
caller), then you can write simple procedural wrappers around the OO
modules you want. there is even a module (i have to look for it) that
can actually mess with exporting procedural subs that share a singleton
object.

but you need to explain why you hate OO it is just another way of
organizing code and it has many advantages (but is no silver bullet).

uri
 
X

xhoster

Hi...

I'm not sure why, but I can't stand OOP. That's it!

You can't stand writing OOP code, or even just using OO libraries? In Perl
you can certainly use a lot of OO code without ever writing any.
Sooo....is it possible to be fully productive using Perl5 in a non-OOP
fashion? Can I still use modules, etc? Or would I be severely restricting
myself?

Few modules force you to subclass them in order to use them, so you could
mostly pretend that they aren't OO. Sometimes you would still have
to use the OO syntax, but you could just pretend it was a weird looking
function call syntax. If:

$handle->method(@arg)

really bugs you, you could often but not always get away with invoking it
as:

Class::Name::method($handle,@arg)

although that seems to be more like "making things hard for myself" more
than "don't like OO" to me.

Xho
 
J

John Bokma

Merrilee Larson said:
Hi...

I'm not sure why, but I can't stand OOP. That's it!
Why?


Sooo....is it possible to be fully productive using Perl5 in a non-OOP
fashion? Can I still use modules, etc? Or would I be severely
restricting myself?

Since some modules are OO only, yes.

But what's the problem of using

my $object = Foo::Bar->new()
$object->foo();

over

Foo::Bar::foo()

Maybe you should study OO? It sounds like you try to avoid OO because you
*think* it eats time.
 
T

Ted Zlatanov

That said, insisting on not using object-oriented approaches in
programming is like insisting that you'll never turn left while
driving: you can still get where you want to go, but you're setting
yourself up for a lot of silly useless complexity. If you insist on
avoiding OO, you can still be productive in Perl; but avoiding OO is
severely restricting yourself independent of what language you choose.

Maybe in Perl this is true, but please don't generalize to
"programming." It's a very narrow view of the field (to continue your
analogy, you'd be driving in the left lane only, so left turns will
seem most natural).

Emacs Lisp comes to mind. It is very useful without using OOP. There
are many other examples. The problem domain and programmer experience
should make the OOP/procedural/functional/etc. choice.

Ted
 
C

Charlton Wilbur

TZ> Maybe in Perl this is true, but please don't generalize to
TZ> "programming." It's a very narrow view of the field (to
TZ> continue your analogy, you'd be driving in the left lane only,
TZ> so left turns will seem most natural).

Er, it's true across the board: if you eliminate object oriented
approaches up front, you *are* limiting yourself. It might be the
case that the problem you're trying to solve is best solved through
other means, in which case the limit is not a problem; but if you
eliminate any object oriented technique up front regardless of the
problem you're trying to solve, you're limiting yourself, and in many
cases eliminating the clearest solution to the problem.

Sometimes, you can get where you want to go by only turning left. In
those cases, deciding up front that you're only going to turn left is
not a problem. Other times, you'll want to turn right -- either
because that's the most natural route, or because taking *one* right
turn means you get to avoid an extra hour of driving.

TZ> Emacs Lisp comes to mind. It is very useful without using
TZ> OOP. There are many other examples. The problem domain and
TZ> programmer experience should make the
TZ> OOP/procedural/functional/etc. choice.

You can't do OOP in Lisp? This is news to me.

You may find that another approach (such as, if you're using Lisp, a
functional approach) is better suited to the problem; but that is
*not* the same thing as deciding, independently of the problem domain,
that object oriented techniques are not to be considered.

Charlton
 
M

Merrilee Larson

ML> Do you mean to say that C programmers are *less* productive, as a rule,
ML> than C++ programmers?

it all depends on the coder as usual.


ML> Good to know! Is that typical of most modules, or only a selected few? Is
ML> there a (slick) way of determining this?

slick? rtfm is about as slick as you can get. and if you don't like OO
(which makes little sense as perl OO is very simple to write for the
caller), then you can write simple procedural wrappers around the OO
modules you want. there is even a module (i have to look for it) that
can actually mess with exporting procedural subs that share a singleton
object.

but you need to explain why you hate OO it is just another way of
organizing code and it has many advantages (but is no silver bullet).

OO simply doesn't *feel* natural to me. I'm 100% more comfortable with a
procedural language. My first exposure to programming was with Perl4. I found
easy and intuitive. Afterwards, I had some Java code pushed unto me, and *that*
did me in for OOP. I feel the same way about PHP - although I prefer Perl to
PHP.

BTW, I'm *not* disparaging Perl OOP. I'm simply expressing how I feel about it.
In my other life, I fluently speak 3 languages: English, French and Spanish.
Learning Italian would probably not be all that much of a challenge. However,
I don't think that I would find learning Chinese/Korean/Japanese all that easy.
No offense meant to any of you Asian Perl hackers. As well, my not *groking*
Chinese et al, does not mean that these are not fine, expressive languages in
their own right. Of course they are - but they might be beyond most of us
"honkies" ;) later....
 
A

Arved Sandstrom

Abigail said:
Merrilee Larson ([email protected]) wrote on MMMMDCCCXXVI September
MCMXCIII in <URL:{} Hi...
{}
{} I'm not sure why, but I can't stand OOP. That's it!
{}
{} Sooo....is it possible to be fully productive using Perl5 in a non-OOP
{} fashion? Can I still use modules, etc? Or would I be severely
restricting
{} myself?

That depends on how much you want to avoid OO. If all you want to avoid
writing OO, you can be fully productive in Perl5. In fact, the native
OO support you get from Perl is so limited, one wonder why people even
bother writing OO Perl.
[ SNIP ]

I haven't observed the average programmer using Java, say, doing anything
more challenging with OOP than you can do in Perl. I'd guess that 90% of
programmers do with their object-oriented language of choice pretty much
what they'd do in Perl5:

Object object = new Object(stuff)
object->method(stuff) OR object.method(stuff)
object1 == object2
Object.classMethod(other_stuff)

That kind of thing. Seeing as how what Perl5 does OOP-wise accurately
describes almost everything that eight or nine programmers out of ten do
with OOP in whatever language they like, I'd be interested to hear why you
think OO Perl is not worth bothering with.

AHS
 
B

Bart Lateur

Merrilee said:
Sooo....is it possible to be fully productive using Perl5 in a non-OOP
fashion?
Yes.

Can I still use modules, etc?

Yes. modules can contain any kind of Perl source code.

So of the modules you find on CPAN are written with OO in mind, and if
there are no alternatives, those will be the ones to use. But you can
still safely mix OO with procedural code.
Or would I be severely restricting
myself?

Some people think OO is handy for easier managing large projects. If you
don't feel that way, then you don't have to use it.
 
U

Uri Guttman

SP> Speaking strictly for myself, it's because the "limitations" I
SP> hear about are primarily a lack of formal OOP strictures. Perl
SP> will let you access package (aka class) variables from any class,
SP> there's no private object variables or methods, you're not
SP> required to use accessors, $self is passed explicitly, and so
SP> forth.

where did you learn all those myths? have you heard about inverted
object? or closure objects? perl can be stricter than many purist OO
langs if you use certain modules to manage your OO. but i suspect the OP
is not concerned with writing OO rather than the simple act of
using/calling OO modules vs calling procedural modules.

SP> I'm talking about the core language here, btw - I'm well aware
SP> that there are CPAN modules that attempt to address these
SP> so-called "limitations", with varying degrees of success.

so? does anyone write any signifigant perl code without using any
modules? limiting yourself to core perl makes no sense in this
comparison. cpan is as much a part of perl as its syntax.

SP> In short, OOP "purists" - the ones I've heard, that is - tend to
SP> bemoan the fact that Perl doesn't *force* best OOP practice, but
SP> merely allows it. But force is not the Perl Way - as it's often
SP> been said, you should stay out of my living room because you
SP> weren't invited, not because I'm holding a gun.

that point i agree with. but then most other OO purist also bemoan the
fact that perl always has better regexes (pcre doesn't cut it).

uri
 
M

Merrilee Larson

Yes. modules can contain any kind of Perl source code.

So of the modules you find on CPAN are written with OO in mind, and if
there are no alternatives, those will be the ones to use. But you can
still safely mix OO with procedural code.


Some people think OO is handy for easier managing large projects. If you
don't feel that way, then you don't have to use it.

Thanks for the encouraging post. Perl4 was "my first love", and it seems to me
that Perl's "Golden Years" occured during Perl4's reign. Just my impression,
but I could be wrong. But if I'm correct, it sure says a lot about procedural
Perl. Thanks again. I'm off to look at Tcl/Tk and Scheme/Lisp. Later...
 
U

Uri Guttman

ML> Thanks for the encouraging post. Perl4 was "my first love", and it
ML> seems to me that Perl's "Golden Years" occured during Perl4's
ML> reign. Just my impression, but I could be wrong. But if I'm
ML> correct, it sure says a lot about procedural Perl. Thanks
ML> again. I'm off to look at Tcl/Tk and Scheme/Lisp. Later... --

tcl? lisp? and you dislike perl's OO? you obviously don't know much
about programming languages if you think those are a step up from
perl. and tk isn't a language but a gui toolkit which is available in
perl too.

as for perl4 being its golden years that is absurd. i did a major
project in perl4 that i wish could have been done in perl5 (which wasn't
out yet). i would like to see you try to hack a complex deep data tree
with support for traversals in perl4. please try. if that doesn't
convince you that references alone were worth the change, then you have
no clue about programming in general. i am out of this thread as it is
obvious no one here could convince you the sky is blue.

uri
 
A

Arved Sandstrom

Abigail said:
Arved Sandstrom ([email protected]) wrote on MMMMDCCCXXVII
September MCMXCIII in <URL:()
() I'd be interested to hear why you think OO Perl is not worth bothering
with.


OOP doesn't have object attributes natively. The programmer has to
build this him/herself.

And that's the root of evilness in Perls OO.

I cringe a bit when the term "native" comes up, because it means so many
different things in programming. But I will assume that by "native" object
attributes you mean that there is a way, in the language, of syntactically
distinguishing the fields of the object that are logical attributes from
those that are not (and are just implementation details).

In other words, how much built-in support is there in the language for
encapsulation. Which in turn leads to so much else in OOP.

Am I reading you correctly?

AHS
 
A

Arved Sandstrom

[ SNIP ]
Thanks for the encouraging post. Perl4 was "my first love", and it seems
to me
that Perl's "Golden Years" occured during Perl4's reign. Just my
impression,
but I could be wrong.

Well, I think you're wrong. :) My start with Perl occurred when Perl 4 was
all there was. Perl 5 was on the horizon, but I predated it by a few years.
Perl's "Golden Years" most definitely were not those of Perl 4.
But if I'm correct, it sure says a lot about procedural
Perl. Thanks again. I'm off to look at Tcl/Tk and Scheme/Lisp. Later...

It seems to me that you don't know what it is that you need from a language.
I say that without trying to be an ass. Considering that your stated goal is
to develop websites, and you've rejected PHP, C, C++, Java...I'm starting to
wonder what's left. You'll certainly reject C#, I see no particular reason
why you'd like Python or Ruby or Tcl a great deal more, I can't imagine
you'll be enraptured with XSLT...

I don't even understand some of the objections - PHP too verbose? How
exactly? Considering what PHP does for you it's unclear to me how it could
be less verbose. Do you want method names to be like those of J?

I am fairly language neutral when it comes to website development, mainly
because I dislike doing websites. But I've done a fair bit of it - most
programmers have - and used ASP + a M$ language, PHP, JSP, ColdFusion,
XML+XSLT, Perl CGI, and who knows what else. And IMHO any of the above (with
the exception of XSLT) are high productivity approaches, not difficult to
understand, all fairly maintainable, and well supported. So again I wonder
what it is that you're looking for in a language to support your web
development efforts.

AHS
 
A

anno4000

Arved Sandstrom said:
I cringe a bit when the term "native" comes up, because it means so many
different things in programming. But I will assume that by "native" object
attributes you mean that there is a way, in the language, of syntactically
distinguishing the fields of the object that are logical attributes from
those that are not (and are just implementation details).

In other words, how much built-in support is there in the language for
encapsulation.

The answer is "none".

The problem with that isn't so much that you can't natively (sorry)
restrict access to fields. Simply telling users what they are and
aren't supposed to do with a field works fine. The real problem is
that users have to know and take into account implementation details
of a class they're merely using.

The typical case is a hash based class you want to inherit from.
If you want your subclass to have additional fields, you must know
which hash keys the base class uses to store its fields (clearly an
implementation detail). If you don't there's no way to avoid conflicts.

Inside-out classes deal satisfactorily with that problem. They are
much easier to use (especially to subclass) than traditional classes,
but the measures to ensure encapsulation make them harder to write.
It can be argued that this should be part of the language.

Perl 5.10 will offer a special kind of hash (through the module
Hash::Util::FieldHash) that takes some of the burden off the programmer.

Anno
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to

The real problem is that users have to know and take into account
implementation details of a class they're merely using.
The typical case is a hash based class you want to inherit from.

I'm a little bit confused here: do you discuss "users" of the class,
or "developers" of derived classes?

AFAIU, having attributes in the language would bring absolutely no
benefits to the "merely users". The "developers", of course, are in a
very different situation...

Yours,
Ilya
 
A

Arved Sandstrom

Abigail said:
Arved Sandstrom ([email protected]) wrote on MMMMDCCCXXVIII [ SNIP ]
** I cringe a bit when the term "native" comes up, because it means so
many
** different things in programming. But I will assume that by "native"
object
** attributes you mean that there is a way, in the language, of
syntactically
** distinguishing the fields of the object that are logical attributes
from
** those that are not (and are just implementation details).
**
** In other words, how much built-in support is there in the language for
** encapsulation. Which in turn leads to so much else in OOP.
**
** Am I reading you correctly?

What I mean is that the language Perl does not have object attributes.
It's not there in the language, in the same way that C doesn't have
regular expressions.

OK, we understand each other on that point. I was being a tad nitpicky,
because I'd argue that neither does Java or C++, for example, exactly have
object attributes, any *more* than Perl 5 does. We have an _understanding_,
a contract if you will, that if we do certain things with access specifiers
and accessor methods (get/sets or properties like in C#) that we will agree
that certain fields are object attributes and others are just implementation
details. But there is absolutely nothing stopping me from exposing a
implementation field as a public field in Java, for example, or exposing it
with a public getX() - does the language have anything to say about whether
or not that field is an attribute of the object? No, it doesn't - it's down
to convention and best practices.

I'd argue that the Perl conventions in this sense are no worse than they are
in many of the mainstream OOP languages.
That doesn't mean you can't do regular expressions in C. They are just
natively not in the language. If you want them, you as the programmer
have to do all the work yourself.

I'm from the school that doesn't consider a language and its common
(standard) libraries in isolation. I understand how you're using the term
"native" here - I just don't find it important. I can't do foldr/foldl or
zip/zipWith or length or map or filter in Haskell either without a library,
short of rewriting them, but I consider those native capabilities.
Similarly, if regex capability is available in a standard C library, I
consider RE handling to be native in C. Strip away all the libraries from
Java and the language is a pretty poor thing.

I actually have to do roughly the same amount of work in Java or C++ or C#
or Eiffel to define object attributes as I do in Perl 5. I am, quite
frankly, unconcerned that some people may perceive "public int X" in a Java
class as somehow being more pure and native than a field X in a blessed hash
ref in Perl. At that point they are in fact identical.
I'm just amazed that people call the absence of elementary construct
(given that you've decided to support OO in the language) a *feature*.
I've never heard anyone advocate Java or C for their lack of native
support for regular expressions or hashes, but people keep considering
the lack of support for object attributes as the best thing since sliced
bread.

I don't think Perl is that bad. I fall very strongly on the side of those
who say that it's a knowledgeable programmer who should follow a contract,
not the language that imposes the contract on him or her. Not only that, but
I expect knowledgeable user of my classes, provided that I document them.
There are enough, fairly simple, safeguards in Perl OOP to ensure that if a
user of an OOP module wants to do something that they oughtn't do, they put
some effort into discovering how to do what they shouldn't. And isn't that
really the basic issue?

As far as object attributes go in Perl 5, they are what I say they are, as
fields in whatever ref I choose. I document them. I provide suitable access.
People use them as recommended, or they don't. End of story.

AHS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top