On 2/18/2015 7:44 PM, Rasmus Lerdorf wrote:
On 02/18/2015 06:07 PM, Christoph Becker wrote:
Hi internals!

A while ago a question was asked on the php-general mailing list with
regard to digit seperators in numeric literals[1].

IMHO it might be a useful enhancement to allow such digit separators for
numeric (integer and float) literals in PHP for better readability;
several other languages already support them (such as Java, Perl, Ruby,
C#, Eiffel and C++14).

Before attempting to draft a respective RFC, I'd like to get some
feedback, whether this is generally considered to be useful, which
character would be preferred (most other languages seem to allow the
underscore, but an apostroph or maybe some other character might be
reasonable as well), and which restrictions should be applied (e.g.
arbitrary use of the separator, group thousands only, etc.)

I'm looking forward to hear your opinion.  Thanks in advance.

[1] <http://marc.info/?l=php-general&m=142143581810951&w=2>

I think it will be difficult to find a separator character that doesn't
make a mess of the grammar.

   my_func(1,999,999) obviously doesn't work
   my_func(1'999'999) as per C++14 clashes with our single-quoted strings
   my_func(1_999_999) like in ADA might work

but _999_ would need to work as well and _ is a valid char in a constant
so you can have a constant named _999_.

   - nope
   # nope
   @ nope
   ~ nope
   ! nope
   % nope
   ^ nope

We went through this for the namespace char, and there simply isn't a
typable single character left to use for something like this. _ is the
closest but it would require some changes and BC breaks which I am not
sure is worth for what appears to me to be a not-so critical feature.

Now if we went into Unicode territory, we could do it. eg.

   my_func(1 999 999) U+1680 (although it looks too much like a -)
   my_func(1 999 999) U+205F (mathematical space)
   my_func(1٬999٬999) U+066C (Arabic thousands separator)
   my_func(1·999·999) U+00B7 (middle dot)

The last one looks best to me, but we'd need a team of people working in
shifts to answer the, "How do I type this?" question.

-Rasmus

how about:

my_func( '1,000.04' );   //if you want to use separators there.


Rick. Who is firmly in the camp that considers type juggling an essential feature of PHP.



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

Reply via email to