<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Parker Malenke → Feed</title>
		<description></description>
		<link>http://prkr.me</link>
		<atom:link href="http://prkr.me/feed.xml" rel="self" type="application/rss+xml" />

		
		<item>
			<title>NYC Redux</title>
			<description>
				
				
				&lt;img src="https://live.staticflickr.com/65535/48485083896_4834082999_b.jpg" title="Blue man" /&gt;
				
				&lt;img src="https://live.staticflickr.com/65535/48485084126_62b9ca129a_b.jpg" title="Untitled man" /&gt;
				
				&lt;img src="https://live.staticflickr.com/65535/48485084491_ef0759cffe_b.jpg" title="Italian street corner" /&gt;
				
				&lt;img src="https://live.staticflickr.com/65535/48485241852_944f5a6c24_b.jpg" title="Buildings" /&gt;
				
				&lt;img src="https://live.staticflickr.com/65535/48485084986_53794389fa_b.jpg" title="Strolling" /&gt;
				
				&lt;img src="https://live.staticflickr.com/65535/48485242397_4e50771a0b_b.jpg" title="Driving" /&gt;
				
				
			</description>
			<link>http://prkr.me/pictures/2019/nyc-redux/</link>
			<guid>http://prkr.me/pictures/2019/nyc-redux/</guid>
			<pubDate>Wed, 07 Aug 2019 00:00:00 -0600</pubDate>
		</item>
		
		<item>
			<title>Understanding the Javascript Event Loop</title>
			<description>
				
				&lt;p&gt;I&amp;rsquo;ve been working on a &lt;a href=&quot;http://backbonejs.com&quot;&gt;backbone.js&lt;/a&gt; website lately and one of the major paradigms of this framework is that events play an important role in driving the application logic (for example, a model is changed and subsequently emits an event informing a view of the need to update). To this end, all the major Backbone classes integrate a custom event system that allows objects to listen for events on other objects or to trigger their own events.&lt;/p&gt;

&lt;p&gt;Event programming isn&amp;rsquo;t always the most intuitive, so I wanted to do a little research on how exactly events work in Javascript before sinking a bunch of time into the paradigm. This post collects my findings about events and the Javascript event loop, mainly for my own reference, but perhaps others will find it useful as well. Since I&amp;rsquo;m definitely not an expert on javascript, some of this may be incorrect&amp;mdash;I will attempt to point out all areas where my understanding is fuzzy and provide code examples to illustrate my findings.&lt;/p&gt;

&lt;h2&gt;Say Hello to the Stack&lt;/h2&gt;

&lt;p&gt;Every time you call a function, the JS runtime (I believe this would be something like V8 in Chrome, Nitro in Safari, or whatever your browser implements) adds a &lt;em&gt;frame&lt;/em&gt; to the stack. This is a last-in-first-out (LIFO) structure that manages all the functions you call. A frame consists of the arguments for the function, all its local variables, and the code contained in its block.&lt;/p&gt;

&lt;p&gt;When you invoke a script the runtime will retrieve the first frame and start executing it. When it gets to another function call it pauses execution of the current frame, adds a frame for the internal function to the stack, and starts executing the new frame (the last in is the first out). Consider the example code in the figure below. The stack starts off empty because no functions have been called. When &lt;code&gt;a&lt;/code&gt; is invoked a frame is created for it and added to the stack. In this example, the runtime will log a message to the console, and then come to the invocation of &lt;code&gt;b&lt;/code&gt;. At this point it pauses execution of &lt;code&gt;a&lt;/code&gt;, creates a frame for &lt;code&gt;b&lt;/code&gt;, adds it to the stack, and begins executing &lt;code&gt;b&lt;/code&gt;. Once &lt;code&gt;b&lt;/code&gt; has completed the runtime will clear that frame off the stack and return to the frame for &lt;code&gt;a&lt;/code&gt;. Once the last function completes the stack will be completely empty.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/photos/events-fig1.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We can test this by adding some status messages to the code:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;starting...&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;added a to the stack&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;hello from b&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;removing a from the stack&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;added b to the stack&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;removing b from the stack&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;...done&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This produce the following output:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;[Log] starting... (index.html, line 9)
[Log] added a to the stack (index.html, line 12)
[Log] added b to the stack (index.html, line 18)
[Log] hello from b (index.html, line 19)
[Log] removing b from the stack (index.html, line 20)
[Log] removing a from the stack (index.html, line 14)
[Log] ...done (index.html, line 24)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;It&amp;rsquo;s possible to put too many functions/frames on the stack at once (the infamous &amp;lsquo;stack overflow&amp;rsquo;); this can happen if you call a recursive function on an input that&amp;rsquo;s too large and spawns too many sub calls. Sounds like ES6 &lt;a href=&quot;http://bbenvie.com/articles/2013-01-06/JavaScript-ES6-Has-Tail-Call-Optimization&quot;&gt;might be getting proper tail calls&lt;/a&gt; that would enable recursion over larger data sets.&lt;/p&gt;

