> From: Jeremy Curcio [mailto:j.cur...@icloud.com]
> Sent: 26 June 2013 17:10
> To: Mike Willbanks
> Cc: PHP Internals
> Subject: Re: [PHP-DEV] Gauging Interest:RFC to add map() function
>
> > I am curious with something that is so easy; why would you want it in core?
>
> A lot of the Math Functions could be considered "so easy".
>
> ...
>
> floor() could be written out as:
> ... [sort-of-floor implemented in PHP] ...
>
> The above examples are just a few that stick out to me I'm sure that looking
> through the list of available math functions would provide a few more 
> examples.
> Keeping these examples in mind, I don't follow the logic of range mapping 
> being
> too easy to implement manually whenever it is needed to not warrant being
> included in core.

Actually, that "floor" implementation will give incorrect answers in quite a 
few cases.

"floor" is very difficult to implement correctly and efficiently for floating 
point numbers, which is why PHP offers a builtin function which delegates to 
the standard c lib's implementation of "floor".
See 
https://github.com/php/php-src/blob/642721b38a9c5ebf336c81027c0dafd6f9246bd6/ext/standard/math.c#L320

That's the same for the other Math functions you have listed: there is real 
benefit to allowing access to the *correct* and efficient standard C 
implementations.


This is not the case for the "map" function you have proposed: there is not a 
corresponding builtin function in the C standard library, which is why PHP 
doesn't offer it as a builtin.


There is another serious problem with the proposal: the name "map" already has 
a specific meaning in programming languages:
http://en.wikipedia.org/wiki/Map_(higher-order_function)
http://php.net/manual/en/function.array-map.php

For this proposal to have any traction, you need to:
 * demonstrate why PHP programmers need this implemented for them (e.g. for the 
"floor" func, it is easy to find tricky edge cases which justify the C lib's 
existence)
 * come up with a name which is self-explanatory and discoverable to users of 
PHP (i.e. if a PHP programmer needs to map floats from one range to another 
range in a linear fashion, what will they search for? "1-d affine transform 
PHP", perhaps?)

TBH, I don't think this proposal has much chance of being accepted (I don't 
have voting rights BTW).

Best,


Rich



Richard Bradley
Tel : 020 7485 7500 ext 3230 | Fax : 020 7485 7575

softwire
Sunday Times Best Small Companies - UK top 20 three years running
Web : www.softwire.com | Addr : 325 Highgate Studios, 53-79 Highgate Road, 
London NW5 1TL
Softwire Technology Limited. Registered in England no. 3824658. Registered 
Office : 13 Station Road, London N3 2SB


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

Reply via email to