rfc:numeric_literal_separator

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:numeric_literal_separator [2019/05/27 16:46] – Fix line breaks in quote theodorejbrfc:numeric_literal_separator [2019/08/19 19:58] (current) – Separators in C# aren't just a proposal theodorejb
Line 3: Line 3:
   * Author: Theodore Brown <theodorejb@outlook.com>, Bishop Bettini <bishop@php.net>   * Author: Theodore Brown <theodorejb@outlook.com>, Bishop Bettini <bishop@php.net>
   * Based on [[https://wiki.php.net/rfc/number_format_separator|previous RFC]] by: Thomas Punt <tpunt@php.net>   * Based on [[https://wiki.php.net/rfc/number_format_separator|previous RFC]] by: Thomas Punt <tpunt@php.net>
-  * Status: Under Discussion+  * Status: Implemented (in PHP 7.4) 
 +  * Discussion: https://externals.io/message/105714
   * Target version: PHP 7.4   * Target version: PHP 7.4
   * Implementation: https://github.com/php/php-src/pull/4165   * Implementation: https://github.com/php/php-src/pull/4165
Line 68: Line 69:
 ===== Unaffected PHP Functionality ===== ===== Unaffected PHP Functionality =====
  
-Underscores in numeric literals will be stripped out during the +Adding an underscore between digits in numeric literal will not 
-lexing stage, so the runtime will not be affected.+change its value. The underscores are stripped out during the lexing 
 +stage, so the runtime is not affected.
  
 <code php> <code php>
Line 167: Line 169:
 literal, which allows searching for a value like "_6F_" to find only literal, which allows searching for a value like "_6F_" to find only
 the numbers containing that specific byte. the numbers containing that specific byte.
 +
 +==== Should it be the role of an IDE to group digits? ====
 +
 +It has been suggested that numeric literal separators aren't needed
 +for better readability, since IDEs could be updated to automatically
 +display large numbers in groups of three digits.
 +
 +However, it isn't always desirable to group numbers the same way.
 +For example, a programmer may write ''10050000'' differently
 +depending on whether or not it represents a financial quantity stored
 +as cents:
 +
 +<code php>
 +$total = 100_500_00; // represents $100,500.00 stored as cents
 +
 +$total = 10_050_000; // represents $10,050,000
 +</code>
 +
 +Binary and hex literals may also be grouped by a varying number of
 +digits to reflect how they are used (e.g. bits may be separated into
 +nibbles, bytes, or words). An IDE cannot do this automatically
 +without knowing the programmer's intent for each numeric literal.
  
 ==== Why resurrect this proposal? ==== ==== Why resurrect this proposal? ====
Line 205: Line 229:
  
   * Ada: single, between digits [[http://archive.adaic.com/standards/83lrm/html/lrm-02-04.html#2.4|1]]   * Ada: single, between digits [[http://archive.adaic.com/standards/83lrm/html/lrm-02-04.html#2.4|1]]
-  * C# (proposal for 7.0): multiple, between digits [[https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.0/digit-separators.md|2]]+  * C#: multiple, between digits [[https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.0/digit-separators.md|2]]
   * C++: single, between digits (single quote used as separator) [[http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3781.html|3]]   * C++: single, between digits (single quote used as separator) [[http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3781.html|3]]
   * Java: multiple, between digits [[https://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html|4]]   * Java: multiple, between digits [[https://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html|4]]
Line 219: Line 243:
 ===== Vote ===== ===== Vote =====
  
-Add numeric literal separators in PHP 7.4? Yes/No.+Voting started 2019-05-30 and ended 2019-06-13. 
 + 
 +<doodle title="Support numeric literal separator in PHP 7.4?" auth="theodorejb" voteType="single" closed="true"> 
 +   Yes 
 +   No 
 +</doodle>
  
 ===== References ===== ===== References =====
Line 227: Line 256:
 Discussion from previous RFC: https://externals.io/message/89925, https://externals.io/message/90626, https://marc.info/?l=php-internals&m=145320709922246&w=2. Discussion from previous RFC: https://externals.io/message/89925, https://externals.io/message/90626, https://marc.info/?l=php-internals&m=145320709922246&w=2.
  
-Blog post about implementation: https://phpinternals.net/articles/implementing_a_digit_separator.+Blog post about original implementation: https://phpinternals.net/articles/implementing_a_digit_separator.
rfc/numeric_literal_separator.1558975569.txt.gz · Last modified: 2019/05/27 16:46 by theodorejb