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_MED,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 1771E1F8C6 for ; Fri, 3 Sep 2021 17:10:18 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 077DA120AEB; Sat, 4 Sep 2021 02:08:51 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id C9064120AE1 for ; Sat, 4 Sep 2021 02:08:48 +0900 (JST) Received: by filterdrecv-7bc86b958d-qrvxl with SMTP id filterdrecv-7bc86b958d-qrvxl-1-613256EF-3A 2021-09-03 17:10:07.066015314 +0000 UTC m=+154172.429091401 Received: from herokuapp.com (unknown) by ismtpd0163p1iad2.sendgrid.net (SG) with ESMTP id QVoj4ysZRn-nYItNA0vYxw for ; Fri, 03 Sep 2021 17:10:07.013 +0000 (UTC) Date: Fri, 03 Sep 2021 17:10:07 +0000 (UTC) From: "ProGM (Piero Dotti)" 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: ProGM 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: 81320 X-SG-EID: =?us-ascii?Q?EbrEMlJ8ZQBAoUhl6ENzvVWux0F7jBHeKYYed+7kHIUCSIrabq=2F+7N88IF7V6+?= =?us-ascii?Q?HSjIgfuekHeFilcD1TmngJfUCNc5YfMt9lJFT=2FP?= =?us-ascii?Q?XbFpvjnYUwYHL=2F9hzZgY1WksWCDNKgoxDaJqFoe?= =?us-ascii?Q?smgUYPR2fyBYMiEIZAcd+3Cf4R8MpIGpLp+UR6U?= =?us-ascii?Q?GndxDkSDhNExwkgiav+bZgfzbErLhtSLmnSBSBG?= =?us-ascii?Q?81HzUARGcp6Y75ix83REMNjieT7+WfI2a=2FpD9rd?= =?us-ascii?Q?QmHUS+jciEPb89Y0MzJJQ=3D=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 105142 Subject: [ruby-core:105142] [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 reported by ProGM (Piero Dotti). ---------------------------------------- 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 * 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/