in reply to Re^2: flip-flop flop
in thread flip-flop flop

Because of this global-state issue the flip-flop is pretty much useless to me

My take is that the flip-flop is very useful for one-liners were is compactness is invaluable, and I wouldn't want to lose that.

But I cannot remember the last time I used in a script. What it does can always be done better -- though more verbosely -- when you have the space.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^4: flip-flop flop
by morgon (Priest) on Mar 30, 2012 at 13:07 UTC
    From my point all it would take is a way to reset it's state somehow - then the flip-flop could be handy.

    Is there any reason why this functionality does not (seem to) exist?

      The main reason is that implicit state that must be resetted explicitly is a bad idea. Especially if you compare it to a lexical variable, which provides state explicitly, and is resetted implicitly at the end of the scope.

      For example if an exception is thrown before you do the reset, the next call of your function will return wrong results.

      And what if there are multiple flip-flops in scope? How do you control which one is reset?

        I agree with your opinion regarding explicitely resetting an implicit state, nevertheless having such a hack (ugly as it would be) available would at least allow to use the flip-flop that is (at least to me) pretty much useless as it is.

        What I would wish for is a flip-flop that is tied to it's lexical scope and gets reset when control leaves the scope.

        As (for me at last) this is such a natural requirement that I assume the fact that it is not implemented probably means there would be other problems with such an approach...