Re: some proposed changes



Huw Rogers <count0 building2 co jp> writes:

> After some hacking I made recursive types work. It was actually
> surprisingly easy.
> 
> I also want to propose changes to the way structure, sequence and any
> marshalling work:
> 
> * if a structure field is not defined in the Perl hash, then it is
> marshalled as if an undefined scalar. Right now it dies, which requires
> Perl scripters to exhaustively initialize every structure member even if
> they'd prefer the ones they leave out to default to undef. It would also
> be consistent with C struct usage (where unmentioned struct members in
> static initializers default to zero-initialized memory) to have default
> undef behaviour.

Well, I'd say that being consistent with Perl is more important, 
but this sounds reasonable to me; unless you use 'exists' explicitely
there is very little difference in Perl between:

 $s = { a => undef }

and:

 $a = { } 

> * if a sequence is undef, it is marshalled as a zero length sequence.
> Right now if it is not a true reference to an array it dies.

I don't agree with this at all.

 $a = []; print scalar (@$a), "\n";
 $a = undef; print scalar (@$a), "\n";

Are very different; the second one is a warning. 

Allowing this would be similar to allowing "undef" to be marshalled as
an empty string without any warning, which is similar to thinking
in C that "" is the same as NULL. <shudder>

> * if an any is undef, it is marshalled as a null Any. Right now if it
> is not a true reference to a 2 element array it dies.

This seems a little dubious to me, if less bad than the previous
one. 

It's less bad largely because there is no existing concept of anything 
like an "Any" in Perl, but its the same sort of confusion between
"an object holding nothing" and "nothing".

Generally, I think the "Use of unitialized value" warning is one of
the most useful warnings in Perl, and almost always indicated a real
bug for me. I'm not sure that allowing the programmer to save a little
typing at the expense of losing these warnings is a good thing.

Regards,
                                        Owen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]