develooper Front page | perl.perl5.porters | Postings from August 2001

Re: [PATCH 2 of 3] $] is deprecated - EXTERMINATE, EXTERMINATE, EXTERMINATE

Thread Previous
From:
John Peacock
Date:
August 25, 2001 20:56
Subject:
Re: [PATCH 2 of 3] $] is deprecated - EXTERMINATE, EXTERMINATE, EXTERMINATE
Message ID:
3B887331.F4C702F0@rowman.com
Simon Cozens wrote:
> 
> On Fri, Aug 24, 2001 at 04:25:44PM -0400, John Peacock wrote:
> > This whole thread is completely missing the point.
> 
> Someone's missing the point, John, but I don't think it's me or Abigail.
> 
> Don't do this. It's stupid. It won't work. You're wasting your time on
> this; do something that will work instead.

Thanks for the vote of confidence.

> 
> Firstly, "upgrade to a vstring" has no meaning. Nothing marks a string
> as being "a vstring". 

Actually, a v-string (as I am defining it) is any string that has been 
tokenized by (currently) going through the 'v' branch of
toke.c:scan_num().  
Sure, you can use other methods to generate the exact same sequences of 
chr()'s, but I am not interested in that.  If you type a bareword with 
2 or more decimals (and/or a leading 'v') AND THEN USE IT IN A VERSION 
COMPARISON, then I can do what I want.  If you type a number or quoted 
string AND THEN USE IT IN A VERSION COMPARISON, then I can do what 
I want.

> I've said it before: a vstring is just a
> collection of chr()'s (actually I said ord(), but not many people
> noticed) stuck together. That's all.

And the funny thing about coding a version as a string of chr()'s
is that they sort in the normal human sense, as opposed to ASCII sort
order which is wrong (unless the user intervenes and forces a specific
number of decimal places):

	"1.10" lt "1.9"

and	v1.10 gt v1.9

but perhaps that is why the v-string name has stuck, in defiance of
the wishes of others.

> 
> If I have
>     use foo v49.46.49;

The tokenizer routine (since you typed a bareword with a 'v' and/or
2 or more decimals) follows the 'v' branch of scan_num, and it is
now under my control (at least briefly).

> your code will see
>     foo->VERSION("1.1");

My code does nothing of the sort.  I compare it natively as a
v-string, rather than stringified.

> 
> "Oh", says your DWIMmer code, "that looks like a version. Better encode
> it as a vstring". "Upgrading this to a vstring" gives you chr(1).chr(1)
> 
> chr(1).chr(1), suprisingly, isn't the same as chr(49).chr(46).chr(49),
> and your code will *NOT* make a sensible comparison, and it won't make
> the comparison I wanted. This "fix" will actually break things.

Bollocks.  It already is a v-string; my code knows it needs to do 
nothing to this term (since I have marked it as such).  See the code
in toke.c:str_to_version() for a hint at what I am proposing.

> 
> Leave it alone. Version comparison is not currently broken, so long as
> people are consistent in what they're feeding to VERSION. You're not
> going to be able to hack the code to make the people consistent, sadly.

Let's see what is broken.  UNIVERSAL::VERSION tries to compare versions
as numbers OR strings (depending on what it was given to play with).  It
even goes so far as to force a numeric test, even if the user asked for
"use Foo v1.2.3" which seems a little dicey.  require_version() in
Exporter
always uses a numeric comparison.  CPAN tries to do the right thing and
has it's own v-string code, but it requires the user to have typed a 'v'
for one of the two terms.  If I want to broaden my net a little, the 
code in pp_ctl::pp_require() does Perl version comparisons another way 
entirely (based on the Janus nature of PL_patchlevel).

This is inconsistent code.  And there are some hidden gotchas, lurking
just below the surface.  For example, lib/Test.pm has the following 
definition: 

	$VERSION = "1.18";

Try these (with bleadperl)

	perl -e "use Test 1.19"  # fails
	perl -e "use Test v1.19" # succeeds???
	perl -e "use Test v1.180"# succeeds
	perl -e "use Test v1.181"# fails

This is not programming by design, but rather by accretion.  And the 
old bits don't play nice with the new bits.  Sure, you say, I had no
business using the v-string notation with Test, to which I say, why
not?

Please, everyone, rather than assuming that you know better (even though
I know some of you may), let me finish my testing and then judge the
code
rather than continue the discussion here.

Thanks

John Peacock

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About