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

Re: [PATCH for discussion] clamp, round #2

Thread Previous | Thread Next
Jeffrey Friedl
August 1, 2001 09:22
Re: [PATCH for discussion] clamp, round #2
Message ID:

Tim Bunce <> wrote:
|>    Why not use xpvhv.xnv_nv?

I guess I sort of assumed that current fields in xpvhv were being used.
But I can see how how some might not be since the first X fields must
match xpvmg. If xpvhv.xnv_nv is free, that would solve the problem.

|>  - Every check for SvIMMORTAL is now slower

In private mail earlier in the week, Michael Schwern made the same
suggestion as you in that PL_sv_undef could probably be used as the
placeholder.  That solves that problem.

  Actually, I can see a way to speed up SvIMMORTAL in either case:

  Currently, it's
     #define SvIMMORTAL(sv) ((sv)==&PL_sv_undef

  where the three PL_* are static perl-interpreter structs.

  Rather than
	SV PL_sv_undef;
	SV PL_sv_yes;
	SV PL_sv_no;
  do the conceptual
        SV immortal_sv[3];
        #defined PL_sv_undef &immortal_sv[0]
        #defined PL_sv_yes   &immortal_sv[1]
        #defined PL_sv_no    &immortal_sv[2]

  The resulting code will be identical, but it allows
     #define SvIMMORTAL(sv) ((sv) >= &immortal_sv[0]
	                     (sv) <  &immortal_sv[3]);
  Which will be faster than what we have currently, and also allow
  for a cost-free expansion of these immortal SVs if the need should
  ever arise.

|> Other issues:
|> Poor names for functions.

I agree that the names I hacked up are poor [I *did* put a vocal
disclaimer], but...

|> Neither does using function names that are ambiguous without their
|> package names. I'd rather see names like set_readonly()

You're assuming that the user will import the names into their namespace. 
I'm sure it's a style/religious thing, but I think only the most very basic
things should ever import automatically (and that good programming practice
dictates that you should refer to most other things with their
fully-qualified names).

For example, I think it's bad design that Data::Dumper encourages you to
   Dumper($foo, $bar);
rather than
   Data::Dumper($foo, $bar);

Something like Data::Dumper is extremly useful, but not so overwhelmingly
part of the language like "open", "warn", etc., that the use of a raw
Dumper() won't likely be a cause of wonder and confusion to someone trying
to pick their way through some monster code with a few dozen 'use'
statements at the top.

I guess it comes down to my feeling that functions that auto-import should
be available via 'perldoc -f'. Otherwise, you need the fully-qualified
name to have any hope of finding the docs on it. Otherwise, you're screwed.

Anyway, even if you agree with me on this in general (which I doubt many on
p5p would), I can understand the feeling that clamp/readonly are of
sufficient basicness that it would fall into the list with "open", "warn",


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About