Re: zend_compare & co
| From: | Jeroen van Wolffelaar | Date: | Sun, 07 Oct 2001 13:12:10 +0000 |
| Subject: | Re: zend_compare & co | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-67477@lists.php.net to get a copy of this message | ||
> At 01:40 AM 10/6/2001 +0200, jeroen@php.net wrote:
> >Can you trust on the compare functions to return either -1, 0 or 1? I
don't
> >think so... but since that assumption is made in various locations in
PHP4,
> >it maybe is true?
>
> I think Zend's internal compare functions where normalized a while ago.
>
>
> >Similar question for zend booleans, can you trust the lval to be either 0
or
> >1, or not?
>
> Yes, booleans should be 0 or 1.
>
> All of this doesn't meant here aren't bugs someplace :) However, I think
in
> general if you want to write a robust function which relies on these
things
> you're best off relying on the 0 being false and all the rest being true.
The point is, who's responsability is it for checking wether they are
normalized or not? IMO, you shouldn't trust compare and boolean function to
be limited to (-1,)0,1, because it is very easy to have !=0 or ==0 in your
checks, and <0 and >0. So why unnecessarily trust on -1, 0 or 1 with a
greater chance on bugs? And also important, that normalization decreases
performance, and for what??
About proto'ing Zend functions: where is the plan, the original scheme
according to what you programmed Zend? Weren't there proto's in it? I agree
with Jani that proto's is the absolute minimum of documentation that should
be in a piece of software that's used by means of its API. About the 'do it
yourself', I would incidentally add proto's to Zend if I could, with
'correct me if i'm wrong' tags.
At least the very important information like wether or not you can trust on
zend booleans to be either 1 or 0 should be clearly documented somewhere...
otherwise you're asking for unnecessary bugs. You mention 'robust functions'
yourself, and robust means to me that a function can be easily checked to
work exactly according to its specification. Implying that there should be
some kind of specificiation to start with.
--Jeroen