[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

mandatory braces

Johannes Ahl-mann

2/13/2005 2:11:00 PM

hi,

i've been playing around with ruby a bit and have a proposal to make.
i am sure that ruby won't adopt it right away and maybe it goes too much
against the ruby way. also, if this has been discussed earlier here, i
apologize for not researching ;-))

if ruby made braces (the round ones ;-) mandatory this would produce
some very nice effects and break nothing except for backward compatibility
(i think). regarding the backward compatibility one could even introduce
a new command-line switch to explicitely activate the "new" syntax.
a few things would become possible:

- differentiation between method bindings and method applications, i.e.
"function1(function2)" instead of "function1(method(:function2))
- procedure objects could be treated similarly to functions:
"myproc()" instead of "myproc.call()"
- ruby code would look more uniform, because at the moment the mixing
of braces and no-braces drives me crazy *gg*

- on the negative side this would force braces for methods "yield",
"print", "puts", "break", etc.

please tell me whether this is a bad idea,

Johannes
12 Answers

Alexander Kellett

2/13/2005 2:52:00 PM

0

On Feb 13, 2005, at 3:14 PM, Johannes Ahl-mann wrote:
> please tell me whether this is a bad idea,

lets put it this way.
if this went into ruby,
i'd fork :)

Alex



dblack

2/13/2005 3:30:00 PM

0

Nikolai Weibull

2/13/2005 3:51:00 PM

0

* Johannes Ahl-mann (Feb 13, 2005 15:20):
> braces (the round ones ;-)

Parentheses, please,
nikolai

--
::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


Bertram Scharpf

2/13/2005 5:58:00 PM

0

Hi,

Am Sonntag, 13. Feb 2005, 23:14:57 +0900 schrieb Johannes Ahl-mann:
> if ruby made braces (the round ones ;-) mandatory this would produce
> [...]
> please tell me whether this is a bad idea,

I'd rather appreciate a way to get rid of the rest of
parentheses that don't mean expression grouping.

Bertram

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...


Nikolai Weibull

2/13/2005 7:01:00 PM

0

* Bertram Scharpf (Feb 13, 2005 19:00):
> I'd rather appreciate a way to get rid of the rest of parentheses that
> don't mean expression grouping.

:-D,
nikolai


--
::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


craig duncan

2/13/2005 10:38:00 PM

0

Johannes Ahl-mann wrote:
> hi,
>
> i've been playing around with ruby a bit and have a proposal to make.
> i am sure that ruby won't adopt it right away and maybe it goes too much
> against the ruby way. also, if this has been discussed earlier here, i
> apologize for not researching ;-))
>
> if ruby made braces (the round ones ;-) mandatory this would produce
> some very nice effects and break nothing except for backward compatibility
> (i think). regarding the backward compatibility one could even introduce
> a new command-line switch to explicitely activate the "new" syntax.
> a few things would become possible:
>
> - differentiation between method bindings and method applications, i.e.
> "function1(function2)" instead of "function1(method(:function2))
> - procedure objects could be treated similarly to functions:
> "myproc()" instead of "myproc.call()"
> - ruby code would look more uniform, because at the moment the mixing
> of braces and no-braces drives me crazy *gg*
>
> - on the negative side this would force braces for methods "yield",
> "print", "puts", "break", etc.
>
> please tell me whether this is a bad idea,
>
> Johannes

I agree (with others) that this exact idea isn't so good. Why should you have to use
parens when a method has no args? But the one flaw that has bothered me about ruby
is that _too much_ flexibility in parsing is allowed. I'd like it if parens were
required around a method call's arguments. The savings in leaving them off i find
less than desirable as i (personally) find it _harder_ to parse things out, visually.
Not to mention that i think the following is ridiculous:

s='abc'
=> "abc"
irb(main):002:0> (s.length -1).downto(0) { |i| p i }
ArgumentError: wrong number of arguments (1 for 0)
from (irb):2:in `length'
from (irb):2
irb(main):003:0> (s.length - 1).downto(0) { |i| p i }
2
1
0
=> 2


Joao Pedrosa

2/13/2005 10:53:00 PM

0

Hi,

On Mon, 14 Feb 2005 07:38:09 +0900, craig duncan
<craig-duncan@earthlink.net> wrote:
> Johannes Ahl-mann wrote:
> > hi,
> >
> > i've been playing around with ruby a bit and have a proposal to make.
> > i am sure that ruby won't adopt it right away and maybe it goes too much
> > against the ruby way. also, if this has been discussed earlier here, i
> > apologize for not researching ;-))
> >
> > if ruby made braces (the round ones ;-) mandatory this would produce
> > some very nice effects and break nothing except for backward compatibility
> > (i think). regarding the backward compatibility one could even introduce
> > a new command-line switch to explicitely activate the "new" syntax.
> > a few things would become possible:
> >
> > - differentiation between method bindings and method applications, i.e.
> > "function1(function2)" instead of "function1(method(:function2))
> > - procedure objects could be treated similarly to functions:
> > "myproc()" instead of "myproc.call()"
> > - ruby code would look more uniform, because at the moment the mixing
> > of braces and no-braces drives me crazy *gg*
> >
> > - on the negative side this would force braces for methods "yield",
> > "print", "puts", "break", etc.
> >
> > please tell me whether this is a bad idea,
> >
> > Johannes
>
> I agree (with others) that this exact idea isn't so good. Why should you have to use
> parens when a method has no args? But the one flaw that has bothered me about ruby
> is that _too much_ flexibility in parsing is allowed. I'd like it if parens were
> required around a method call's arguments. The savings in leaving them off i find
> less than desirable as i (personally) find it _harder_ to parse things out, visually.
> Not to mention that i think the following is ridiculous:

I think that one of the things that make Ruby what it is is the
general flexibility of its syntax. The other day I saw this in an
example for Rails:

{= foo.flash['bar'] if foo.flash['bar'] }

or Something... See? The flexibility paid off for the guy that wanted
to use it like that.

I generally avoid such constructions, mind you. But I know that one
line is better than 3 lines, depending on the situation. :-)

If you take a look at the code of Rails you will see code evaluations
and whatnot that are much better in Ruby than in other languages that
support RTTI / Reflection.


> s='abc'
> => "abc"
> irb(main):002:0> (s.length -1).downto(0) { |i| p i }
> ArgumentError: wrong number of arguments (1 for 0)
> from (irb):2:in `length'
> from (irb):2
> irb(main):003:0> (s.length - 1).downto(0) { |i| p i }
> 2
> 1
> 0
> => 2

At least you got an error. :-)

Cheers,
Joao


Douglas Livingstone

2/14/2005 12:07:00 AM

0

> if this went into ruby,
> i'd fork :)
>
> Alex

if this went into ruby,
i'd download that fork :)

Douglas


dblack

2/14/2005 12:12:00 AM

0

dblack

2/14/2005 12:17:00 AM

0