From: ptkwt@... (Phil Tomson) Date: 2004-02-01T05:09:52+09:00 Subject: Re: No difference between .. and ... flip/flop operators? In article <7434BCFA-541B-11D8-83F8-000A95CD7A8E@talbott.ws>, Nathaniel Talbott wrote: >On Jan 31, 2004, at 12:37, Michael campbell wrote: > >> Nathaniel Talbott wrote: >> >>> An interesting question; I'll try to give a coherent answer. First of >>> all, I have to read other people's code, and if they use obscure, >>> hard-to-understand constructs >> >> I don't find it either of those. >> >> >>> that I have to look up every time >> >> nor do I have to do that. > >Point taken. But then, I know from talking to others that my opinion on >it's clarity and my need to look it up are not isolated occurrences. > > >>> , it makes it much harder to grok what's going on. >> >> I understand and respect your point here, but is it not a nicer way of >> saying "I find hard to grok, so it should be restricted from >> _everyone's_ use"? > >Well, I'd phrase it more as, "It's hard for a lot of people to grok, so >we should find a better construct for it." I don't think the >functionality should go away, but I think it should be implemented as a >library function, not a piece of the syntax. Or, if it is syntax, that >that syntax should be more inherently self-apparent. > >I'd also add the sentence, "I find it dog-ugly, so I will do everything >within my power to see that it DIES!" It's this that really drives >me... the aesthetics of the construct just make me want to wretch. It's >an amalgamation of several different pieces of the language that just >don't make sense together. Oh, and it has internal state that those >various pieces don't. It just doesn't seem to fit in. Now if I was the >only one who had this opinion, then it should certainly stay... but >apparently matz agrees with me at some level. I'm bummed that some >people will miss it, but that's the fun of language design - you get to >"Tick off all of the people, some of the time." I'm glad he's the >designer and not me :-) > Not only will it be missed, it will break a _lot_ of code if it's removed. I wasn't at RubyConf2003, so I'm not sure, but rumor has it that Matz isn't worried about breaking code in Ruby 2.0 (Rite), similar to what the Perl folks are doing with Perl6.0, but it would be nice to have some sort of mechanism where we can discuss the proposed changes that will break things. At least in the case of Perl6 there will be a way to run legacy code (Pony and/or a translator). Will this sort of approach be available in Ruby 2.0? This issue needs more community discussion. Back to the flip/flop issue: What exactly do you propose to replace it with? If you propose to replace this piece of syntax with a library function, where should that function live? Maybe in File or IO somewhere? (like so): File.open("filename") {|f| f.each_line_between(/BEGIN/,/END/) {|l| #do something between BEGIN, END #but what if you want to nest another one in here? end } However, that doesn't help when you've got several flip/flops (or nested flip/flops) looking for several different ranges of lines in a file like: File.foreach("filename") {|f| f.each_line {|l| if l=~/BEGIN/ .. l=~/END/ #between BEGIN and END if l=~/def/ .. l=~/end/ #between def and end inside BEGIN .. END block end end } } I don't see any way that an 'each_line_between' type method would be able to do this since it lives in File. Perhaps we should introduce an 'each_line_between' for simple cases, but I don't see how it can replace the flip/flop op for the nested case (which is commonly done). I really hope Matz will reconsider. Phil