Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Real life uses for closures.

by nikosv (Hermit)
on Feb 12, 2013 at 18:13 UTC ( #1018423=note: print w/ replies, xml ) Need Help??


in reply to Real life uses for closures.

GUI wise,could use a closure for events + state. For example click a button which fires an event but also encapsulates state too, for example keeping track of how many times that button has been clicked, etc

Could also be used for filtering data and since the question is language agnostic take a loot at Jon Skeet's The Beauty of Closures


Comment on Re: Real life uses for closures.
Re^2: Real life uses for closures.
by BrowserUk (Pope) on Feb 12, 2013 at 22:46 UTC
    take a loot at Jon Skeet's The Beauty of Closures

    Thanks for the link. The content was very interesting; and right on subject for my enquiry.

    (That said, now I remember what put me of learning C#. It just as bad a Java for making your source code look like you suffer from Tourette's: Predicate ... predicate ... predicate ... predicate. :)


    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.
      Heh, reading that link, one of the basic things I've used closures for lately is filtering a list in different ways. I had one utility function that goes into a loop parsing email files from a directory (and if successful, finally returning the attachments from the one you want according to some parameters) and skipping files that it's already seen before. Then I found that in some particular case I needed to call the function multiple times and have it remember what it had seen from the previous call. So I turned the filtering function into a parameter, allowing you to maintain the hash of 'seen' email files outside of the loop in the main function (but keeping the original behaviour by default, which is what I want most of the time). Pretty basic example...but there it is.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018423]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2014-12-18 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (48 votes), past polls