a...@ajf.me (Andrea Faulds) wrote:

> * Always allowing implicit conversions from int to float is sometimes
> going to cause data loss, so it may also be reasonable for PHP to
> prevent this specific case

IMHO, automatic conversion int --> float is perfectly reasonable because:
1) int can always be converted to float, possibly loosing some less
significant digists (int on 64-bit PCs can contain up to 19 digits,
float contains up to about 16 digits);
2) the called function is already aware (according to the contract of its
interface accepting float) that the passed value is an "approximated
representation of a number", and should also be aware of all the
limitations of the floating-point arithmetic.

> * Requiring an exact type match has the least mental overhead, and
> allows types to be checked at compile-time

Agree with the first part of the sentence (saving neural cells, specially
when you have to understand someone else's code...), but there is no
need for a "compiler" to garantee the type-safety of a program: static
validation can be used right now on PHP using DocBlocks only, without the
need to add new features or to change the current syntax of the language.

For example:

    /**
     * @param float $x
     * @param float $y
     * @return float
     */
    function modulus($x, $y)
    {  return sqrt($x*$x + $y*$y); }

    echo modulus(1,1);

can be easily statically validated and is perfectly equivalent to the
possible new syntax:

    function modulus(float $x, float $y): float
    { return sqrt($x*$x + $y*$y); }

    echo modulus(1,1);

Rather than changing PHP trying to (badly) imitate other languages,
the language might evolve in another completely different direction
preserving its nature of scripting language, but paying more attention
designing its features (syntax, libraries, etc.) so that static validation
and eventually compilation into an efficient binary executable code can
be performed.

Regards,
 ___ 
/_|_\  Umberto Salsi
\/_\/  www.icosaedro.it


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to