ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [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)
@ 2021-09-03 17:10 ProGM (Piero Dotti)
  2021-09-03 19:56 ` [ruby-core:105144] " mame (Yusuke Endoh)
  2021-09-04  3:21 ` [ruby-core:105146] " znz (Kazuhiro NISHIYAMA)
  0 siblings, 2 replies; 3+ messages in thread
From: ProGM (Piero Dotti) @ 2021-09-03 17:10 UTC (permalink / raw
  To: 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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:105144] [Ruby master Misc#18150] Proposal: Deprecate leading zero syntax to declare octals, since it's extremely confusing (and Python 3 removed it too)
  2021-09-03 17:10 [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) ProGM (Piero Dotti)
@ 2021-09-03 19:56 ` mame (Yusuke Endoh)
  2021-09-04  3:21 ` [ruby-core:105146] " znz (Kazuhiro NISHIYAMA)
  1 sibling, 0 replies; 3+ messages in thread
From: mame (Yusuke Endoh) @ 2021-09-03 19:56 UTC (permalink / raw
  To: ruby-core

Issue #18150 has been updated by mame (Yusuke Endoh).


The syntax is primarily used for file permissions. By grepping the source code of all public gems, you see thousands of lines like `:mode => 0644`.

```
$ gem-codesearch -f \.rb "\b0644\b" | wc -l
8324

$ gem-codesearch -f \.rb "\b0755\b" | wc -l
5277

$ gem-codesearch -f \.rb "\b0o644\b" | wc -l
142

$ gem-codesearch -f \.rb "\b0o755\b" | wc -l
161
```

I understand your feelings, but the syntax is very trivial. IMO, this deprecation looks not worth killing so many existing assets.

----------------------------------------
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-93551

* 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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [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)
  2021-09-03 17:10 [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) ProGM (Piero Dotti)
  2021-09-03 19:56 ` [ruby-core:105144] " mame (Yusuke Endoh)
@ 2021-09-04  3:21 ` znz (Kazuhiro NISHIYAMA)
  1 sibling, 0 replies; 3+ messages in thread
From: znz (Kazuhiro NISHIYAMA) @ 2021-09-04  3:21 UTC (permalink / raw
  To: 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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-04  3:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-03 17:10 [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) ProGM (Piero Dotti)
2021-09-03 19:56 ` [ruby-core:105144] " mame (Yusuke Endoh)
2021-09-04  3:21 ` [ruby-core:105146] " znz (Kazuhiro NISHIYAMA)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).