Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   Ruby Warnings (http://www.velocityreviews.com/forums/t813561-ruby-warnings.html)

Chris Pine 02-12-2004 02:20 PM

Ruby Warnings
 
I have been getting complaints that the code in my tutorial generates
warnings (just in chapter 5). So, I'm looking into it, and I notice the
following:

irb(main):001:0> puts 'hello '.+ 'world'
(irb):1: warning: parenthesize argument(s) for future version
hello world
=> nil
irb(main):002:0> puts 'hello ' + 'world'
hello world
=> nil

So why the warning? It's a shame, because the code won't be nearly as
readable for newcomers to Ruby, littered as it will have to be with
parenthases.

Also, can we stop switching from "syntax error" to "parse error" and back?

Chris

PS: I tried sending this to the ML instead of the newsgroup, and nothing
happened. Not even a message telling me "no, thank you, chris". What's up?



Yukihiro Matsumoto 02-12-2004 02:44 PM

Re: Ruby Warnings
 
Hi,

In message "Ruby Warnings"
on 04/02/12, "Chris Pine" <newsgroups@hellotree.com> writes:

|I have been getting complaints that the code in my tutorial generates
|warnings (just in chapter 5). So, I'm looking into it, and I notice the
|following:
|
| irb(main):001:0> puts 'hello '.+ 'world'
| (irb):1: warning: parenthesize argument(s) for future version
| hello world
| => nil
| irb(main):002:0> puts 'hello ' + 'world'
| hello world
| => nil
|
|So why the warning?

'hello '.+ 'world'

is a form of "recv.message arg", i.e. parentheses around argument are
omitted apparently, and the expression itself is an argument to
"puts". When you use method call as argument, don't omit parentheses,
no exception.

| It's a shame, because the code won't be nearly as
|readable for newcomers to Ruby, littered as it will have to be with
|parenthases.

I think newcomers can easily be confused by a dot before plus.

matz.



Mauricio Fernández 02-12-2004 05:18 PM

Re: Ruby Warnings
 
On Thu, Feb 12, 2004 at 11:44:15PM +0900, Yukihiro Matsumoto wrote:
|So why the warning?
>
> 'hello '.+ 'world'
>
> is a form of "recv.message arg", i.e. parentheses around argument are
> omitted apparently, and the expression itself is an argument to
> "puts". When you use method call as argument, don't omit parentheses,
> no exception.


This case is a bit unfortunate:

def foo(a); a end; puts(foo "a")
-:1: warning: parenthesize argument(s) for future version

--
_ _
| |__ __ _| |_ ___ _ __ ___ __ _ _ __
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

oh okay. my mistake.

Yafcot:atj(*),

mark

* Yet another fool coming over this: according to joey
-- mark@mail.novare.net




All times are GMT. The time now is 12:36 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.