Project

General

Profile

Actions

Misc #11372

closed

Confusing a+b=9 ... unintented behavior, valid statement

Added by kozel (Dug Dough) almost 9 years ago. Updated almost 9 years ago.

Status:
Rejected
Assignee:
-
[ruby-core:70025]

Description

Hello, I found that when = is written instead of ==, it can cause unintended effects and it is hard to notice this typo, because it is valid statement. For example valid statement a+b=7 ,due to the everything is a expression, is treated as a+(b=11) and not interpreted as syntax error, like in other languages.

Should't be this behavior changed?
My suggestion is to make the assignment operator unable to be used as expresion (syntactically). It would prevent that mistakes.
Optionally (for 'backward compatibility', or 'override'), assignment enclosed in parentheses would still be treated as expression , that would make a+(b=9) valid. The meaning of extra parentheses would mean "This is not mistake, i want to use the value of variable b as expression".

Updated by kozel (Dug Dough) almost 9 years ago

Just small error: Number 11 is wrong, 7 is right. :)

Updated by matz (Yukihiro Matsumoto) almost 9 years ago

  • Status changed from Open to Rejected

Hi,

Although I can understand how you feel, the change will break millions of Ruby programs.
There could be milder option, like warning for certain usege of equal sign in expressions.

Matz.

Actions

Also available in: Atom PDF

Like0
Like0Like0