Issue #5400 has been reported by Magnus Holm. ---------------------------------------- Feature #5400: Remove flip-flops in 2.0 http://redmine.ruby-lang.org/issues/5400 Author: Magnus Holm Status: Open Priority: Normal Assignee: Category: Target version: 2.0 Nobody knows them. Nobody uses them. Let's just get rid of flip-flops, shall we?
on 2011-10-04 09:43
on 2011-10-04 10:37
Issue #5400 has been updated by Joey Zhou. Magnus Holm wrote: > Nobody knows them. Nobody uses them. Let's just get rid of flip-flops, shall we? I disagree. The flip-flop syntax is obscure, but very useful, especially in text manipulation. For example, I want to fetch some chunks of lines : DATA.each_line do |line| print line if (line =~ /begin/)..(line =~ /end/) end __END__ 0a 1begin 2c 3end 4e 5f 6begin 7end 8i 9j this will print: 1begin 2c 3end 6begin 7end flip-flop syntax comes from Perl, the Perl idiom looks like "print if /begin/../end/;" or "print if 5..8;" (which means print line5 to line8). Perl idiom is implicit, not so easy to read, Ruby idiom is a little hard to write. I'm afraid Rudy didn't take advantage of flip-flops, I try to write in this way: DATA.readlines.select {|line| (line =~ /begin/)..(line =~ /end/) } # error it seems that ruby treat (line =~ /begin/)..(line =~ /end/) as a range object, that is not what I mean. Maybe it's difficult for the parser to distinguish the range token ".." and flip-flop token "..", how about change the token? for example, "~~"? DATA.readlines.select {|line| (line =~ /begin/)~~(line =~ /end/) } ---------------------------------------- Feature #5400: Remove flip-flops in 2.0 http://redmine.ruby-lang.org/issues/5400 Author: Magnus Holm Status: Open Priority: Normal Assignee: Category: Target version: 2.0 Nobody knows them. Nobody uses them. Let's just get rid of flip-flops, shall we?
on 2011-10-04 12:58
Issue #5400 has been updated by Joey Zhou. Magnus Holm wrote: > Nobody knows them. Nobody uses them. Let's just get rid of flip-flops, shall we? Well, the flip-flop behavior is useful, so it should not be removed. However, I agree that the syntax is a bit confusing. Flip-flop in Ruby is not so powerful as in Perl (http://perldoc.perl.org/perlop.html#Range-Operators). It seems like expression leading to true or false, but it cannot be assigned to a variable, and often be treated as a range literal. So maybe we can get rid of the ".." syntax, instead, introduce a class to do the same thing. I've implemented a simple class FlipFlop, which simulates the behavior of flip-flop in Perl. -- begin -- class FlipFlop def initialize(test_right_same_time=false) @bool = false @sequence_num = 0 @same_time = test_right_same_time end def rewind initialize(@same_time) end def test(condition_left,condition_right) if @bool == false and condition_left @sequence_num = 1 @bool = true if @same_time == true and condition_right @sequence_num = 1.0 @bool = false end return true elsif @bool == true and not condition_right @sequence_num += 1 return true elsif @bool == true and condition_right @sequence_num += 1.0 @bool = false return true else # @bool == false and condition_left == false @sequence_num = 0 return false end end def true? @bool end def value @sequence_num end def end? @sequence_num.is_a? Float end end -- end -- flipflop = FlipFlop.new # take only line3 ~ line5 from a chunk of lines (from /begin/ to /end/) lines = DATA.readlines.select do |line| t = flipflop.test(line =~ /begin/, line =~ /end/) t and flipflop.value.between?(3,5) end p lines # ["04end(x)\n", "09(x)\n", "10(x)\n", "11(x)\n", "17(x)\n", "18(x)\n", "19end(x)\n"] __END__ 01 02begin 03 04end(x) 05 06 07begin 08 09(x) 10(x) 11(x) 12end 13 14 15begin 16 17(x) 18(x) 19end(x) 20begin ---------------------------------------- Feature #5400: Remove flip-flops in 2.0 http://redmine.ruby-lang.org/issues/5400 Author: Magnus Holm Status: Open Priority: Normal Assignee: Category: Target version: 2.0 Nobody knows them. Nobody uses them. Let's just get rid of flip-flops, shall we?
on 2011-10-04 13:26
Hello,
I'm one of the few users of flip-flop.
W, H = 44, 54
c = 7 + 42 * W
a = [0] * W * H
g = d = 0
f = proc do |n|
a[c] += 1
o = a.map {|z| " :#"[z, 1] * 2 }.join.scan(/.{#{W * 2}}/)
puts "\f" + o.map {|l| l.rstrip }.join("\n")
sleep 0.005
d += 1 - 2 * ((g ^= 1 << n) >> n)
c += [1, W, -1, -W][d %= 4]
end
1024.times do
!!(!!(!!(!!(!!(!!(!!(!!(!!(true...
f[0])...f[1])...f[2])...
f[3])...f[4])...f[5])...
f[6])...f[7])...f[8])
end
Sorry for off-topic :-)
I have no objection to deletion, but I'm just curious.
Why do you want to delete it aggressively?
on 2011-10-07 19:34
On Tue Oct 04 2011 @ 4:43, Magnus Holm wrote: > Nobody knows them. Nobody uses them. Let's just get rid of flip-flops, > shall we? As someone who came to Ruby from Perl, I also use/like the flip-flop operator. Having said that, maybe a better question than "Who likes the feature?" or "Who doesn't?" is "What's bad enough about flip-flop that merits removal?" Does it cause some performance problem or lead to wrongheaded programming? (Not rhetorical: I genuinely don't see what would make it worth removing.) Thanks, Peter
on 2011-10-08 04:52
Issue #5400 has been updated by Andrew Grimm. I'll be a little sad if the flip flop operator is removed, but it is a Perlism, and Ruby is gradually getting rid of Perlisms. I suspect it won't be around in 100 years time, and I've heard that flip-flops aren't mentioned in the Ruby specification. When I mentioned flip-flops (and Rubinius' failure to support them) in my talk at RubyKaigi 2011, the response of some was "What's the flip flop operator?" If the feature is removed, how will Ruby treat existing code that uses the flip-flop operator? Will it convert it into a literal range, and raise an ArgumentError? (false)..(true) raises an ArgumentError Or will it explain that flip-flops are no longer supported? ---------------------------------------- Feature #5400: Remove flip-flops in 2.0 http://redmine.ruby-lang.org/issues/5400 Author: Magnus Holm Status: Open Priority: Normal Assignee: Category: Target version: 2.0 Nobody knows them. Nobody uses them. Let's just get rid of flip-flops, shall we?
on 2011-10-08 04:57
Hi,
Under the current plan, I am not going to remove flip-flop from 2.0,
since we are not going to made incompatible changes anytime soon. We
have to wait until 3.0.
matz.
In message "Re: [ruby-core:40043] [Ruby 1.9 - Feature #5400] Remove
flip-flops in 2.0"
on Sat, 8 Oct 2011 11:51:50 +0900, Andrew Grimm
<andrew.j.grimm@gmail.com> writes:
|I'll be a little sad if the flip flop operator is removed, but it is a Perlism,
and Ruby is gradually getting rid of Perlisms. I suspect it won't be around in 100
years time, and I've heard that flip-flops aren't mentioned in the Ruby
specification.
|
|When I mentioned flip-flops (and Rubinius' failure to support them) in my talk at
RubyKaigi 2011, the response of some was "What's the flip flop operator?"
|
|If the feature is removed, how will Ruby treat existing code that uses the
flip-flop operator?
|
|Will it convert it into a literal range, and raise an ArgumentError?
(false)..(true) raises an ArgumentError
|
|Or will it explain that flip-flops are no longer supported?
on 2011-10-10 17:49
> I have no objection to deletion, but I'm just curious. > Why do you want to delete it aggressively? > > -- > Yusuke Endoh <mame@tsg.ne.jp> I just want to get rid of complexity in the language. Currently, flip-flops aren't well known for Rubyists, so I don't feel comfortable of using them in code. I fear that it won't be readable. And if you *don't* know them, it's easy to confuse them for literal ranges, which makes it even more confusing. If it had a distinct syntax, you would at least realize that you don't know about them, now you would go "what? a Range literal is always true, no?".
on 2011-10-22 00:10
On 10 October 2011 16:48, Magnus Holm <judofyr@gmail.com> wrote: > And if you *don't* know them, it's easy to confuse them for literal > ranges, which makes it even more confusing. If it had a distinct > syntax, you would at least realize that you don't know about them, now > you would go "what? a Range literal is always true, no?". > > IMHO, "they aren't well known to Rubyists" doesn't sound like a good enough reason to delete it. Instead, my argument would be that I have found less use for them and therefore, it can be considered least used tool in the toolbox. On the same note, I would be curios to find out the use cases where flip-flops would be ideal. Just my two cents. Anuj
on 2012-03-26 20:34
Issue #5400 has been updated by mame (Yusuke Endoh). Target version set to 3.0 ---------------------------------------- Feature #5400: Remove flip-flops in 2.0 https://bugs.ruby-lang.org/issues/5400#change-25224 Author: judofyr (Magnus Holm) Status: Open Priority: Normal Assignee: Category: Target version: 3.0 Nobody knows them. Nobody uses them. Let's just get rid of flip-flops, shall we?
on 2012-11-18 02:41
Issue #5400 has been updated by boris_stitnicky (Boris Stitnicky). For Endo's sake, please don't remove this jewel, bring it to perfection, somehow :)))) ---------------------------------------- Feature #5400: Remove flip-flops in 2.0 https://bugs.ruby-lang.org/issues/5400#change-33033 Author: judofyr (Magnus Holm) Status: Open Priority: Normal Assignee: Category: Target version: Next Major Nobody knows them. Nobody uses them. Let's just get rid of flip-flops, shall we?
on 2013-02-26 01:34
Issue #5400 has been updated by ko1 (Koichi Sasada). Category set to core Assignee set to matz (Yukihiro Matsumoto) ---------------------------------------- Feature #5400: Remove flip-flops in 2.0 https://bugs.ruby-lang.org/issues/5400#change-37015 Author: judofyr (Magnus Holm) Status: Open Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: core Target version: Next Major Nobody knows them. Nobody uses them. Let's just get rid of flip-flops, shall we?
on 2013-03-23 00:53
This is an old, but still open, thread. The argument that Ruby's flip-flop operator should be removed just because someone doesn't use (or know) it, would also apply to a group of methods in Enumerable, all of the Socket library, a good number of IO methods, and anything else people haven't run into or bothered to investigate. There's no way for anyone to say how useful flip-flops are, short of trying to remove them and listening to the ensuing howling as code fails or people refuse to upgrade because their core apps won't run. I suspect we'd find a lot of code running deep in reporting and parsing systems in corporations using that feature. I know in our own code you'd find it. The ".." and "..." operators are obscure, but are incredibly for processing files and text, as said above. That Ruby has a "perlism" doesn't bother me at all. I'm not afraid of them, and don't think they're inherently bad. I've seen people's proposals for replacements for '..' and, frankly, the resulting replacement was horrific, and even less readable and would cause me to howl. So, until there's conclusive proof that it's not being used, or that there is a better way to do it and legacy code won't break, I'd say leave it alone. There are more interesting and useful things that could be done, like making URI more robust and modern, or figuring out why IPAddr barfs with IP addresses like '127.0.00.1', or '127.000.000.001', when Socket is completely happy with them.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.