[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Why not adopt "Python Style" indentation for Ruby?

Yukihiro Matsumoto

5/18/2007 4:26:00 PM

Hi,

In message "Re: Why not adopt "Python Style" indentation for Ruby?"
on Sat, 19 May 2007 00:15:05 +0900, Jaroslaw Zabiello <hipertracker@gmail.com> writes:

|What do you think about OPTIONAL block indendation in Ruby?

I am not positive for general block-by-indentation idea. If one
REALLY loves the idea, Python always waits for you.

But I sometime want "end"-less single line structure (in normal
order), e.g.

if foo then bar # pseudo syntax; you may require delimiters

not

bar if foo

especially when I write very small code chunk. Not knowing what
syntax it should be.

matz.

6 Answers

enduro

5/18/2007 9:25:00 PM

0

Yukihiro Matsumoto schrieb:

>But I sometime want "end"-less single line structure (in normal
>order), e.g.
>
> if foo then bar # pseudo syntax; you may require delimiters
>
>not
>
> bar if foo
>
>especially when I write very small code chunk. Not knowing what
>syntax it should be.
>
+1

Sven

Brian Candler

10/7/2008 7:35:00 PM

0

Yukihiro Matsumoto wrote:
> But I sometime want "end"-less single line structure (in normal
> order), e.g.
>
> if foo then bar # pseudo syntax; you may require delimiters
>
> not
>
> bar if foo
>
> especially when I write very small code chunk. Not knowing what
> syntax it should be.

As an observation, I always found ruby's "then" to be a rather
superfluous non-keyword; that is,

if a == b then
...
end

if a == b
... same
end

if a == b then ...; end

if a == b; ... same; end

So a possible (but highly incompatible) approach would be for "then" to
introduce a single-line block, e.g.

if a == b then puts "hello"; puts "world" # end implied

if a == b
puts "hello"
puts "world"
end

It could also be used, although less obviously, in other constructs:

while !a.empty? then puts a.shift

I'm not sure what 'then' followed immediately by newline should do.

Anyway, this is just an idle thought, as it would break lots of things.
--
Posted via http://www.ruby-....

brabuhr

10/7/2008 10:05:00 PM

0

On Tue, Oct 7, 2008 at 3:35 PM, Brian Candler <b.candler@pobox.com> wrote:
> It could also be used, although less obviously, in other constructs:
>
> while !a.empty? then puts a.shift

"while then"? (kinda sounds funny to my ears :)

And, in this case, is it really better than:
puts a.shift while !a.empty?

Brian Candler

10/8/2008 7:58:00 AM

0

unknown wrote:
> "while then"? (kinda sounds funny to my ears :)

It does. I was just trying to see what happens if you apply the idea
consistently. I guess taken to extremes you'd also get

def f(x,y) then x+y

which I don't particularly like, but then one-line method definitions
are pretty unusual.

<aside>
I still like that better than "f =-> x,y {x+y}" from 1.9, which is
horrid

I'd much rather have a new keyword: "f = fn(x,y) {x+y}"
</aside>

> And, in this case, is it really better than:
> puts a.shift while !a.empty?

No, not really.

It might be useful for 'if' though. I quite often write code with lots
of backwards lines:

something if foo
raise "Error" unless bar
other if baz

and it would be good to write them the right way round. (Although
"unless...then" doesn't really read well either)

More importantly,

if (x = some_big_calculation) then x.something

can't be written in backwards form currently.
--
Posted via http://www.ruby-....

Jeremy McAnally

10/8/2008 3:40:00 PM

0

Then you're introducing a big chunk of parser ambiguity. For example

if a == b then puts "hello"; puts "world" # end implied

Do you mean if a==b puts "hello" *AND* puts "world" or should you
output "hello" if it's true and "world" no matter what. That would
put a big load on the parser to figure out the different between the
different line delimiters and how that impacts the code around it.

--Jeremy

On Tue, Oct 7, 2008 at 2:35 PM, Brian Candler <b.candler@pobox.com> wrote:
> Yukihiro Matsumoto wrote:
>> But I sometime want "end"-less single line structure (in normal
>> order), e.g.
>>
>> if foo then bar # pseudo syntax; you may require delimiters
>>
>> not
>>
>> bar if foo
>>
>> especially when I write very small code chunk. Not knowing what
>> syntax it should be.
>
> As an observation, I always found ruby's "then" to be a rather
> superfluous non-keyword; that is,
>
> if a == b then
> ...
> end
>
> if a == b
> ... same
> end
>
> if a == b then ...; end
>
> if a == b; ... same; end
>
> So a possible (but highly incompatible) approach would be for "then" to
> introduce a single-line block, e.g.
>
> if a == b then puts "hello"; puts "world" # end implied
>
> if a == b
> puts "hello"
> puts "world"
> end
>
> It could also be used, although less obviously, in other constructs:
>
> while !a.empty? then puts a.shift
>
> I'm not sure what 'then' followed immediately by newline should do.
>
> Anyway, this is just an idle thought, as it would break lots of things.
> --
> Posted via http://www.ruby-....
>
>



--
http://jeremymca...
http:/...
http://omgb...

My books:
http://manning.com...
http://humblelittlerub... (FREE!)

Brian Candler

10/8/2008 5:38:00 PM

0

Jeremy McAnally wrote:
> Then you're introducing a big chunk of parser ambiguity. For example
>
> if a == b then puts "hello"; puts "world" # end implied
>
> Do you mean if a==b puts "hello" *AND* puts "world" or should you
> output "hello" if it's true and "world" no matter what.

I meant it would be equivalent to

if a == b; puts "hello"; puts "world"; end

(I thought I wrote that out in full)

> That would
> put a big load on the parser to figure out the different between the
> different line delimiters and how that impacts the code around it.

If the rules are clearly defined, parsers are easy to write. It's
certainly much clearer than many of the existing Ruby parsing rules :-)
--
Posted via http://www.ruby-....