Things That Newcomers to Ruby Should Know

Peter Hickman [mailto:peter@semantico.com] informs

Ruby has no pre/post increment operator!

x++ or x-- will fail to parse.

I hope this is in ruby’s wish list :slight_smile:

Hi –

···

On Fri, 11 Oct 2002, [iso-8859-1] “Peña, Botp” wrote:

Peter Hickman [mailto:peter@semantico.com] informs

Ruby has no pre/post increment operator!

x++ or x-- will fail to parse.

I hope this is in ruby’s wish list :slight_smile:

If you search for ++ – on http://www.ruby-talk.org, you’ll see a lot
of past discussion about this, including explanations from Matz about
the unsuitability of these for Ruby. The short version is: no :slight_smile:

David


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

I think

gsub(’\’,’\\’)

should be in the list also.

Regards, Christian

Scripsit ille aut illa Peña, Botp botp@delmonte-phil.com:

Peter Hickman [mailto:peter@semantico.com] informs

Ruby has no pre/post increment operator!

x++ or x-- will fail to parse.

I hope this is in ruby’s wish list :slight_smile:

Even worse:

++x

and

–x

(preferred usage in C code since they don’t involve a temporary)
parse and run perfectly, but don’t do anything. There is a warning
about this, but it does not really help much if you don’t already know
this pitfall:

rpolzer@www42:~$ ruby -w -e ‘a = 1; --a;’
-e:1: warning: useless use of -@ in void context

One might think ruby is wrong and it is not useless (“I know what I’m
doing”) - the only hint is that only one - is printed.

I think a better way would be a syntax error on double + or - operators
if they are not separated by whitespace. ±x or -+x should not be parsed
successfully, too, just to be consequent. It’s ruby, no brainfuck.

···


In diesem Sinne kannst du’s wagen.
Verbinde dich! du sollst in diesen Tagen
Mit Freuden meine Künste sehn;
Ich gebe dir, was noch kein Mensch gesehn.

Hi Christian,

Can you give an example of how it may be tricky (causing
subtle/unnoticable bug) for a newcomer?

Regards,

Bill

···

============================================================================
Christian Szegedy szegedy@nospam.or.uni-bonn.de wrote:

I think

gsub(‘\’,‘\\’)

should be in the list also.

Regards, Christian

Rudolf Polzer wrote:

It’s ruby, no brainfuck.

That would make a great error message.

I’m assuming he was referring to Botp’s wish list not the ruby newcomers list (my mail reader thinks he was replying to that post).

···

On Wed, 16 Oct 2002 23:03:10 +0900 William Djaja Tjokroaminata billtj@y.glue.umd.edu wrote:

Hi Christian,

Can you give an example of how it may be tricky (causing
subtle/unnoticable bug) for a newcomer?

Regards,

Bill


To call me “awesome” is an understatement.

Hi Christian,

Can you give an example of how it may be tricky (causing
subtle/unnoticable bug) for a newcomer?

Regards,

Bill

I’m assuming he was referring to Botp’s wish list not the ruby newcomers list (my mail reader thinks he was replying to that post).

ibz@ignoramus:$ irb
Reading config file… done.
ruby-1.7.3 on i686-pc-linux with irb 0.9(02/07/03)
Type ‘help’ for more information.

str = ‘a\b\c’
… >>> puts str
a\b\c
nil
puts str.gsub(/\/,‘\\’)
a\b\c
nil
puts str.gsub(/\/,‘\\\’)
a\b\c
nil
puts str.gsub(/\/,‘\\\\’)
a\b\c
nil
puts str.gsub(/\/) { ‘\\’ }
a\b\c
nil
puts str.gsub(/\/, ‘&&’)
a\b\c
nil

,---- [ Programming Ruby, p.64 ]

When the substitution occurs, the regular expression
engine performs another pass through the string, converting
“\” to "", so the net effect is to replace each single
backslash with another single backslash.
`----

Kindest regards,

			--ibz.
···

On Wed, 16 Oct 2002 23:03:10 +0900 > William Djaja Tjokroaminata billtj@y.glue.umd.edu wrote:

Hi,

Thanks for the input. I will include it in the list.

Regards,

Bill

···

===========================================================================
Ibraheem Umaru-Mohammed umarumohammed@btinternet.com wrote:

str = ‘a\b\c’
… >>> puts str
a\b\c
nil
puts str.gsub(/\/,‘\\’)
a\b\c

(deleted)