ruby picture

RCR 297: Warn about use of ++ and --

Submitted by aredridel (Mon Mar 21 02:02:00 UTC 2005)

Abstract

An often unexpected surprise of Ruby is that ++ and -- are non-operations.

Problem

There is confusion that ++ and -- are silent non-operations for integer types. Programmers familiar with languages that have these operators are often confused.

Proposal

Warn about the use of ++ and --, perhaps only when the -w flag is set.

Analysis

Making the error obvious would be best handled at the parsing stage, so that ++ can be warned about, but +(+()) would not.

Implementation

No implementation in pure ruby is particularly feasible.
ruby picture
Comments Current voting
This seems like a good idea.


As I was a newbie, Googled told me why this is not a good idea (mail on a mailing list). Ruby should have told me instead IMO. :)


Why don't we just make x++ mean x = x.succ() and x-- mean x = x.prev() or something?


Strongly opposed 1
Opposed 0
Neutral 2
In favor 17
Strongly advocate 3
ruby picture
If you have registered at RCRchive, you may now sign in below. If you have not registered, you may sign up for a username and password. Registering enables you to submit new RCRs, and vote and leave comments on existing RCRs.
Your username:
Your password:

ruby picture

Powered by .