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 18.05.2007 09:26
on 18.05.2007 09:38
Hi,
In message "Re: Why not adopt "Python Style" indentation for Ruby?"
on Fri, 18 May 2007 16:25:03 +0900, Chris Dew
<cmsdew@googlemail.com> writes:
|What are the reasons why this isn't used/implemented/liked?
Python style block by indentation is an interesting idea, but it works
badly with
* tab/space mixture
* templates, e.g. eRuby
* expression with code chunk, e.g lambdas and blocks
So I'd rather be conservative here.
matz.
on 18.05.2007 11:05
On 18/05/07, Yukihiro Matsumoto <matz@ruby-lang.org> wrote: > * tab/space mixture > * templates, e.g. eRuby > * expression with code chunk, e.g lambdas and blocks * clipboards, email, pastebins, and other places where the code is not preserved literally Thanks Michal
on 18.05.2007 11:07
Actually, Isn't end repeating yourself full stop? Do we really need it? Julian. On Fri, 18 May 2007 16:25:03 +0900
on 18.05.2007 11:09
On May 18, 2007, at 11:04 AM, Michal Suchanek wrote: >> works >> badly with >> >> * tab/space mixture >> * templates, e.g. eRuby >> * expression with code chunk, e.g lambdas and blocks > * clipboards, email, pastebins, and other places where the code is not > preserved literally code generators
on 18.05.2007 12:50
* tab/space mixture * templates, e.g. eRuby * expression with code chunk, e.g lambdas and blocks * clipboards, email, pastebins, and other places where the code is not preserved literally * code generators tabs can be made forbidden (g.v.rossum himself said he'd never supported tabs in the first place if he new what it would cauze) maybe it can be made optional. or one could write a little conversion script. i agree python's indentation looks clean. yet i have experienced allmost all of the above mentioned "cons"... _c.
on 18.05.2007 12:57
On May 18, 2007, at 12:50 PM, cies wrote: > maybe it can be made optional. or one could write a little > conversion script. Or add source filters: http://search.cpan.org/~fxn/Acme-Pythonic-0.45/lib/Acme/Pythonic.pm MWUUAHAHAHA. -- fxn
on 18.05.2007 14:31
On Fri, May 18, 2007 at 06:09:23PM +0900, Xavier Noria wrote: > >preserved literally > > code generators Disabling sections of code, i.e. if false ... ... code with original indentation ... end Also, multi-level namespaces where you don't want to indent the entire source file that much, e.g. module Foo module Bar class Baz def wibble ... end end # Baz end # Bar end # Foo (Admittedly, I believe it's now possible to write module Foo; module Bar; end; end class Foo::Bar::Baz ... end)
on 18.05.2007 15:02
Chris Dew <cmsdew@googlemail.com> writes: > 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.
on 18.05.2007 15:37
Hi,
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.
matz.
on 18.05.2007 16:00
On 18.05.2007 15:36, Yukihiro Matsumoto wrote:
> sure if it can be applied to Ruby.
Just to throw in my 0.02EUR here: I don't think it's worth the effort
(which I guess is huge) because Ruby's syntax *is* concise already. If
I got to decide I would rather see those efforts go into JVM based Ruby
implementations and / or native threads. But that's just my personal
preference.
Kind regards
robert
on 18.05.2007 16:04
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.) 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 18.05.2007 16:16
"Yukihiro Matsumoto" <matz@ruby-lang.org> wrote in message news:1179473895.694681.23173.nullmailer@x31.netlab.jp... > > * tab/space mixture > * templates, e.g. eRuby > * expression with code chunk, e.g lambdas and blocks > > So I'd rather be conservative here. > > matz. imho: indentation should not define semantic; suggestion: make 'end' optional if code block contains only one statement; BRs Sergey Volkov
on 18.05.2007 16:26
Hi,
In message "Re: Why not adopt "Python Style" indentation for Ruby?"
on Fri, 18 May 2007 23:15:05 +0900, "S.Volkov" <svolkov@comcast.net>
writes:
|imho: indentation should not define semantic;
Agreed.
|suggestion: make 'end' optional if code block contains only one statement;
I'm not sure if we can define syntax for above suggestion.
while cond
puts a
puts b # delimit by indentation or else??
or maybe
while cond: puts a # should be in same line
matz.
on 18.05.2007 17:15
Dnia Fri, 18 May 2007 16:38:05 +0900, Yukihiro Matsumoto napisa³(a): > Python style block by indentation is an interesting idea, but it works > badly with > > * tab/space mixture Tabs are against PEP8 which recomends space usage only. > * templates, e.g. eRuby eRuby is crap if you compare it with Haml template http://haml.hamptoncatlin.com/. It is interesting how they use indendation and how clean it can be. And finally... they are written in Ruby and for Ruby users! :) What do you think about OPTIONAL block indendation in Ruby?
on 18.05.2007 17:20
On 5/18/07, Yukihiro Matsumoto <matz@ruby-lang.org> wrote: > sure if it can be applied to Ruby. > > matz. I've picked up on python in the last couple months and like the indentation. In addition to forced readablity, I find another practical benefit is that it eliminates hard to track down syntax errors due to matching {}, begin/end, etc. In ruby, C, perl, etc these errors can be painful to track down in a large file with lots of blocks within blocks. Syntactically it isn't too difficult once you have the lexer generate indent and unindent tokens. Then the parser just looks for matching indent and unindent tokens instead of {} or begin/end, etc. You might consider something like this as an alternative block syntax. Maybe a ":" followed by a newline (and extra indentation) would start this style. I'm not sure of a clean way to handle arguments though. p.s. in the late eighties I made a little shell language (for the Atari ST) that used indentation just like python.
on 18.05.2007 17:22
Dnia Fri, 18 May 2007 22:36:58 +0900, Yukihiro Matsumoto napisa³(a):
> I admit Haskell syntax is much better than Python's.
Matz, you must be joking... Python is much easier to read than Haskell.
on 18.05.2007 17:26
On 5/18/07, Jaroslaw Zabiello <hipertracker@gmail.com> wrote: > > * templates, e.g. eRuby > > eRuby is crap if you compare it with Haml template > http://haml.hamptoncatlin.com/. Except eRuby is a general templating system, and Haml is for XHTML generation.
on 18.05.2007 17:40
On 5/18/07, Eric Mahurin <eric.mahurin@gmail.com> wrote: <snip> > I've picked up on python in the last couple months and like the > indentation. In addition to forced readablity, I find another > practical benefit is that it eliminates hard to track down syntax > errors due to matching {}, begin/end, etc. In ruby, C, perl, etc > these errors can be painful to track down in a large file with lots of > blocks within blocks. You could always run it through a tool to clean up code and provide proper indentation. I personally don't like it when a language dictates how my code ought to look, since I'm pretty picky myself :s > Syntactically it isn't too difficult once you have the lexer generate > indent and unindent tokens. Then the parser just looks for matching > indent and unindent tokens instead of {} or begin/end, etc. When working in a team, regardless of how the code has been formatted, I've always been able to slap pieces of code together and not worry about indentation (when such language doesn't worry about indentation). Working in python always adds a little extra stress when mixing and matching code, and the problem gets bigger when indentation isn't standardized across teams or when applying code from the web. filipe
on 18.05.2007 17:44
On 5/18/07, Jaroslaw Zabiello <hipertracker@gmail.com> wrote: > > He didn't say anything about readability. In terms of syntax structure and consistency, Haskell *is* better than Python. Every language is easy to read if you're used to reading it. Jason
on 18.05.2007 17:46
In message <1179498273.407463.1345.nullmailer@x31.netlab.jp>, Yukihiro Matsumoto writes: >|suggestion: make 'end' optional if code block contains only one statement; >I'm not sure if we can define syntax for above suggestion. I am pretty sure we can't, unless we acquire a machine sufficiently quantum to let us simply generate multiple outputs for each input program. That would, I think, resolve the question. Sort of. -s
on 18.05.2007 18:05
Dnia Sat, 19 May 2007 00:26:15 +0900, Gregory Brown napisa³(a): > Except eRuby is a general templating system, and Haml is for XHTML generation. It is not true. Haml can generate non valid XML content as well. But it is true that Haml main target is XHTML and CSS generation. For CSS generation is Sass which uses very similiar approach http://haml.hamptoncatlin.com/docs/sass Is it not strange that such solution was invented by Ruby, not Python, guys? :)
on 18.05.2007 18:17
On 5/18/07, Jaroslaw Zabiello <hipertracker@gmail.com> wrote: > > * templates, e.g. eRuby > eRuby is crap if you compare it with Haml template > http://haml.hamptoncatlin.com/. How well does Haml work with non-HTML templating? -austin
on 18.05.2007 18:18
Hi,
In message "Re: Why not adopt "Python Style" indentation for Ruby?"
on Sat, 19 May 2007 00:20:06 +0900, Jaroslaw Zabiello
<hipertracker@gmail.com> writes:
|> I admit Haskell syntax is much better than Python's.
|
|Matz, you must be joking... Python is much easier to read than Haskell.
To rephrase, "Haskell INDENTATION SYNTAX is much better than
Python's". Clear?
matz.
on 18.05.2007 18:20
On 5/18/07, Eric Mahurin <eric.mahurin@gmail.com> wrote: > On 5/18/07, Yukihiro Matsumoto <matz@ruby-lang.org> wrote: > I've picked up on python in the last couple months and like the > indentation. In addition to forced readablity, I find another > practical benefit is that it eliminates hard to track down syntax > errors due to matching {}, begin/end, etc. In ruby, C, perl, etc > these errors can be painful to track down in a large file with lots of > blocks within blocks. Scope indicated by whitespace is an indication, IMO, that the compiler thinks that it knows better than you do. Always a mistake. I want a programming language that works how I do; I don't want to have to work how a stupid programming language requires it. (I sometimes put debug statements flush left so that it's a simple /^p<CR> to search for them. Can't do that with scope controlled by whitespace. Dumb, dumb, dumb, dumb.) -austin
on 18.05.2007 18:22
On 5/18/07, Jaroslaw Zabiello <hipertracker@gmail.com> wrote: > Dnia Sat, 19 May 2007 00:26:15 +0900, Gregory Brown napisa³(a): > > Except eRuby is a general templating system, and Haml is for XHTML generation. > It is not true. Haml can generate non valid XML content as well. But it is > true that Haml main target is XHTML and CSS generation. For CSS generation > is Sass which uses very similiar approach > http://haml.hamptoncatlin.com/docs/sass Neither is useful for those of us who want general purpose templating. There are bigger problems in the world than your little web-apps. -austin, generates C++ with erb
on 18.05.2007 18:26
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.
on 18.05.2007 18:26
In message <9e7db9110705180919t527d5e10o5e6a8e96f2245b88@mail.gmail.com>, "Austin Ziegler" writ es: >(I sometimes put debug statements flush left so that it's a simple >/^p<CR> to search for them. Can't do that with scope controlled by >whitespace. Dumb, dumb, dumb, dumb.) Suspiciously familiar! -s
on 18.05.2007 18:59
On 5/18/07, Austin Ziegler <halostatue@gmail.com> wrote: > thinks that it knows better than you do. > > Always a mistake. > > I want a programming language that works how I do; I don't want to > have to work how a stupid programming language requires it. > > (I sometimes put debug statements flush left so that it's a simple > /^p<CR> to search for them. Can't do that with scope controlled by > whitespace. Dumb, dumb, dumb, dumb.) That is the exact same case I find the indentation thing gets in the way. I had to change my way of putting in print debug statements (same as yours). Every language makes you change your ways a bit. Of course python's debug facilities (pdb) are much better than ruby's so I don't do print debugging as much. I would rather have multiple ways to specify blocks: * {}'s * indentation * in-line (single statement/expression) BTW, python's lambda sucks! You can't put generic code in there - it must be a single expression. I think it has to do with the indentation thing. Only statements can have code blocks (using indentation) and a lambda is an expression. I don't like the clear separation of statements and expressions that python has. I think it all comes back to the indentation thing. They didn't do it right. Sounds like Haskell did (but I have no experience with it).
on 18.05.2007 19:25
On May 18, 12:19 pm, "Eric Mahurin" <eric.mahu...@gmail.com> wrote: > > blocks within blocks. No, it is just the other way around. Languages that use curly braces for indentation like C, Perl, etc. are EASY to work with once code is not properly factored and it extends outside a single page. Ruby is easy only when you use {, not so much when you use do/end, unfortunately, as most editors know nothing about it. Some good editors (emacs, for example), can tell you the context you are in the modeline with curly braces, but not so with other block indentation types. And most editors can easily find matching braces. No editor I am aware knows how to match indentation yet or do/end contexts (not that it could not be coded, thou). Python is a true nightmare to debug and understand once you have code that trails off a single page. A good example of these problems, for example, is the Maya Python API which is as ugly as it can be, using all of the ugliest things of python (tabulation using tabs, lots of underscore methods, lots of code that is not easily refactored, etc). Another problem with indentation only that has not been mentioned is that simple cut and paste of source code between two files is not guaranteed to work (and often will lead to a syntax error or worse, a runtime error). This to me is still a big no-no for indentation only, as most programmers *do* often cut and paste code from different contexts or files. With languages that use braces or Ruby's do/end you really don't have to worry about that, for the most part.
on 18.05.2007 19:45
On 2007-05-18, gga <GGarramuno@aol.com> wrote: > No editor I am aware knows how to match indentation yet or do/end > contexts (not that it could not be coded, thou). Emacs + ruby-mode.el understands do/end just fine. Regards, Jeremy Henty
on 18.05.2007 20:13
Chris Dew 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" 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. Wolfgang Nádasi-Donner
on 18.05.2007 20:17
"Yukihiro Matsumoto" <matz@ruby-lang.org> wrote in message news:1179498273.407463.1345.nullmailer@x31.netlab.jp... > Hi, > > In message "Re: Why not adopt "Python Style" indentation for Ruby?" > on Fri, 18 May 2007 23:15:05 +0900, "S.Volkov" <svolkov@comcast.net> > writes: > .. > > |suggestion: make 'end' optional if code block contains only one > statement; > > I'm not sure if we can define syntax for above suggestion. > > while cond > puts a > puts b # delimit by indentation or else?? You are right, not feasible - rejected :) > or maybe > > while cond: puts a # should be in same line Thus we introduce new semantic for newline! Following construct becomes invalid (and confusing): while cond: puts a puts b end =>my personal opinion - NO imho: we need special terminator anyway, now it is 'end', could be another; suggestion: introduce ';;' terminator for 'implicit blocks (not started with class/module/def/do/begin), ie: #-- while cond : puts a ; puts b ;; # but while cond do puts a ; puts b end #-- until - same as while #-- if cond : p a ;; #-- if cond : p a else p b ;; #-- unless - same as if #-- for var in expr : p var ;; # but for var in expr do p var end #-- case - sorry my lunch time ended, has to return back to my office.. BRs Sergey Volkov
on 18.05.2007 20:20
> *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...)
Cheers,
Enrique Comba Riepenhausen
on 18.05.2007 20:21
Hi,
In message "Re: Why not adopt "Python Style" indentation for Ruby?"
on Sat, 19 May 2007 03:15:17 +0900, "S.Volkov" <svolkov@comcast.net>
writes:
|imho: we need special terminator anyway, now it is 'end', could be another;
|suggestion: introduce ';;' terminator for 'implicit blocks (not started with
|class/module/def/do/begin), ie:
For your information, 1.9 once had exact same syntax you've proposed
for a short while. I have a time machine. The idea was abandoned
since it caused serious unreadability.
matz.
on 18.05.2007 20:51
On 5/18/07, gga <GGarramuno@aol.com> wrote: > No, it is just the other way around. Languages that use curly braces > for indentation like C, Perl, etc. are EASY to work with once code is > not properly factored and it extends outside a single page. Ruby is > easy only when you use {, not so much when you use do/end, > unfortunately, as most editors know nothing about it. Some good > editors (emacs, for example), can tell you the context you are in the > modeline with curly braces, but not so with other block indentation > types. And most editors can easily find matching braces. No editor I > am aware knows how to match indentation yet or do/end contexts (not > that it could not be coded, thou). Vim does this just fine. -austin
on 18.05.2007 23:18
On 5/18/07, Yukihiro Matsumoto <matz@ruby-lang.org> wrote: > with > |class/module/def/do/begin), ie: > > For your information, 1.9 once had exact same syntax you've proposed > for a short while. I have a time machine. The idea was abandoned > since it caused serious unreadability. > > matz. Very glad to hear it. We don't want Ruby turning into Ocaml, rife with unreadable symbols and impossible to follow constructions. Ruby's do/end is just fine. So we can't do two-liner if statements. I've never, ever liked that syntax as it makes code at first glance confusing. e.g.: int i = 0, j = 0, x = 0; for(i = 0; i < 10 ; i++) for(j = 0; j < 30; j++); for(x = 0; x < 100; x++) printf(i + j + x); I'm a big fan of the more verbose keywords of Ruby because for one there are very few of them and two it makes the language easy to read. Jason
on 18.05.2007 23:23
Eric Mahurin schrieb: > You might consider something like this as an alternative block syntax. > Maybe a ":" followed by a newline (and extra indentation) would start > this style. I'm not sure of a clean way to handle arguments though. What about another syntax: Putting a special character at the beginning of every line that is governed by significant whitespace. Thes would cause no problems with normal Ruby syntax, but would provide a way to use significant indentation if one really wants to. If "~" were that special character, it would look like that: ~ 5.times do |n| ~ n.times do ~ print n ~ puts Of course, hardly any editor would be prepared to support this, currently... This approach would have the additional advantage of being more robust to contexts where leading whitespace gets stripped. Cheers Sven
on 18.05.2007 23:26
Yukihiro Matsumoto schrieb: >syntax it should be. > +1 Sven
on 19.05.2007 00:42
On May 18, 5:22 pm, Sven Suska <sven71...@suska.org> wrote: > but would provide a way to use significant indentation if one really > wants to. > > If "~" were that special character, it would look like that: > ~ 5.times do |n| > ~ n.times do > ~ print n > ~ puts I can't count how many times I've forgotten "do". Sometimes I have wished a colon could "induce" the block: 5.times |n|: n.times: print n puts But I don't think a line prefix is worth the trouble. T.
on 19.05.2007 08:39
On 5/18/07, Trans <transfire@gmail.com> wrote: > > Putting a special character at the beginning of every line that is > > I can't count how many times I've forgotten "do". Sometimes I have > wished a colon could "induce" the block: That puzzles me, would you not forget the ":" then? Or do you have a lot of Python experience. Not that I think bad of the ":" syntax, just wondering. Robert
on 19.05.2007 10:31
"Yukihiro Matsumoto" <matz@ruby-lang.org> wrote in message news:1179512451.328481.6736.nullmailer@x31.netlab.jp... > |class/module/def/do/begin), ie: > > For your information, 1.9 once had exact same syntax you've proposed > for a short while. I have a time machine. The idea was abandoned > since it caused serious unreadability. always? may be real cause was abuse of this syntax? well, if suffix did not work, can we try prefix syntax for 'end'-less constructs? (if not has been tried before) suggestion: :& - prefixes 'single statement body' code block in class/module/def/unless/then/else/while/until #- samples if cond :& puts a if cond : puts a else :& puts b while cond :& puts a for var in expr :& puts var # also valid: if cond :& (puts a; puts b) while cond :& begin puts a end #- single statements 'chain' unless cond_a :& for ea in expr :& for eb in ezpr :& if cond(ea, eb) :& do_smthng #- simple functor with local state class<<fib=Object.new :& def get(m) :& (@fh||=Hash.new{|h,n|h[n]=n<2?n:h[n-1]+h[n-2]})[m] fib.get 10 #-> 55 BRs Sergey
on 19.05.2007 13:30
On May 19, 2:38 am, "Robert Dober" <robert.do...@gmail.com> wrote: > > > > ~ print n > > > ~ puts > > > I can't count how many times I've forgotten "do". Sometimes I have > > wished a colon could "induce" the block: > > That puzzles me, would you not forget the ":" then? Or do you have a > lot of Python experience. Not that I think bad of the ":" syntax, just > wondering. Hehe. Probably so. I'm not a hisser ;) But I think I would forget the colon much less often, especially given it created indention significance. T.
on 19.05.2007 13:35
On May 18, 2:41 pm, Jeremy Henty <onepo...@starurchin.org> wrote: > On 2007-05-18, gga <GGarram...@aol.com> wrote: > > > No editor I am aware knows how to match indentation yet or do/end > > contexts (not that it could not be coded, thou). > > Emacs + ruby-mode.el understands do/end just fine. > > Regards, > > Jeremy Henty No, it doesn't. When I type a close brace in emacs, I get the corresponding line where the matching brace matches (hilited if visible in the page, or in the modeline if not). When I position myself next to a brace, I get the same hiliting happening. Can't recall if that's a feature of hilite or the electric mode of emacs. However, whenever I type "end" to close a block, I have NO clue where the block begins. And if it is code I did not write, not knowing where the code begins is a killer. Being emacs, I *could* potentially hack the lisp code to handle do/end blocks properly (or indentation too). I haven't seen anyone do it yet (and publically give it away).
on 19.05.2007 17:05
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.
on 19.05.2007 20:03
On Sun, May 20, 2007 at 12:05:06AM +0900, Brendan wrote: > > *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. 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 19.05.2007 20:49
Chad Perrin wrote: >>> (I use both Ruby and Python. I think indentation is one of the few > look more complete to me. Reading Python code always makes me feel like > > That's just an off-the-cuff hypothesis. > I've been watching this debate go by for some time, and I'm not sure this sort of thing can ever be solved, but here are my personal opinions: 1. When you come right down to it, there are only a few basic syntax styles that have survived the test of time. *Most* languages, including C, Ruby, Pascal and Perl, use some variant of the Algol 60 syntax. The other "survivors" are the Lisp/Scheme variant of prefix notation, Forth's postfix notation, and the regular expression syntax. I suppose assembly language syntax has also survived, and FORTRAN and COBOL, but I don't think anyone would design a new language with those. 2. I think Python's "variant" of Algol 60 notation is less than satisfactory, but I also have problems with the liberality present in the syntax of Perl and Ruby. I don't like to make the reader or parser work any harder than necessary just for the convenience of the coder. So I like explicit delimiters like curly braces, parentheses, mandatory semicolons at the end of statements, begin/end pairs, etc. for the Algol 60 languages. Lisp/Scheme and Forth were deliberately designed to make the parser's job trivial, and I like them too. :) 3. I've pretty much given up on the dream that I'll be able to program in one language only, although some languages are close enough. At the moment, I can get just about everything done in either Perl or R, with the other languages simply being fun to learn and use but not essential. I could probably eliminate Perl if there were more R programmers, but there aren't and won't be, because R is designed for scientists and mathematicians, not business people.
on 19.05.2007 21:46
Trans schrieb: >>~ n.times do >>~ print n >>~ puts >> >> > >But I don't think a line prefix is worth the trouble. > > Trouble? -- I want the editor to insert the prefix, of course. Some editors are already able to do this with line comments, so they can be adapted easily. Sven
on 20.05.2007 04:50
On May 18, 12:58 pm, "Eric Mahurin" <eric.mahu...@gmail.com> wrote: > > > these errors can be painful to track down in a large file with lots of > > (I sometimes put debug statements flush left so that it's a simple > > /^p<CR> to search for them. Can't do that with scope controlled by > > whitespace. Dumb, dumb, dumb, dumb.) > > That is the exact same case I find the indentation thing gets in the > way. I had to change my way of putting in print debug statements > (same as yours). Every language makes you change your ways a bit. Of > course python's debug facilities (pdb) are much better than ruby's so Well, I think that's going to change over the next year. If you haven't tried Ken Sibilev's ruby-debug, http://rubyforge.org/projects/ruby-debug/ give it a shot. Over the last year it has improved quite a bit and I expect over the next year it will make the same steady progress. I'm hoping the next release will have a user manual, and possibly start adding some regression tests (which by the way pdb doesn't currently have). As someone who's a little bit familiar with both debuggers, I think the design of ruby-debug is the cleaner and more flexible. In fact, I think it's the best organized debugger of any that I've seen so far. (But then. as it grows..)
on 20.05.2007 09:46
On 19.05.2007 20:48, M. Edward (Ed) Borasky wrote: > 2. I think Python's "variant" of Algol 60 notation is less than > satisfactory, but I also have problems with the liberality present in > the syntax of Perl and Ruby. I don't like to make the reader or parser > work any harder than necessary just for the convenience of the coder. I would understand why you would want to make the reader's job easier - but the parser? That's just a piece of software and I believe that we should always strive to make software easier to use for humans not machines. Besides of that, personally I don't find the current Ruby syntax hard to read. Do you have some examples where you feel that reading Ruby is made hard(er) because of the liberties you mention? Kind regards robert
on 20.05.2007 10:12
IMHO, at least in complicated cases, the reader has to emulate a parer, so both are the same. Whenever there is syntax that's tricky to parse, it's also tricky to read. See pythons space-vs-tab problem, for example. Aur
on 20.05.2007 10:26
Quoting Robert Klemme <shortcutter@googlemail.com>: > > Besides of that, personally I don't find the current Ruby syntax hard to > read. Do you have some examples where you feel that reading Ruby is > made hard(er) because of the liberties you mention? > > Kind regards > > robert I can think of three examples right off the top of my head: Rails, Rake and RSpec. There's something really eerie about seeing code like that. You *know* it works, but you can't figure out why or how.
on 20.05.2007 10:36
On 20/05/07, znmeb@cesmail.net <znmeb@cesmail.net> wrote: > Quoting Robert Klemme <shortcutter@googlemail.com>: > > Besides of that, personally I don't find the current Ruby syntax hard to > > read. Do you have some examples where you feel that reading Ruby is > > made hard(er) because of the liberties you mention? > I can think of three examples right off the top of my head: Rails, Rake and > RSpec. There's something really eerie about seeing code like that. You *know* > it works, but you can't figure out why or how. And you think replacing do/end with indentation would help? I really can't see how - could you give an example?
on 20.05.2007 14:02
Trans wrote: > On May 18, 5:22 pm, Sven Suska <sven71...@suska.org> wrote: >> but would provide a way to use significant indentation if one really >> wants to. >> >> If "~" were that special character, it would look like that: >> ~ 5.times do |n| >> ~ n.times do >> ~ print n >> ~ puts > > I can't count how many times I've forgotten "do". Sometimes I have > wished a colon could "induce" the block: > > 5.times |n|: > n.times: > print n > puts > > But I don't think a line prefix is worth the trouble. > > T. I totally agree. A line pre-fix is a bit pointless in my opinion, although I am in favour in moving towards a Python-style indentation syntax. As for the 'do' issue I don't see why it can't be removed, if something is always expected then you can just assume its there, right? 5.times do |n| n.times do print n end puts end (Or using the ':' instead) Could just be: 5.times |n| n.times print n end puts end