Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: IO::File vs CORE::open

by EvanCarroll (Chaplain)
on May 13, 2009 at 03:39 UTC ( #763660=note: print w/ replies, xml ) Need Help??


in reply to Re^3: IO::File vs CORE::open
in thread IO::File vs CORE::open

I'd rather demonstrate with code:

package Bar; use IO::File; my $fh = IO::File->new('/dev/null' , 'w'); ... package main; open ( my $fh, '>', 'foobar' ); $fh->autoflush(1); print $fh "good";
The above code is fairly normal perl: each package is prefixed with the modules it requires. Now, watch:
package main; open ( my $fh, '>', 'foobar' ); $fh->autoflush(1); print $fh "good";

The above code is fairly normal perl: each package is prefixed with the modules it requires. Except it doesn't work, this time around extra knowledge of the internal implementation of an edge case of a CORE function is required.

So, you're totally off here, while IO::File requires IO::File to be loaded this is expected; CORE::open requiring IO::Handle, is not. As for Win32::Process::Create, congrats you found one. For the others, they are all just as awkward. Another awkward complexity perl programmers have to learn with questionable-to-0 gain. I would argue here that my/local/state don't apply to this argument.

Subclassing something that isn't an object is awkward... You don't say! What does that even mean.
Is it or isn't it? You seem to disagree with some of the other people that defend it. It accepts method calls, it delegates to a class, and it has a ->new. If it walks like an object (with a broken leg), and talks like an object (with a speech impediment) in perl -- it's obviously a stupid hackish-object.
Inheritance isn't the best choice for files anyway, whether using IO::File or not.
Inheritance works fine for my needs to extend a fh -- ( i had to add whether the file was created on the call to create a write filehandle, and cache the name the file was opened from ).

It isn't about critiquing CORE::open for it's weirdness, it about showing people you don't need to work with archaic weird idioms when learning perl. Just tell them to use IO::File and enjoy that at least some of the weirdness will be absent. I prefer to omit the esoteric features of perl, and I'm arguing that CORE::open here is esoteric, non-transparent, and hackish in comparison to the IO::File's version



Evan Carroll
www.EvanCarroll.com


Comment on Re^4: IO::File vs CORE::open
Select or Download Code
Re^5: IO::File vs CORE::open
by ikegami (Pope) on May 13, 2009 at 17:46 UTC
    package Bar; use IO::File; my $fh = IO::File->new('/dev/null' , 'w'); ... package main; my $fh = IO::File->new('foobar', 'w'); $fh->autoflush(1); print $fh "good";
    Now, watch:
    package main; my $fh = IO::File->new('foobar', 'w'); # XXX $fh->autoflush(1); print $fh "good";

    this time around extra knowledge of the internal implementation of an edge case of a CORE function is required.

    How is using a method from IO::Handle any different from using a method from IO::File. You need to know the module to use it. You need to require the module to use it.

    Either you don't know you can do $fh->autoflush(1);, or you know you know that IO::Handle can do $fh->autoflush(1);.

    If you cargo culted $fh->autoflush(1);, you get an (imperfect but) meaningful message.

    while IO::File requires IO::File to be loaded this is expected; CORE::open requiring IO::Handle, is not.

    How can CORE::open requiring IO::Handle be unexpected when CORE::open doesn't require IO::Handle?

    If it walks like an object (with a broken leg), and talks like an object (with a speech impediment) in perl -- it's obviously a stupid hackish-object.

    By that logic, IO::File is a stupid hackish file handle (not an object) since it walks and talks like a unblessed file handle.

    Bad argument.

    Inheritance works fine for my needs to extend a fh

    I didn't say it didn't work. I said it's not the best option.

    It isn't about critiquing CORE::open for it's weirdness, it about showing people you don't need to work with archaic weird idioms when learning perl. Just tell them to use IO::File and enjoy that at least some of the weirdness will be absent.

    IO::Handle is the weirdness, not open.

    And they'll still need to work with open, so you're telling them to learn an extra useless method.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2014-12-28 20:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls