[Bioperl-l] Bio::Root::IO _readline/_pushback behavior

Chris Fields cjfields at illinois.edu
Wed Aug 3 10:16:37 EDT 2011


On Aug 3, 2011, at 3:55 AM, Kai Blin wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi folks,
> 
> as I mentioned on https://redmine.open-bio.org/issues/3264 there is
> something odd going on with Bio::Root::IO's _readline/_pushback
> functions. This seems to be intentional, at least there is a test case
> asserting the behaviour I'm seeing. It his however very confusing to the
> unexpecting programmer using the code.
> 
> One assumption I'd immediately make would be that if I have code that
> does a $foo = $io->_readline; $io->_pushback($foo); $bar =
> $io->_readline;, $foo will be the same string as $bar, regardless what
> other pieces of the code did. Currently, this is not the case, because
> the readbuffer that _pushback pushes back into has new strings appended
> to the end but readline removes them from the front.

I think this test is performed in the regressions already, but if not then it is more than welcome.

> This easily violates the "principle of least surprise", so I think we
> should change the readbuffer to a stack. As far as I can tell, changing
> the _pushback function to "unshift" instead of "push" to the readbuffer
> breaks only the Root/RootIO.t test designed to test the old behaviour. I
> don't see any other tests failing on my system that don't fail without
> this patch.
> 
> Any comments from the core devs?

I don't have a problem with that beyond the change to the RootIO.t tests (it implies a specific behavior that some developers expect, so is a very subtle API change).  However, this is how one would expect it, to be more like an 'unread' stack instead of a queue.  In fact, there is a module I used for Biome's pushback/readline called IO::Unread that implements an IO layer for mimicing this behavior, might be worth looking into.

> Cheers,
> Kai

chris


Christopher Fields
Senior Research Scientist
National Center for Supercomputing Applications
Institute for Genomic Biology
University of Illinois Urbana-Champaign
1206 W. Gregory Dr. , MC-195
Urbana, IL 61801




More information about the Bioperl-l mailing list