&lt;h2&gt;Events&lt;/h2&gt;

&lt;p&gt;Alright, now back to the topic at hand. The first major point to realize is that there are two kinds of events in Javascript: &lt;em&gt;synchronous&lt;/em&gt; and &lt;em&gt;asynchronous&lt;/em&gt;. Most browser events are asynchronous, although a few are synchronous (such as &lt;a href=&quot;http://javascript.info/tutorial/events-and-timing-depth#synchronous-events&quot;&gt;DOM mutation and Nested Dom events&lt;/a&gt;). Any custom event handling, such as the events module built into backbone.js, another custom solution like &lt;a href=&quot;https://github.com/Wolfy87/EventEmitter&quot;&gt;EventEmitter&lt;/a&gt;, or jQuery&amp;rsquo;s &lt;a href=&quot;http://api.jquery.com/trigger/&quot;&gt;&lt;code&gt;.trigger()&lt;/code&gt;&lt;/a&gt; function, is going to be a synchronous implementation. So what&amp;rsquo;s the difference between these types of events?&lt;/p&gt;

&lt;h3&gt;Synchronous Events&lt;/h3&gt;

&lt;p&gt;Synchronous events are basically another way of invoking functions. Emission of these events essentially involves walking through a list of listener/handler functions and calling them. Consider the following sample implementation:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;EventManager&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_events&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{};&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// private storage for events and their listeners&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// if the event already exists, add the callback&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// otherwise create it with the given callback&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_events&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;nx&quot;&gt;_events&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;nx&quot;&gt;_events&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// invoke all the functions registered with an event&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;trigger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ev&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_events&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[];&lt;/span&gt;

            &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ev&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;nx&quot;&gt;ev&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;})();&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;So synchronous event systems are really just a way to invoke one or more functions without knowing what those functions are at the point when the event is triggered. Calling &lt;code&gt;EventManager.trigger()&lt;/code&gt; pauses execution of whatever block you&amp;rsquo;re in and then sequentially invokes each of the listeners, adding and removing them from the stack until the list is exhausted, at which point control is returned to the context that emitted the event.&lt;/p&gt;

&lt;p&gt;Consider this example:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;c1&quot;&gt;// Make a plan for a martian landing&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;tellThePublic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;The martians are coming!&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;EventManager&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;martians:landed&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;tellThePublic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;react&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Head for the hills!&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;EventManager&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;martians:landed&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;react&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Our plan is now in place&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;


&lt;span class=&quot;c1&quot;&gt;// later...&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;EventManager&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;trigger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;martians:landed&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Plan executed&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This will output:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;[Log] Our plan is now in place
[Log] The martians are coming!
[Log] Head for the hills!
[Log] Plan executed&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Notice that when the event was triggered, execution of the main script was paused while all the listeners were invoked (i.e. &amp;lsquo;Plan executed&amp;rsquo; wasn&amp;rsquo;t logged until the plan was actually carried out). In this case execution followed these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Triggering the &lt;code&gt;&#39;martians:landed&#39;&lt;/code&gt; event pauses the main context&lt;/li&gt;
&lt;li&gt;&lt;code&gt;tellThePublic()&lt;/code&gt; is added to the stack&lt;/li&gt;
&lt;li&gt;&lt;code&gt;tellThePublic()&lt;/code&gt; is pulled off and executed&lt;/li&gt;
&lt;li&gt;&lt;code&gt;react()&lt;/code&gt; is added to the stack&lt;/li&gt;
&lt;li&gt;&lt;code&gt;react()&lt;/code&gt; is pulled off and executed&lt;/li&gt;
&lt;li&gt;Main context resumes and &lt;code&gt;&#39;Plan executed&#39;&lt;/code&gt; is logged&lt;/li&gt;
&lt;/ol&gt;


&lt;h3&gt;Asynchronous Events&lt;/h3&gt;

&lt;p&gt;Instead of acting as a shortcut for adding frames to the stack, triggering async events adds messages to a queue. This behavior can&amp;rsquo;t be simulated with third party code (at least not that I&amp;rsquo;m aware of). Before discussing the queue, what kind of events are asynchronous? In my research it sounds like pretty much any event that comes from the browser, or in node any event that comes from a built in object. Clicks on elements, &lt;code&gt;window.setTimeout&lt;/code&gt; callbacks, mouseovers, keypresses, &lt;code&gt;XMLHttpResponse&lt;/code&gt;&amp;rsquo;s &lt;code&gt;readyState&lt;/code&gt;, etc. all behave in an asynchronous fashion.&lt;/p&gt;

