Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105456 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 31207 invoked from network); 26 Apr 2019 14:09:05 -0000 Received: from unknown (HELO mail-it1-f174.google.com) (209.85.166.174) by pb1.pair.com with SMTP; 26 Apr 2019 14:09:05 -0000 Received: by mail-it1-f174.google.com with SMTP id u65so5155395itc.2 for ; Fri, 26 Apr 2019 04:10:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=5YKU2cfZ4LxaSq9fL0qgUqF45Dg9ldLyjS2A9lbyRds=; b=RMF4wjhzOGr2K4sGhDOD8wuBlLTjEt/mYKoKZgFtv5dSFKnc17GyfYfaU9jt8xFmqM qb0lDs2AG50uDoBknKxjcfp9Y3rTUK4hLzxw8qWBkDvGeysurZChzMIfB0Tj2f2NzVPm KjtV2ruMV6b+364+GWRYwUQIEGla3pQOK4AyL2szH1C4M/k7ivAgYu5/xCUeUU2fls60 qxX4tbhMTKPYHR5miLwYOhVUJe1SFrc9yPRChtcQtBBK18y9hIIwKDwCZXvOJimg6UZ6 VvmCZHwcRGHRNnwvEwcfgUesiJPQQItSiYdOkGrCQeW1ZYcMRs2mQAMnm/TxPrsBgw8s lYGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=5YKU2cfZ4LxaSq9fL0qgUqF45Dg9ldLyjS2A9lbyRds=; b=gxz2pSM/pFz3hPAf6uQ3q+VjbUcpzbMACVxE1EZI25sBOghDjfh7cQMAYdMXU6Jud7 59XsOBj3gvn1sG7nNder6uk4Shmqes/u7hfv7RWjudPd+zncgKf34D3PJjpejDFifnqT y0fqc7QX6ZWmFmPLb7NBa6LNq4TDhEjBwZzONVjx/3iho8U8Shm7vDsRuB9sGrtZdvLN y38N3uKavvOVvOPfxm5pqgtmg0kQ1hKgj4DWxS1Tb+um+3XDCZzZBFiJVD2mBKOzR/je 2VVx6JAfIG9clcVioB2d3sq+3Gojr22o/YfvO2BksdaSCRyNn92eV9B0hdpkdilSNmeF cSoA== X-Gm-Message-State: APjAAAWchVGreHnGqh1nsIG8AXMXBev4VWLZu7fkKs6B7Hwl8QV28pEG hDY4uJA4SUWoPKhvqRV7Lk4D11D8DCNkzT0Z2/it6DDq X-Google-Smtp-Source: APXvYqxXRHnwq+uR7e7gw6/Z8SI6hs6oZkQ2Rs286WYmEWNtFeTNxd4hUv/5vlAjmi+T2YZRQewJHQfaDNN0KX12PcA= X-Received: by 2002:a02:6d05:: with SMTP id m5mr18374833jac.83.1556277011856; Fri, 26 Apr 2019 04:10:11 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 26 Apr 2019 12:10:00 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="00000000000076bfa605876cfac2" Subject: Re: [PHP-DEV] Revive Number Format Separator RFC From: rowan.collins@gmail.com (Rowan Collins) --00000000000076bfa605876cfac2 Content-Type: text/plain; charset="UTF-8" > > On Thu, Apr 25, 2019 at 6:07 PM Theodore Brown > > 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. > Hi, I'm not particularly against this proposal, but I'm not sure how often I'd use it. On Fri, 26 Apr 2019 at 06:15, Bishop Bettini wrote: A cursory scan of current usage suggests that number format separator might > be used in scenarios such as: > > Phone numbers > 919_555_1234 > 49_89_636_48018 > This is a poor example, because phone numbers shouldn't be stored as integers; there's nothing you can do with them mathematically, and outside of North America it's extremely common for them to have significant leading zeroes. > Date time values > 2018_04_26 > 20180426_183242 > Again, I can't see why you'd ever use an integer for that, rather than a string. Were there really integer literals of this form in the packages you searched? > For those first few, Kotlin has similar examples [2], but Javascript > discourages use of number separator in "number-ish" values (eg phone > numbers) [3]. > The second article you link to isn't official documentation, just someone's blog post about the feature. I agree with the comment, though - the Kotlin example of a credit card number wouldn't pass code review with me, because they're not really "numbers", they're identifiers which happen to only use digits (the only mathematical operation on a card number would be checking the Luhn checksum, which is a digit-by-digit operation anyway). The only example that I can see myself using is the one of money-as-cents (or, in my case, pence): $pricePence = 1000_00; // GBP 1000.00 Although some kind of struct with separate fields and overloaded operators would probably be better still: $price = Money{ 'GBP', 1000, 00 }; The main use I've had for large number literals is for things like cache lifetimes, where the extra syntax wouldn't help, but constant expressions do: $lifetimeSecs = 604800; // 7 days const SECONDS_IN_MINUTE = 60; const SECONDS_IN_HOUR = SECONDS_IN_MINUTE * 60; const SECONDS_IN_DAY = SECONDS_IN_HOUR * 24; $lifetimeSecs = 7 * SECONDS_IN_DAY; Similar approaches work for other contexts, for instance: const GIBIBYTE = 1024 ** 3; const GIBIBYTE = 2 ** 30; both read more clearly than anything you could do with underscores: const GIBIBYTE = 1_073_741_824; const GIBIBYTE = 0x40_000_000; const GIBIBYTE = 0b1_00000_00000_00000_00000_00000_00000; Regards, -- Rowan Collins [IMSoP] --00000000000076bfa605876cfac2--