Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^7: Is it ok to mix functional and oo programming in one package?

by rhesa (Vicar)
on Oct 19, 2007 at 01:30 UTC ( [id://645874]=note: print w/replies, xml ) Need Help??


in reply to Re^6: Is it ok to mix functional and oo programming in one package?
in thread Is it ok to mix functional and oo programming in one package?

Ah, but wait, you didn't write
hello $a;
Why's that? It works ;-)

But when there's a hello sub in package main, then _that's_ the one that gets called, so it's not as if the advice is completely unjustified.

#!/usr/bin/perl use warnings; use strict; package Foo; sub new { return bless {},shift; } sub hello { print "hello"; } package main; sub new { print "haha"; return; } sub hello { print "Hi, $_[0]!"; } my $a = new Foo; hello $a; __END__ Hi, Foo=HASH(0x814bd48)!

Replies are listed 'Best First'.
Re^8: Is it ok to mix functional and oo programming in one package?
by BrowserUk (Patriarch) on Oct 19, 2007 at 11:34 UTC
    Ah, but wait, you didn't write hello $a;

    True, but when I have an object instance, invoking instance methods using direct method invocation is, well, natural. I'd never think to do it any other way. But class methods on a bare-word...


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 09:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found