&lt;h4&gt;The Event Queue&lt;/h4&gt;

&lt;p&gt;In addition to the stack, javascript runtimes include a structure known as the &lt;em&gt;queue&lt;/em&gt;. This is similar, except that it operates on a first-in-first-out (FIFO) basis. Whenever you register an event handler for an async event the runtime makes a note associating the provided function with the specified event. When an event is triggered the runtime looks through its list of handlers to see if any are associated with the current event. If so, it creates a &lt;em&gt;message&lt;/em&gt;, which references the handler function, and adds it to the queue. How are messages from the queue invoked? That&amp;rsquo;s the job of the event loop.&lt;/p&gt;

&lt;h4&gt;The Event Loop&lt;/h4&gt;

&lt;p&gt;Whenever the stack is empty, the runtime will ask the event loop for the next available message. If one exists, the event loop hands the associated function off to the runtime, which creates a corresponding frame, adds it to the stack, and executes it. Note the major difference versus synchronous events here: &lt;em&gt;Async event handlers are only ever invoked when the stack is empty.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here is a figure illustrating the sequence of events (zing!) that happens when dealing with an async event:
&lt;img src=&quot;/assets/photos/events-fig3.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h4&gt;Code Example&lt;/h4&gt;

&lt;p&gt;Okay, let&amp;rsquo;s look at some code. Here&amp;rsquo;s an example that will hopefully make this clearer.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;c1&quot;&gt;// create a handler function and add it to the click event&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;broadcast&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;A click event was fired!&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;click&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;broadcast&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;If you were to run this example and start clicking around you&amp;rsquo;d see the message would be logged to the console pretty much in real time as you click the document. Note that in this case the stack is basically empty this whole time. Now let&amp;rsquo;s try it with a stack that has more stuff to do.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;c1&quot;&gt;// here&amp;#39;s a long running function&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;runFor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;ms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getTime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){}&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// yes this is very hacky&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// now run this on the stack while we&amp;#39;re listening for the click event&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;broadcast&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;A click event was fired!&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;click&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;broadcast&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;runFor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now if you run this and start clicking on the document you&amp;rsquo;ll see that nothing is logged for 5 seconds and then all of a sudden a bunch of strings are logged. This is because the &lt;code&gt;runFor()&lt;/code&gt; function stays on the stack for 5 seconds. No messages from the event queue can be handled until the stack is clear. Once it finally clears all the messages are handled in sequential order. To check that messages are handled in a FIFO manner try the example with a different handler:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;broadcastCounter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_count&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Click number: &amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;_count&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;})();&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;click&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;broadcastCounter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;You should see that the strings are printed in sequential order starting at 1 and going up.&lt;/p&gt;

&lt;h4&gt;Remaining Questions&lt;/h4&gt;

&lt;p&gt;At this point I feel like I have a pretty good handle on the event loop and asynchronous events. There are still a few points that aren&amp;rsquo;t entirely clear, but I have some guesses at what the answers are.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Is a call to &lt;code&gt;addEventListener()&lt;/code&gt; blocking?&lt;/em&gt;&lt;br/&gt;
Functions that register async event handlers tend to return pretty much instantaneously. My guess is that in a strictly single threaded environment these functions will block the execution of a script until the runtime finishes recording the event and respective handler (step 2 in the diagram). I suppose it&amp;rsquo;s possible that some of the runtime maintenance tasks like this could also occur in a separate thread/process.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Is the message enqueueing process blocking?&lt;/em&gt;&lt;br/&gt;
When an async event is triggered, does the runtime pause execution of the script while it looks up the relevant handler and adds it to the event queue? Again, I think this would work as a concurrent process, but it&amp;rsquo;s not required.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Do async processes ever occur simultaneously?&lt;/em&gt;&lt;br/&gt;
The examples I had in mind were file reads in node.js or ajax requests in the client. I&amp;rsquo;m pretty sure ajax requests can occur concurrently, with something along the lines of:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You create an XMLHttpRequest object, this blocks the main thread while telling the browser where to get the resource, what headers to use, etc.&lt;/li&gt;
&lt;li&gt;Once the browser gets all this info, your function returns and execution continues.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;While your execution is continuing&lt;/em&gt; the browser has started a request in another thread. Your continuing execution might start additional ajax requests, which might also occur concurrently if the browser supports multiple http requests (I think they all do these days).&lt;/li&gt;
&lt;li&gt;When that request returns an event is fired and your callback is added to the event queue.&lt;/li&gt;
&lt;li&gt;The stack empties at some point and your callback is taken off the event loop and executed with the results of the request.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;I&amp;rsquo;m not sure about file reads in node.js. My guess is that it&amp;rsquo;s a similar process, except that a file read kicks off a separate thread at the OS level that then returns with the results of the file. In this manner you could have your js executing in one thread, a file read executing in another thread, and an ajax request executing in a third thread. So you can have concurrent execution with javascript, it&amp;rsquo;s just that only one script is ever executing at a time (the other threads are in the browser or at the OS level).&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;So that&amp;rsquo;s my brief foray into javascript events and the event loop. For functions that don&amp;rsquo;t take too long to execute it probably doesn&amp;rsquo;t matter if you&amp;rsquo;re using synchronous or asynchronous events, but if you have anything that could hold up the main thread for very long or are attaching an event handler that could take a while to clear it&amp;rsquo;s good to know the differences.&lt;/p&gt;

