On Fri, Apr 26, 2019 at 6:10 AM Rowan Collins <rowan.coll...@gmail.com> wrote:

> On Thu, Apr 25, 2019 at 6:07 PM Theodore Brown <theodor...@outlook.com> wrote:
>
> > Is there any chance the Number Format Separator RFC [1] could be revived
> > for PHP 7.4? I looked at the discussion from a few years ago and it's
> > not clear why many people originally voted against it.
>
>
> I'm not particularly against this proposal, but I'm not sure how often I'd
> use it.

How often you use numeric separators depends on what you are doing.
I definitely agree that phone numbers and dates are not good use cases,
and that there are usually better ways to write things like the number
of seconds in a day or number of bytes in a gigabyte.

However, there are many other appropriate uses of large integers
where numeric separators can make the code more readable and
prevent mistakes. Here's an example from code I maintain:

```php
function getActiveDirectoryTimestamp(DateTime $date): int
{
    // Active Directory stores dates as the number of 100-nanosecond
    // intervals since January 1, 1601.
    $epochDiff = 11_644_473_600;
    $secondsAfterADEpoch = $date->getTimestamp() + $epochDiff;
    return $secondsAfterADEpoch * 10_000_000;
}
```

Another common use case is constants used in scientific calculations:

```php
const ASTRONOMICAL_UNIT = 149_597_870_700;
const SPEED_OF_LIGHT = 299_792_458;

echo 'Time for light to travel from sun to earth: ';
echo (ASTRONOMICAL_UNIT / SPEED_OF_LIGHT) . ' sec.';
```

For me personally the most frequent use case is actually in tests,
where various values (e.g. large dollar amounts) are passed to
functions in order to validate business logic. Numeric separators
would help make such unit tests a lot more readable.

Best regards,

Theodore Brown

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

Reply via email to