in reply to Re: evolving an OO solution for a bitstream
in thread evolving an OO solution for a bitstream

Well, for me shoving procedures into special blocks just for the sake of static variables seems a bit cumbersome.

You said:

my $stream = BitStream::new("bigbinfile");
Thats not a method call. Thats a procedure call.

I must be missing something. Why isn't Bitstream::new a good way of constructing an object ? Later, I use $stream->get_bits, which is a method call.

  • Comment on Re: Re: evolving an OO solution for a bitstream

Replies are listed 'Best First'.
Re: Re: Re: evolving an OO solution for a bitstream
by dragonchild (Archbishop) on Oct 21, 2003 at 17:51 UTC
    Let's say that BitStream inherits from Stream::Generic. If you call BitStream's new() your way, you cannot do my $self = $class->SUPER::new(@_); to have some intialization deferred to the parent. Better is my $stream = BitStream->new("bigbinfile"); - much easier to extend, now. Plus, you could do something like:
    # This way of dealing with meg and gig is a poor way, used only for de +monstration. # Supersearch for a better way. my $KB = 1024; my $MB = 1024 * $KB; my $GB = 1024 * $MB; my %Classes = ( $MB => 'BitStream::Vec', $GB => 'BitStream::Buffered', ); my $filesize = -s $filename; my $classname = 'BitStream::InMemory'; foreach my $min_size (sort { $a <=> $b } keys %Classes) { last unless $filesize >= $min_size; $classname = $classes{$min_size}; } my $stream = $classname->new($filename);

    That way, you can choose your BitStream::* class based on the size of your file. If it's under a meg, use the instream. Between a meg and a gig, use the hybrid vec option. Over a gig, you need to use the slow buffered method.

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    ... strings and arrays will suffice. As they are easily available as native data types in any sane language, ... - blokhead, speaking on evolutionary algorithms

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: Re: Re: evolving an OO solution for a bitstream
by demerphq (Chancellor) on Oct 21, 2003 at 18:00 UTC

    Well, for me shoving procedures into special blocks just for the sake of static variables seems a bit cumbersome.

    As compared to what? And does whatever you would compare against allow for statics to be shared amongst a variety of subs? Using the nesting feature of blocks you can set up all kinds of data relationships between subs. (However I admit that I have a Pascal background and nesting subroutines comes naturally.)

    Why isn't Bitstream::new a good way of constructing an object ?

    Because the implementor of Bitsteam might just go and reorganize eveything so that Bitstream doesnt have its own new, but rather inherits it from some other class, perhaps a File::Stream or more realistically IO::File. And then all of a sudden your code breaks. The point is that

    Package::subroutine("is a procedure call which doesn't search \@ISA"); Package->method("is a method call which does search \@ISA");

    I mean, you never know what your other personality is going to do when you aren't looking.
    :-)


    ---
    demerphq

      First they ignore you, then they laugh at you, then they fight you, then you win.
      -- Gandhi


Re: Re: Re: evolving an OO solution for a bitstream
by diotalevi (Canon) on Oct 21, 2003 at 17:49 UTC

    That should be BitStream->new( 'bigbinfile' ). Now your new() method can be subclassed and is a class method and not just a procedural function.