<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Separating event handling from event filtering</title>
	<atom:link href="http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/</link>
	<description></description>
	<lastBuildDate>Tue, 20 Jul 2010 14:27:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: mzx</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/comment-page-1/#comment-7816</link>
		<dc:creator>mzx</dc:creator>
		<pubDate>Thu, 30 Apr 2009 16:25:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-7816</guid>
		<description>&lt;p&gt;nice one.
and as u remember some flex components (TextInput) 
has different event handler for enter.. so to do as many events as u need is the correct approach imao&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>nice one.
and as u remember some flex components (TextInput) 
has different event handler for enter.. so to do as many events as u need is the correct approach imao</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Theo</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/comment-page-1/#comment-7796</link>
		<dc:creator>Theo</dc:creator>
		<pubDate>Thu, 09 Apr 2009 09:06:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-7796</guid>
		<description>&lt;p&gt;It&#039;s not a constructor in the object-oriented sense. It&#039;s a function that returns a lambda, it&#039;s a common functional programming idiom.&lt;/p&gt;

&lt;p&gt;Something can be a filter without having the name &quot;filter&quot;, and &quot;filter&quot; is an overloaded term and can mean different things. &quot;guarded&quot; is a filter because it filters, just like a guard is a filter since he or she says who can enter and who cannot. But a guard is not a water filter, nor is a cigarette filter, and none of those is the list filtering function &quot;filter&quot;.&lt;/p&gt;

&lt;p&gt;Your class-based version kind of shows exactly why I prefer to solve a problem like this using higher order functions. That code is so much unnecessary extra code that doesn&#039;t do anything besides creating a functor (i.e. an object that acts as a function). I understand that not every one knows functional programming idioms and get them straight away, but if you work in a language that has higher order functions why avoid using them? If someone doesn&#039;t get the functional approach to solving a problem it&#039;s too bad for them. If we shouldn&#039;t do this or that because some may not understand we might as well limit ourselves to the feature set of Fortran.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&quot;If you add the guarded listener on the stage for example you will have to remove the listener later or obj1 and obj2 will never be garbage collected.&quot;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is true for any event listener, your EventFilter too, so it&#039;s hardly an argument. Use weak references or keep the listener around, that&#039;s your options whichever way you decide to solve the problem.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>It&#8217;s not a constructor in the object-oriented sense. It&#8217;s a function that returns a lambda, it&#8217;s a common functional programming idiom.</p>

<p>Something can be a filter without having the name &#8220;filter&#8221;, and &#8220;filter&#8221; is an overloaded term and can mean different things. &#8220;guarded&#8221; is a filter because it filters, just like a guard is a filter since he or she says who can enter and who cannot. But a guard is not a water filter, nor is a cigarette filter, and none of those is the list filtering function &#8220;filter&#8221;.</p>

<p>Your class-based version kind of shows exactly why I prefer to solve a problem like this using higher order functions. That code is so much unnecessary extra code that doesn&#8217;t do anything besides creating a functor (i.e. an object that acts as a function). I understand that not every one knows functional programming idioms and get them straight away, but if you work in a language that has higher order functions why avoid using them? If someone doesn&#8217;t get the functional approach to solving a problem it&#8217;s too bad for them. If we shouldn&#8217;t do this or that because some may not understand we might as well limit ourselves to the feature set of Fortran.</p>

<p><em>&#8220;If you add the guarded listener on the stage for example you will have to remove the listener later or obj1 and obj2 will never be garbage collected.&#8221;</em></p>

<p>This is true for any event listener, your EventFilter too, so it&#8217;s hardly an argument. Use weak references or keep the listener around, that&#8217;s your options whichever way you decide to solve the problem.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Panayot</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/comment-page-1/#comment-7793</link>
		<dc:creator>Panayot</dc:creator>
		<pubDate>Wed, 08 Apr 2009 18:05:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-7793</guid>
		<description>&lt;p&gt;You are using kind of constructor but without new operator. The guarded returns a function object but you don&#039;t feel it as an object.&lt;/p&gt;

&lt;p&gt;Also you say it is filter but use &#039;guarded&#039; as name.&lt;/p&gt;

&lt;p&gt;I would prefer to use something like:&lt;/p&gt;

&lt;p&gt;public class EventFilter {
    protected var _filter:Function;
    protected var _function:Function;
    public function EventFilter(theFilter:Function, theFunction:Function) {
        _filter = theFilter;
        _function = theFunction;
    }
    public function get handler(e:Event) {
        if (_filter(e)) _function(e)
    } 
}&lt;/p&gt;

