From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id BF98E1F8C6 for ; Sat, 4 Sep 2021 03:22:06 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id ACDE2120BCD; Sat, 4 Sep 2021 12:20:40 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id AB5B5120BCB for ; Sat, 4 Sep 2021 12:20:37 +0900 (JST) Received: by filterdrecv-7bc86b958d-p9pqm with SMTP id filterdrecv-7bc86b958d-p9pqm-1-6132E64F-47 2021-09-04 03:21:51.961027544 +0000 UTC m=+190877.979145931 Received: from herokuapp.com (unknown) by ismtpd0173p1iad2.sendgrid.net (SG) with ESMTP id sfeG5GyyRZGQ3GD-tu0kSg for ; Sat, 04 Sep 2021 03:21:51.894 +0000 (UTC) Date: Sat, 04 Sep 2021 03:21:51 +0000 (UTC) From: "znz (Kazuhiro NISHIYAMA)" Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Misc X-Redmine-Issue-Id: 18150 X-Redmine-Issue-Author: ProGM X-Redmine-Sender: znz X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-Redmine-MailingListIntegration-Message-Ids: 81324 X-SG-EID: =?us-ascii?Q?tuH+TxE7++n73nNPC626k24KiyFlUEf4GSA7WvS=2Fa=2F4tseSR4X+hWiwYKmMLqJ?= =?us-ascii?Q?E1muVBG7v=2Fgk2TMWQZETaKA0L835jLSHXz1yQrv?= =?us-ascii?Q?oYXCp8oZtPyqFjmw67ZiIOX3m+pnJ9YCScE7t8+?= =?us-ascii?Q?xde02HvbkL=2FPHbVfgv6F7soraHcYTkL1EWUVbOM?= =?us-ascii?Q?EPHO1jSw=2Fjixltd0APB5e2Cu=2FCdIuYgJkYfjBS1?= =?us-ascii?Q?XMYdqg0KcIO9lBMTQPIPtxMcZ7CFGYCxOL1HTYt?= =?us-ascii?Q?rYKu9Fxnua6ziTQZY1R4w=3D=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 105146 Subject: [ruby-core:105146] [Ruby master Misc#18150] Proposal: Deprecate leading zero syntax to declare octals, since it's extremely confusing (and Python 3 removed it too) X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #18150 has been updated by znz (Kazuhiro NISHIYAMA). I think supporting `08` and `09` only satisfy such usecases. ---------------------------------------- Misc #18150: Proposal: Deprecate leading zero syntax to declare octals, since it's extremely confusing (and Python 3 removed it too) https://bugs.ruby-lang.org/issues/18150#change-93553 * Author: ProGM (Piero Dotti) * Status: Open * Priority: Normal ---------------------------------------- Hi there, I'd like to open a discussion about the leading zeros syntax to declare octal numbers. Let me give you a little bit of context. It seems like ruby considers all integers with leading zeros as octal. For instance, if you write 012, ruby reads it as 10 in decimal. There is an alternative syntax for this, using an "o" character after the zero, i.e. 0o12 I've discovered this behavior by chance a couple of days ago. I was declaring a new Date object: ``` ruby START_DATE = Date.new(2021, 09, 01) ``` In my mind, I was thinking of ISO 8601 ("2021-09-01") and I wrote it in that way without even thinking about it. I immediately got a weird error: ``` ruby SyntaxError ((irb):2: Invalid octal digit) ``` That was astonishing. "What the heck does this error mean?", I thought. After a brief research, I've discovered that many languages that come from C have this "weird" behavior. Javascript, Go, Java, and ruby itself all treat leading zeros like this. Rust and Elixir, instead, are parsing 00123 like 123, as math notation suggests. Finally, Python 3+ raises an error. --- My proposal is: throw a deprecation warning in ruby 3.x when using this syntax and treat 0011 as 11 from ruby 4+. Why? * Because it's extremely confusing * There is an alternative syntax that is much more explicit (0o11 vs 011) * It leads to weird behaviors (like 011 != 11) * Because Python 2.x was treating leading zeros numbers as octals like ruby does, but this has been changed in python 3+: https://medium.com/techmacademy/leading-zeros-in-python-a-hidden-mystery-revealed-ee3e3065634d Ruby's claim is "A PROGRAMMER'S BEST FRIEND". As a programmer, I don't consider this behavior very friendly. :( Let me know what you think about this! -- https://bugs.ruby-lang.org/