&lt;h3&gt;Takeaways&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Asynchronous event handlers will be blocked by anything on the stack. Design your script to leave the stack empty whenever possible. Try moving things into messages in the queue instead.&lt;/li&gt;
&lt;li&gt;Synchronous event handlers will block the main thread. This has the potential to lock up the browser if you run anything too intensive in them.&lt;/li&gt;
&lt;li&gt;Javascript never executes in parallel, but it can kick off other threads/processes in the browser, OS, runtime, etc. (I think.)&lt;/li&gt;
&lt;li&gt;Asynchronous events means that your script doesn&amp;rsquo;t have to block while it waits for these other threads to return. You can keep doing something else, and then once the other thread returns &lt;em&gt;and&lt;/em&gt; you&amp;rsquo;re not doing anything else you can handle the results of whatever process you started.&lt;/li&gt;
&lt;li&gt;Custom events (backbone.js&amp;rsquo;s event model, jQuery&amp;rsquo;s &lt;code&gt;.trigger()&lt;/code&gt;, other third party custom event libraries) are not asynchronous. Instead they&amp;rsquo;re just a handy way of organizing your function invocations.&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Resources&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/EventLoop&quot;&gt;Concurrency model and Event Loop (MDN)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blog.carbonfive.com/2013/10/27/the-javascript-event-loop-explained/&quot;&gt;The JavaScript Event Loop: Explained&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://javascript.info/tutorial/events-and-timing-depth#asynchronous-events&quot;&gt;Events and Timing In-Depth&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.inkling.com/read/javascript-definitive-guide-david-flanagan-6th/chapter-19/handling-events-with-jquery&quot;&gt;Handling Events with jQuery&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events&quot;&gt;Creating and Triggering Events (MDN)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://thomashunter.name/blog/the-javascript-event-loop-presentation/&quot;&gt;The Javascript Event Loop&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Examples&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://codepen.io/anon/pen/Aeivq&quot;&gt;http://codepen.io/anon/pen/Aeivq&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://codepen.io/anon/pen/Hgziy&quot;&gt;http://codepen.io/anon/pen/Hgziy&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


				
			</description>
			<link>http://prkr.me/words/2014/understanding-the-javascript-event-loop/</link>
			<guid>http://prkr.me/words/2014/understanding-the-javascript-event-loop/</guid>
			<pubDate>Sun, 23 Mar 2014 00:00:00 -0600</pubDate>
		</item>
		
		<item>
			<title>NYC</title>
			<description>
				
				
				&lt;img src="http://farm8.staticflickr.com/7421/12548036725_ffe5e6fefb_b.jpg" title="Reading room" /&gt;
				
				&lt;img src="http://farm8.staticflickr.com/7317/12548209563_1d3a331e57_b.jpg" title="Gutenberg Bible" /&gt;
				
				&lt;img src="http://farm8.staticflickr.com/7366/12548241833_9cf612ea31_b.jpg" title="A southern view" /&gt;
				
				&lt;img src="http://farm8.staticflickr.com/7372/12548139185_67ffe38f6a_b.jpg" title="Grids" /&gt;
				
				
			</description>
			<link>http://prkr.me/pictures/2014/nyc/</link>
			<guid>http://prkr.me/pictures/2014/nyc/</guid>
			<pubDate>Sat, 15 Feb 2014 00:00:00 -0700</pubDate>
		</item>
		
		<item>
			<title>Oxford</title>
			<description>
				
				
				&lt;img src="http://farm3.staticflickr.com/2860/11764613683_3f9afcc613_b.jpg" title="Oxford Architecture" /&gt;
				
				&lt;img src="http://farm4.staticflickr.com/3752/11764627933_8e03ec0a86_b.jpg" title="Radcliffe Camera" /&gt;
				
				&lt;img src="http://farm4.staticflickr.com/3816/11764337875_f14cb36ec6_b.jpg" title="Simply Messing About in Boats" /&gt;
				
				&lt;img src="http://farm4.staticflickr.com/3704/11764355505_b5f8b48e14_b.jpg" title="Christ Church" /&gt;
				
				&lt;img src="http://farm3.staticflickr.com/2852/11764640983_c0639d6570_b.jpg" title="Those Dreaming Spires" /&gt;
				
				
			</description>
			<link>http://prkr.me/pictures/2014/oxford/</link>
			<guid>http://prkr.me/pictures/2014/oxford/</guid>
			<pubDate>Sat, 04 Jan 2014 00:00:00 -0700</pubDate>
		</item>
		
		<item>
			<title>A New Year and a New Book Rating Scheme</title>
			<description>
				
				&lt;p&gt;A few days ago I completed my goal of reading 35 books in 2013. I&amp;rsquo;ve logged all the books I&amp;rsquo;ve read for the past three years now (on &lt;a href=&quot;http://goodreads.com/parkermalenke&quot;&gt;Goodreads&lt;/a&gt;), and it&amp;rsquo;s kind of nice to look back at my recent literary history with ease. When I started rating books I didn&amp;rsquo;t really have much of a plan for which books got which ratings. And I felt bad about giving books negative ratings, meaning I rarely gave out one or two stars. This paradigm doesn&amp;rsquo;t have much expressive power, so starting with books I read in 2014 I&amp;rsquo;m going to use a new rating scheme, specified here:&lt;/p&gt;

&lt;p&gt;&amp;#9733;&amp;#9733;&amp;#9733;&amp;#9733;&amp;#9733;&lt;br/&gt;
I absolutely loved the book&amp;mdash;wouldn&amp;rsquo;t change anything about it. There&amp;rsquo;s a good chance I&amp;rsquo;ll recommend these books to most people.&lt;/p&gt;

&lt;p&gt;&amp;#9733;&amp;#9733;&amp;#9733;&amp;#9733;&lt;br/&gt;
A very good book. Stood out as an above average read that I enjoyed a lot. Still, some aspects of the book could use improving before reaching five star status.&lt;/p&gt;

&lt;p&gt;&amp;#9733;&amp;#9733;&amp;#9733;&lt;br/&gt;
Solidly average. No real negatives, but nothing truly outstanding either. Worth spending the time to read, but not necessarily worth re-reading.&lt;/p&gt;

&lt;p&gt;&amp;#9733;&amp;#9733;&lt;br/&gt;
Below average. Some redeeming qualities, but my time would probably have been better spent elsewhere. Might still recommend to others if I felt they could enjoy it more.&lt;/p&gt;

&lt;p&gt;&amp;#9733;&lt;br/&gt;
A bad book. Didn&amp;rsquo;t enjoy it, and didn&amp;rsquo;t really find anything beneficial in it. Wouldn&amp;rsquo;t recommend to others.&lt;/p&gt;

&lt;p&gt;My new rubric doesn&amp;rsquo;t necessarily depend on the re-readability of a book. There are some fantastic books that I would never really plan on re-reading, either because the style of the book doesn&amp;rsquo;t lend itself to that or just because of logistics. (How many times can one read &lt;em&gt;Infinite Jest&lt;/em&gt;?)&lt;/p&gt;

				
			</description>
			<link>http://prkr.me/words/2014/new-year-new-book-rating-scheme/</link>
			<guid>http://prkr.me/words/2014/new-year-new-book-rating-scheme/</guid>
			<pubDate>Thu, 02 Jan 2014 00:00:00 -0700</pubDate>
		</item>
		
		<item>
			<title>Canyonlands NP</title>
			<description>
				
				
				&lt;img src="http://farm6.staticflickr.com/5460/9305555092_e6d5df8755_b.jpg" title="Untitled" /&gt;
				
				&lt;img src="http://farm6.staticflickr.com/5539/9302777931_b13cf8c7b8_b.jpg" title="Untitled" /&gt;
				
				
			</description>
			<link>http://prkr.me/pictures/2013/canyonlands-np/</link>
			<guid>http://prkr.me/pictures/2013/canyonlands-np/</guid>
			<pubDate>Tue, 16 Jul 2013 00:00:00 -0600</pubDate>
		</item>
		
		<item>
			<title>Gene Patents and the Supreme Court</title>
			<description>
				
				&lt;p&gt;The US Supreme Court recently issued a ruling in the case &lt;em&gt;Association of Molecular Pathology v. Myriad Genetics&lt;/em&gt; that addresses the validity of patents on genes, including those on portions of the human genome. This decision determined that naturally occurring genes are products of nature and therefore ineligible for patent protection, but confirmed that cDNA (complementary DNA) can be patented. It&amp;rsquo;s fantastic to see the legal system recognize genes as the natural resources that they are, although the decision should have extended to cDNA as well.&lt;/p&gt;

&lt;p&gt;Typical genes in eukaryotic cells (those that make up complex multicellular organisms like humans) contain two types of sequences termed &lt;em&gt;introns&lt;/em&gt; and &lt;em&gt;exons&lt;/em&gt;. In the process of expressing a gene the intron sections are cut out and the exon components are spliced together producing the final sequence that gets turned into the end product, a protein. The cDNA version of a gene is the same as the version found in a chromosome, just with all the introns removed. So why can corporations patent cDNA and not the regular DNA found in end genome?&lt;/p&gt;

&lt;p&gt;The catch is that cDNA isn&amp;rsquo;t technically a naturally occurring product. In the cell, the processed version of the full gene is actually made out of RNA, a molecule similar to DNA but different in a few key ways. Researchers often make cDNA from isolated RNA, however, using very simple and common procedures because the processed version of a gene is much easier to work with for many standard laboratory experiments.&lt;/p&gt;

&lt;p&gt;At the start of the genomics era it was difficult and expensive to decipher what the sequence for a given gene was, but in the years since the turn of the century the cost has decreased dramatically, even &lt;a href=&quot;http://www.genome.gov/sequencingcosts/&quot;&gt;outpacing Moore&amp;rsquo;s law&lt;/a&gt; over the past few years. The general idea behind patents is to provide an incentive for members of society to undertake an initial outlay in costs that will eventually produce something beneficial to society. What the Supreme Court is communicating with their ruling is that the production of cDNA for certain genes is an activity beneficial to society but which requires a monetary incentive for researchers to undertake that task. This is simply not the case however. The identification of a naturally occurring gene sequence is very easy and inexpensive with modern procedures, and producing a cDNA version of a gene is even easier. Our &lt;a href=&quot;http://en.wikipedia.org/wiki/Copyright_Clause&quot;&gt;constitution specifies&lt;/a&gt; that patents are to be granted &amp;ldquo;to promote the progress of science and useful arts&amp;rdquo;, yet it&amp;rsquo;s not clear why the court believes cDNA patents are necessary for accomplishing this goal.&lt;/p&gt;

&lt;p&gt;The ruling itself contains language that could potentially invalidate cDNA patents. In &lt;a href=&quot;http://www.supremecourt.gov/opinions/12pdf/12-398_1b7d.pdf&quot;&gt;their opinion&lt;/a&gt; the justices &amp;ldquo;hold that genes and the information they encode are not patent eligible…simply because they have been isolated from the surrounding genetic material.&amp;rdquo; The process of producing cDNA is arguably a method of isolating the information encoded by a gene from surrounding genetic material.&lt;/p&gt;

&lt;p&gt;Ultimately, the invalidation of patents on DNA sequences found in the genome is more important than the lifting of intellectual property restrictions on cDNA. The ruling allows genetic screening of the genome (tests which can identify gene variants to help doctors make treatment decisions) without interference from patent holders like Myriad Genetics, who until now could charge licensing fees or prevent companies and researchers from conducting the tests at all. This is an important step forward for the sciences, and it&amp;rsquo;s encouraging to see that this was a unanimous decision amongst the justices. cDNA patents could potentially prove troublesome to researchers investigating patented genes, but perhaps those restrictions will be removed in time as well.&lt;/p&gt;

				
			</description>
			<link>http://prkr.me/words/2013/gene-patents-and-supreme-court/</link>
			<guid>http://prkr.me/words/2013/gene-patents-and-supreme-court/</guid>
			<pubDate>Tue, 25 Jun 2013 00:00:00 -0600</pubDate>
		</item>
		
		<item>
			<title>Ireland</title>
			<description>
				
				
				&lt;img src="http://farm3.staticflickr.com/2805/9033488839_e1e1a57dd0_b.jpg" title="Near the cliffs of Moher" /&gt;
				
				&lt;img src="http://farm6.staticflickr.com/5448/9035699968_f6c7303006_b.jpg" title="Ireland" /&gt;
				
				&lt;img src="http://farm4.staticflickr.com/3668/9033462973_ce6de0b865_b.jpg" title="Kinsale" /&gt;
				
				&lt;img src="http://farm3.staticflickr.com/2860/9033482115_54974cfd47_b.jpg" title="Sunset at an Irish beach" /&gt;
				
				
			</description>
			<link>http://prkr.me/pictures/2013/ireland/</link>
			<guid>http://prkr.me/pictures/2013/ireland/</guid>
			<pubDate>Thu, 13 Jun 2013 00:00:00 -0600</pubDate>
		</item>
		
		<item>
			<title>How To Teach College Students</title>
			<description>
				
				&lt;p&gt;This guide contains my thoughts as a seasoned college student on what makes a teacher good or bad. Nearly forty instructors over three years of college level education have constructed this understanding of educators. Some taught me how to deal with bureaucracy, some taught me how to transcribe slide shows onto lined paper, some taught me a little, some taught me a lot. In my experience, a number of good or bad practices exist which combine to determine the overall quality of a teacher. Hopefully this manifesto of sorts will drive beneficial change in the typical college classroom experience.
Of course, the advice proffered below predominantly reflects my perception of education and does not represent an exhaustive collection of student opinions. I do believe, however, that many students would benefit if teachers put these principles into broader practice. At least my ideas might provoke discussion among teachers and students about efficient transmittance of knowledge.&lt;/p&gt;

&lt;h2&gt;Good Ideas&lt;/h2&gt;

&lt;h3&gt;Transparency&lt;/h3&gt;

&lt;p&gt;Teachers must understand what we as students need to know and then clearly communicate it to us. This applies to the general course material in addition to individual homework assignments and exams. I find it frustrating, if not disrespectful, when teachers fail to clearly delineate what they expect of students. My best experiences with such clarity have come from math classes that were typically organized with a very manageable load of weekly homework, which applied concepts from well articulated lectures, and periodic exams that students entered possessing well-formed notions about the types of problems to expect. Here are the key points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When outside of class we should spend 90 per cent of our time applying concepts we already have a decent grasp of, preferably from prior teaching, and only 10 per cent on understanding the assignment.&lt;/li&gt;
&lt;li&gt;Some professors try to obfuscate their exam expectations by providing students with little to no information about what to expect. I understand the motivation behind this, but failing to produce either past exams or informative study guides only introduces ineffective ambiguity into the studying process. Students have to balance time between many classes, and with only a diffuse idea of what to expect on exams they will likely spend either too much or too little time preparing.&lt;/li&gt;
&lt;li&gt;Use a standard and understandable grading scale for the class. The fewer types of items that go into the final grade the better.&lt;/li&gt;
&lt;li&gt;Students should find all the relevant details for various course components in the syllabus.&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Organization&lt;/h3&gt;

&lt;p&gt;Transparency goes cheek by jowl with organization. A minimal and consistent class structure helps significantly when establishing an accessibly organized (and hence transparent) class structure.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Homework should come at regular, rational intervals; weekly rather than two periods after we finish each chapter.&lt;/li&gt;
&lt;li&gt;Keep notes and slides consolidated. No one likes printing five different documents just to understand one lecture (or the class structure).&lt;/li&gt;
&lt;li&gt;Slides, if used, should have a consistent organization. Think about those who prefer to take notes on blank paper when creating and presenting them.&lt;/li&gt;
&lt;li&gt;Again, we should spend 90 per cent of our effort on learning the material and 10 per cent on accessing it.&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Typography&lt;/h3&gt;

&lt;p&gt;This is a little pet peeve of mine and perhaps less important to creating a good learning experience, but still influential. Good typography competes with good grammar when creating clear and professional communication. You can find several good resources for learning more about this essential subject online. (&lt;a href=&quot;http://www.typographyforlawyers.com/?page_id=1300&quot;&gt;Here&lt;/a&gt;, &lt;a href=&quot;http://www.markboulton.co.uk/journal/comments/five-simple-steps-to-better-typography&quot;&gt;here&lt;/a&gt;, &lt;a href=&quot;http://www.thedesigncubicle.com/2008/12/10-common-typography-mistakes/&quot;&gt;here&lt;/a&gt;, and &lt;a href=&quot;http://www.sitepoint.com/principles-beautiful-typography/&quot;&gt;here&lt;/a&gt;).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Learn how to choose a font (hint: &lt;a href=&quot;http://comicsanscriminal.com/&quot;&gt;not comic sans&lt;/a&gt;) and use it consistently throughout slides and documents.&lt;/li&gt;
&lt;li&gt;Do not use colored, capital, bolded, or underlined words (or some horrible combination thereof) without very good reason.&lt;/li&gt;
&lt;li&gt;Do not use myriad different font sizes. Pick two or three and stick with them.&lt;/li&gt;
&lt;li&gt;The same goes for the number of different fonts.&lt;/li&gt;
&lt;li&gt;Learn to use &lt;a href=&quot;http://www.dummies.com/how-to/content/using-em-dashes-and-en-dashes-properly.html&quot;&gt;em dashes&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;Bad Ideas&lt;/h2&gt;

&lt;h3&gt;Independent Floundering&lt;/h3&gt;

&lt;p&gt;I believe every student should exhibit proficiency at independent learning. It forms an essential part of being a genuine individual. With that said, I am paying you through the nose to facilitate my learning. I expect you to teach me. All too often, however, a teacher’s attempt at encouraging students to learn a topic outside of class results in the pupil simply floundering around online, bouncing back and forth between Yahoo Answers and Wikipedia.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build a launch pad (with lectures or concise but sufficient instructions) that students can base their independent investigations on.&lt;/li&gt;
&lt;li&gt;Provide an accessible method of confirming results that students find (office hours or a scheduled time in lecture to discuss progress on the assignment before turning it in). Trial and error has never been an efficient learning method.&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Entertaining&lt;/h3&gt;

&lt;p&gt;Do not set out to entertain us. College students know an infinitude of ways to keep themselves better entertained than attending class. Your attempts will simply muddle up the concepts and add to the effort students expend on extracting information from class. Focus on teaching your material in a clear, concise, and accessible manner. If some students find themselves enjoying class, so much the better.&lt;/p&gt;

&lt;h3&gt;Severity&lt;/h3&gt;

&lt;p&gt;A college education is rooted on the idea of a contract between the school (professors) and students. We have mutually agreed that the school will provide knowledge and the students will provide money. Besides the simple standards of professionalism and etiquette applicable in any social situation, this is the extent of any obligation students have to professors. Specifically, professors should not impose penalties on behavior they personally and individually disapprove of but which does not impede other students. For example, skipping class, unobtrusively texting, working on the crossword, completing homework from other classes, etc. Of course all these activities may be viewed negatively, but the professor still receives payment, the contract is upheld. Once such activities impinge on the ability of other students to receive instruction action may be undertaken. But setting strict, arcane rules at the outset serves more to create a degree of hostility between students and the teacher.&lt;/p&gt;

&lt;h3&gt;Repetition&lt;/h3&gt;

&lt;p&gt;Some students may need to hear a concept several times in several contexts before comprehending it. Some may simply need a brief reminder of it. Do not treat these two the same.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lectures should form the backbone of a class. Students who quickly grasp the material should be able to learn everything they need from class. Required, basic, information should not be scattered through various learning outlets. Doing so presents an unorganized and opaque challenge.&lt;/li&gt;
&lt;li&gt;Additional veins of teaching should come as optional layers added atop the lecture. Requiring students to complete repetitive reading quizzes, homework, lab reports, online lectures, and recitation quizzes may help some, but it more likely burdens others who would do better spending time on another class they have a harder time grasping.&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Online Anything&lt;/h3&gt;

&lt;p&gt;Digitization of homework or quizzes has never aided students and only added a depressingly high administrative and logistical barrier between their brains and course material.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It shackles students to the distraction machine known as a computer.&lt;/li&gt;
&lt;li&gt;I have yet to see an online homework system that works well in a modern web browser and conforms to standard usability practices. This creates an unnecessary technological hurdle that wastes time and effort.&lt;/li&gt;
&lt;/ul&gt;


				
			</description>
			<link>http://prkr.me/words/2011/how-to-teach-college-students/</link>
			<guid>http://prkr.me/words/2011/how-to-teach-college-students/</guid>
			<pubDate>Mon, 03 Oct 2011 00:00:00 -0600</pubDate>
		</item>
		
		<item>
			<title>Gran Torino Review</title>
			<description>
				
				&lt;div data-picture data-alt=&quot;Gran Torino Movie Poster&quot; data-title=&quot;&quot;&gt;
    &lt;div
    data-src=&quot;http://prkr.me/assets/photos/gtr-poster.jpeg&quot;
    &gt;&lt;/div&gt;

    &lt;div
    data-src=&quot;http://prkr.me/assets/photos/gtr-poster.jpeg&quot;
    data-media=&quot;(min-width: 400px)&quot;
    &gt;&lt;/div&gt;

    &lt;div
    data-src=&quot;http://prkr.me/assets/photos/gtr-poster.jpeg&quot;
    data-media=&quot;(min-width: 800px)&quot;
    &gt;&lt;/div&gt;

    &lt;!-- Fallback content for non-JS browsers. --&gt;
    &lt;noscript&gt;
        &lt;img src=&quot;http://prkr.me/assets/photos/gtr-poster.jpeg&quot; alt=&quot;Gran Torino Movie Poster&quot; title=&quot;&quot;&gt;
    &lt;/noscript&gt;
&lt;/div&gt;


&lt;p&gt;I nearly always have certain expectations when I go to see a movie. Rarely does the movie fit those preconceptions. Sometimes it falls short, sometimes it surpasses. Only once in a great while does a film deliver so far beyond my hopes as Gran Torino did.&lt;/p&gt;

&lt;p&gt;A very complex, but never confusing tale, Clint Eastwood’s performance contains meaningful conversation on manhood, family, race, neighbors, courage, conviction, life, and death. With excellent acting and a beautiful production quality, this film should be on everyone’s list.&lt;/p&gt;

				
			</description>
			<link>http://prkr.me/words/2011/gran-torino-review/</link>
			<guid>http://prkr.me/words/2011/gran-torino-review/</guid>
			<pubDate>Tue, 21 Jun 2011 00:00:00 -0600</pubDate>
		</item>
		

	</channel>
</rss>