&lt;p&gt;Then assign listeners like:&lt;/p&gt;

&lt;p&gt;var eventFilter = new EventFilter(_isEnterKey, _onSend)
addEventListener(KeyboardEvent.KEY_UP, eventFilter.handler);&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;

&lt;p&gt;protected function _isEnterKey(e:Event) { ... }
protected function _onSend(e:Event) { form.send() }&lt;/p&gt;

&lt;p&gt;If you have getter and setters defined on the EventFilter you would be able to change the filtering function and the handler.&lt;/p&gt;

&lt;p&gt;Also that way it&#039;s clear that you create an object that references the objects that own the filter and the function properties.&lt;/p&gt;

&lt;p&gt;Some coders may miss the fact that the function returned by:
guarded(obj1.someFilter, obj2.somehandler);
would most probably reference the obj1 and obj2. If you add the guarded listener on the stage for example you will have to remove the listener later or obj1 and obj2 will never be garbage collected.&lt;/p&gt;

&lt;p&gt;Anyway it&#039;s only my point of view. You&#039;ve done nice work on this article and I would love to see your higher order functions library :)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>You are using kind of constructor but without new operator. The guarded returns a function object but you don&#8217;t feel it as an object.</p>

<p>Also you say it is filter but use &#8216;guarded&#8217; as name.</p>

<p>I would prefer to use something like:</p>

<p>public class EventFilter {
    protected var _filter:Function;
    protected var _function:Function;
    public function EventFilter(theFilter:Function, theFunction:Function) {
        _filter = theFilter;
        _function = theFunction;
    }
    public function get handler(e:Event) {
        if (_filter(e)) _function(e)
    } 
}</p>

<p>Then assign listeners like:</p>

<p>var eventFilter = new EventFilter(_isEnterKey, _onSend)
addEventListener(KeyboardEvent.KEY_UP, eventFilter.handler);</p>

<p>&#8230;</p>

