As far as I can see, the 'end' keyword is 'repeating yourself' when
used with properly indented code.
class Foo
def bar(value)
if value < 7
puts "hello"
else
puts "world"
end
end
def foobar
puts "foobar"
end
end
could be
class Foo
def bar(value)
if value < 7
puts "hello"
else
puts "world"
def foobar
puts "foobar"
with no reduction in meaning, yet 25% fewer lines of code.
What are the reasons why this isn't used/implemented/liked? It would
be a small change to the interpreter. Enabling meaningful indentation
would only make 'end' optional, not invalid; backwards compatibility
wouldn't be a problem.
(I use both Ruby and Python. I think indentation is one of the few
*language* features where Python leads Ruby.)
If this post generates a positive response, I'll make a patch for Ruby
1.9.
On Fri, 18 May 2007 16:25:03 +0900 Chris Dew <cmsdew@googlemail.com> wrote:
As far as I can see, the 'end' keyword is 'repeating yourself' when
used with properly indented code.
class Foo
def bar(value)
if value < 7
puts "hello"
else
puts "world"
end
end
def foobar
puts "foobar"
end
end
could be
class Foo
def bar(value)
if value < 7
puts "hello"
else
puts "world"
def foobar
puts "foobar"
with no reduction in meaning, yet 25% fewer lines of code.
What are the reasons why this isn't used/implemented/liked? It would
be a small change to the interpreter. Enabling meaningful indentation
would only make 'end' optional, not invalid; backwards compatibility
wouldn't be a problem.
(I use both Ruby and Python. I think indentation is one of the few
*language* features where Python leads Ruby.)
If this post generates a positive response, I'll make a patch for Ruby
1.9.
As far as I can see, the 'end' keyword is 'repeating yourself' when
used with properly indented code.
Note that the Haskell folks have managed to evolve a language in which
python-like spacing can be used to mark the extent of discrete code
chunks, but so can traditional braces.
This is more then kind of thing I'd like to see in Ruby: having it
allow the compact python notation, but not require it. (So that,
e.g., code generators would still be easy to write)
I think anyone serious about adding indentation-as-syntax to Ruby
should take a very close look at how Haskell manages to allow it
without requiring it.
···
--
s=%q( Daniel Martin -- martin@snowplow.org
puts "s=%q(#{s})",s.to_a.last )
puts "s=%q(#{s})",s.to_a.last
This is a very subjective thing. A lot of people don't use Python
because they don't like this feature.
In my case I like the symmetry that Ruby's matching end provides. I
find it makes the code easier to read and maintain. I've written and
maintained some Python code that "trails off into nowhere" with a long
series of indentations. I find this "stairway" code rather painful to
work with.
But if it is possible to add this feature to Ruby without breaking
anything, it could be interesting. It would certainly draw a few
Pythonists to check out Ruby.
Ryan
···
On 5/18/07, Chris Dew <cmsdew@googlemail.com> wrote:
What are the reasons why this isn't used/implemented/liked? It would
be a small change to the interpreter. Enabling meaningful indentation
would only make 'end' optional, not invalid; backwards compatibility
wouldn't be a problem.
(I use both Ruby and Python. I think indentation is one of the few
*language* features where Python leads Ruby.)
As far as I can see, the 'end' keyword is 'repeating yourself' when
used with properly indented code.
class Foo
def bar(value)
if value < 7
puts "hello"
else
puts "world"
end
end
def foobar
puts "foobar"
end
end
could be
class Foo
def bar(value)
if value < 7
puts "hello"
else
puts "world"
def foobar
puts "foobar"
The is one big disadvantage in Python's syntax. Things like...
def bar(value); (value<7) ? (puts "hello") : (puts "world"); end
...are not possible in Python - and they are useful for the typical
one-to-three-liners in support areas, where Ruby still has the chance to
replace Perl - a chance that Python never had.
I know that my example has nothing to do with documentation oriented
software development, but this is not necessary for a broad range of
small ad-hoc tools.
with no reduction in meaning, yet 25% fewer lines of code.
What are the reasons why this isn't used/implemented/liked? It would
be a small change to the interpreter. Enabling meaningful indentation
would only make 'end' optional, not invalid; backwards compatibility
wouldn't be a problem.
(I use both Ruby and Python. I think indentation is one of the few
*language* features where Python leads Ruby.)
Here my 5 cents...
Gentlemen, if you want to code Python style, go ahead, program in Python.
I mean every language has it's pros an cons. I come from a Java world (11 years of Java) and I am not asking that Ruby should be Java like. That is absolute nonsense.
Ruby is like Ruby, so, if you like it (as I do) take it, if you don't... there are lots of different programming languages out there you can choose from, or like Mats, go ahead and develop your own (you will notice it's actually not that easy to do it right...)
I personally prefer that 'end' be in place, so that all ruby code is
readable. I personally believe there may be something wrong with a
syntax which sacrifices explicit readability (for everyone, not just
python programmers) for increased typing speed and the illusory gain
of 'fewer LOC'. This was one of the major reasons which convinced me
to use ruby instead of python.
···
On May 18, 4:23 am, Chris Dew <cms...@googlemail.com> wrote:
...
with no reduction in meaning, yet 25% fewer lines of code.
What are the reasons why this isn't used/implemented/liked? It would
be a small change to the interpreter. Enabling meaningful indentation
would only make 'end' optional, not invalid; backwards compatibility
wouldn't be a problem.
(I use both Ruby and Python. I think indentation is one of the few
*language* features where Python leads Ruby.)
As far as I can see, the 'end' keyword is 'repeating yourself' when
used with properly indented code.
Maybe it is maybe it isn't. Personally I'm an 'end' man. I like my
blocks.
It would be easier if you learnt to type, or used editor macros.
(I use both Ruby and Python. I think indentation is one of the few
*language* features where Python leads Ruby.
If this post generates a positive response, I'll make a patch for Ruby
1.9.
Nope, leave the language as it is. I like it unaltered thank you very
much.
However I've never understood why there has to be 'one true syntax'
for any computer language. As long as the syntax generates the same
ASTs in the interpreter I can't see why you couldn't choose the syntax
you prefer - whether that is whitespace indentation, or the symbolic
mush of the 'C' derived languages.
···
On May 18, 8:23 am, Chris Dew <cms...@googlemail.com> wrote:
What I dislike about indent is that you need to satisfy the parser in
order to make the program run.
It's like an additional control element, like ';'.
I do not think a language should care about indentation.
With that having said, I concur with the initial statement - "end" does
not give me, as a programmer, meaningful information. I only have to use
it to satisfy the ruby parser - in python, you can omit that, but you
(a) must then indent properly (which is, again, to satisfy the parser)
and (b) you have to use the strange ':', which is annoying.
What I would love to have, however, would be a per-file option that
would allow me to omit end for a given .rb file. Just like shebang or
encoding lines could be used.
I could then write specific classes in a single .rb file (one class per
file) and they would be more readable too.
In message "Re: Why not adopt "Python Style" indentation for Ruby?" on Fri, 18 May 2007 22:01:13 +0900, Daniel Martin <martin@snowplow.org> writes:
Note that the Haskell folks have managed to evolve a language in which
python-like spacing can be used to mark the extent of discrete code
chunks, but so can traditional braces.
I admit Haskell syntax is much better than Python's. But I am not yet
sure if it can be applied to Ruby.
I, personally, don't have an argument on principle like that for my own
preferences in this matter. I just like the fact that an "end" makes it
look more complete to me. Reading Python code always makes me feel like
my eyes are just going to trail off the right-hand edge of the page
because the "shape" of the code never brings me back to the leftmost
edge, the way code "should".
When I look at Python code, and ponder the way it does things so
differently from Ruby regarding delimiters and indentation (the same
thing in Python), it seems to me that Python was created for people who
write code in a particular mindset, and it's not a mindset I share when
I'm writing code. I guess maybe some people, when writing code, think
in footnote hierarchies, while others (like me) think in nested scopes.
That's just an off-the-cuff hypothesis.
···
On Sun, May 20, 2007 at 12:05:06AM +0900, Brendan wrote:
On May 18, 4:23 am, Chris Dew <cms...@googlemail.com> wrote:
> ...
> with no reduction in meaning, yet 25% fewer lines of code.
>
> What are the reasons why this isn't used/implemented/liked? It would
> be a small change to the interpreter. Enabling meaningful indentation
> would only make 'end' optional, not invalid; backwards compatibility
> wouldn't be a problem.
>
> (I use both Ruby and Python. I think indentation is one of the few
> *language* features where Python leads Ruby.)
I personally prefer that 'end' be in place, so that all ruby code is
readable. I personally believe there may be something wrong with a
syntax which sacrifices explicit readability (for everyone, not just
python programmers) for increased typing speed and the illusory gain
of 'fewer LOC'. This was one of the major reasons which convinced me
to use ruby instead of python.
--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
Larry Wall: "A script is what you give the actors. A program is what you
give the audience."
You don't need to do code generation, at least in the way you have done it. I posted a solution way back up this thread that does not require the creation of intermediate files to load.
In foo.rb
require 'pyrb.rb'
__END__
def foo:
[1,2,3,4].each do |i|:
puts i
[1,2,3,4].each do |j|:
puts i
if i == 2 :
puts "foo"
else:
puts "bar"