<p>protected function _isEnterKey(e:Event) { &#8230; }
protected function _onSend(e:Event) { form.send() }</p>

<p>If you have getter and setters defined on the EventFilter you would be able to change the filtering function and the handler.</p>

<p>Also that way it&#8217;s clear that you create an object that references the objects that own the filter and the function properties.</p>

<p>Some coders may miss the fact that the function returned by:
guarded(obj1.someFilter, obj2.somehandler);
would most probably reference the obj1 and obj2. If you add the guarded listener on the stage for example you will have to remove the listener later or obj1 and obj2 will never be garbage collected.</p>

<p>Anyway it&#8217;s only my point of view. You&#8217;ve done nice work on this article and I would love to see your higher order functions library :)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Greveson</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/comment-page-1/#comment-7530</link>
		<dc:creator>Eric Greveson</dc:creator>
		<pubDate>Wed, 03 Sep 2008 21:30:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-7530</guid>
		<description>&lt;p&gt;I like the guard function method over the key mapper method (which I&#039;ve been using up to now), it&#039;s more flexible and reminds me that I should be making use of first-class functions (I&#039;m from a C++ background so I keep forgetting about them)! I&#039;d like to see your higher order functions library being released too - simple, lightweight libraries that really improve the way people code are something that&#039;s mostly missing from the Flex community at the moment (although I&#039;ve been trying Mate recently, after your recommendation, and it&#039;s pretty cool).&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I like the guard function method over the key mapper method (which I&#8217;ve been using up to now), it&#8217;s more flexible and reminds me that I should be making use of first-class functions (I&#8217;m from a C++ background so I keep forgetting about them)! I&#8217;d like to see your higher order functions library being released too &#8211; simple, lightweight libraries that really improve the way people code are something that&#8217;s mostly missing from the Flex community at the moment (although I&#8217;ve been trying Mate recently, after your recommendation, and it&#8217;s pretty cool).</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Carden</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/comment-page-1/#comment-7262</link>
		<dc:creator>Tom Carden</dc:creator>
		<pubDate>Fri, 15 Aug 2008 06:03:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-7262</guid>
		<description>&lt;p&gt;It took me a couple of attempts to fully understand the appeal of this approach, but I like it very much.  It feels somehow &quot;well rounded&quot; :)&lt;/p&gt;

&lt;p&gt;If you&#039;re still leaning towards releasing your higher order functions library, I&#039;d gladly contribute time to helping with documentation or testing.  I have some array filtering classes of my own that might fit with such a library, too.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>It took me a couple of attempts to fully understand the appeal of this approach, but I like it very much.  It feels somehow &#8220;well rounded&#8221; :)</p>

<p>If you&#8217;re still leaning towards releasing your higher order functions library, I&#8217;d gladly contribute time to helping with documentation or testing.  I have some array filtering classes of my own that might fit with such a library, too.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Marcus Stade</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/comment-page-1/#comment-6971</link>
		<dc:creator>Marcus Stade</dc:creator>
		<pubDate>Sat, 05 Jul 2008 17:00:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-6971</guid>
		<description>&lt;p&gt;I LOVE this concept, thank you very much for sharing! Great blog btw, just stumbled upon it.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I LOVE this concept, thank you very much for sharing! Great blog btw, just stumbled upon it.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Joshua E Cook</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/comment-page-1/#comment-6735</link>
		<dc:creator>Joshua E Cook</dc:creator>
		<pubDate>Fri, 16 May 2008 13:58:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-6735</guid>
		<description>&lt;p&gt;Stephan, although your KeyMapper works elegantly for associating an action with a particular keycode, the guarding method is more flexible.  Consider if you wanted to associate a different action for a keycode when the SHIFT or CTRL keys are held down.  This would require significant changes to your KeyMapper class, but only a simple change to the guard function is required.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Stephan, although your KeyMapper works elegantly for associating an action with a particular keycode, the guarding method is more flexible.  Consider if you wanted to associate a different action for a keycode when the SHIFT or CTRL keys are held down.  This would require significant changes to your KeyMapper class, but only a simple change to the guard function is required.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Bjorn Schultheiss</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/comment-page-1/#comment-6208</link>
		<dc:creator>Bjorn Schultheiss</dc:creator>
		<pubDate>Sun, 13 Apr 2008 13:45:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-6208</guid>
		<description>&lt;p&gt;The only time this seems useful is if your repeating the same &#039;if statement&#039; in multiple methods, otherwise you&#039;ve simply wrapped the if statement in another function...&lt;/p&gt;

&lt;p&gt;I was interested to see how you were going to modify
sendButton.addEventListener(MouseEvent.CLICK, onSendButtonClicked);&lt;/p&gt;

&lt;p&gt;but later you replaced it with
sendButton.addEventListener(MouseEvent.CLICK, onSendForm);&lt;/p&gt;

&lt;p&gt;ahh well.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>The only time this seems useful is if your repeating the same &#8216;if statement&#8217; in multiple methods, otherwise you&#8217;ve simply wrapped the if statement in another function&#8230;</p>

<p>I was interested to see how you were going to modify
sendButton.addEventListener(MouseEvent.CLICK, onSendButtonClicked);</p>

<p>but later you replaced it with
sendButton.addEventListener(MouseEvent.CLICK, onSendForm);</p>

<p>ahh well.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Functional ActionScript &#8211; Part III &#8212; RTFM / Daniel Gasienica</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/comment-page-1/#comment-5889</link>
		<dc:creator>Functional ActionScript &#8211; Part III &#8212; RTFM / Daniel Gasienica</dc:creator>
		<pubDate>Wed, 02 Apr 2008 01:03:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-5889</guid>
		<description>&lt;p&gt;[...] Iconara: Separating event handling from event filtering [...]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[...] Iconara: Separating event handling from event filtering [...]</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Theo</title>
		<link>http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/comment-page-1/#comment-5831</link>
		<dc:creator>Theo</dc:creator>
		<pubDate>Mon, 31 Mar 2008 11:44:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.iconara.net/2008/03/30/separating-event-handling-from-event-filtering/#comment-5831</guid>
		<description>&lt;p&gt;Stephan: yes, I agree, your solution is quite elegant. I have nothing against the if-statement in your handleKeyEvent, it is not of the kind that makes code fragile.&lt;/p&gt;

&lt;p&gt;guards are very general and there are absolutely better ways to solve specific cases.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Stephan: yes, I agree, your solution is quite elegant. I have nothing against the if-statement in your handleKeyEvent, it is not of the kind that makes code fragile.</p>

<p>guards are very general and there are absolutely better ways to solve specific cases.</p>]]></content:encoded>
	</item>
</channel>
</rss>
