<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jason Rowe &#187; General Programming</title>
	<atom:link href="http://jasonrowe.com/category/general-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://jasonrowe.com</link>
	<description>enjoying the web</description>
	<lastBuildDate>Sun, 13 May 2012 14:05:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Right Click Add To Path</title>
		<link>http://jasonrowe.com/2012/04/25/right-click-add-to-path/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=right-click-add-to-path</link>
		<comments>http://jasonrowe.com/2012/04/25/right-click-add-to-path/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 03:03:41 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[General Programming]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1839</guid>
		<description><![CDATA[I do lots of installs on my windows machine and got tired of having to change the path environment variables manually. I created a AddPath.exe that will do this for me and added a short cut to the right click &#8230; <a href="http://jasonrowe.com/2012/04/25/right-click-add-to-path/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<a href="http://jasonrowe.com/wp-content/uploads/2012/04/addpath.png"><img src="http://jasonrowe.com/wp-content/uploads/2012/04/addpath.png" alt="" title="addpath" width="236" height="93" class="alignleft size-full wp-image-1840" /></a>

<p>I do lots of installs on my windows machine and got tired of having to change the path environment variables manually. I created a AddPath.exe that will do this for me and added a short cut to the right click context menu. </p>

<p>In one right click I can get this result:</p>
<a href="http://jasonrowe.com/wp-content/uploads/2012/04/addpathresult.png"><img src="http://jasonrowe.com/wp-content/uploads/2012/04/addpathresult.png" alt="" title="addpathresult" width="355" height="151" class="alignnone size-full wp-image-1878" /></a>



<p>Here is how it works if you are interested:</p>
<ol>
<li>Compile Code Via &#8211; git@github.com:JasonRowe/AddPath.git or <a href="http://jasonrowe.com/misc/AddPath.zip">Download the zip file</a>.</li>
<li>Put the executable (AddPath.exe) and the dependency file (System.dll) into C:\tools\</li>
<li>This executable needs to run as Admin. Right click on AddPath.exe, click compatibility tab and select &#8220;run this program as an administrator&#8221;</li>
</ol>

<p>To add the right click context menu you need to add a new key to the registry</p>

<img src="http://jasonrowe.com/wp-content/uploads/2012/04/AddPathReg1.png" alt="" title="AddPathReg" width="664" height="229" class="alignleft size-full wp-image-1863" />

<ol>
<li>open the registry editor (Start -> Run -> regedit.exe)</li>
<li>Find the key HKEY_CLASSES_ROOT\Folder. Create a new key named shell if its not already there (HKEY_CLASSES_ROOT\Folder\shell)</li>
<li>In the shell key (possibly just created) create a new key and change its name AddPath or whatever you want to show in the context menu</li>
<li>Under the new key create a new key named command (HKEY_CLASSES_ROOT\Folder\shell\AddPath\command) and change its default value C:\tools\AddPath.exe &#8220;%1&#8243;</li>
</ol>

That %1 in quotes becomes the folder path and is passed to AddPath.exe as a parameter. Here is what the code is doing with the path that is passed in:

<pre class="brush: csharp; title: ; notranslate">
 public static void AddPathSegments(Options options)
        {
            try
            {
                string allPaths = Environment.GetEnvironmentVariable(&quot;PATH&quot;, options.Target);
                if (allPaths != null)
                    allPaths = options.PathSegment + &quot;; &quot; + allPaths;
                else
                    allPaths = options.PathSegment;
                Environment.SetEnvironmentVariable(&quot;PATH&quot;, allPaths, options.Target);

                Console.WriteLine(&quot;Added path segment: {0}&quot;, options.PathSegment);
            }
            catch (Exception ex)
            {
                Console.WriteLine(&quot;could not add path segment: {0} -  error {1}&quot;, 
                                   options.PathSegment, ex);
            }
        }
</pre>]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2012/04/25/right-click-add-to-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understand Your Networks Using ThinkUp</title>
		<link>http://jasonrowe.com/2012/04/16/understand-your-networks-using-thinkup/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=understand-your-networks-using-thinkup</link>
		<comments>http://jasonrowe.com/2012/04/16/understand-your-networks-using-thinkup/#comments</comments>
		<pubDate>Tue, 17 Apr 2012 03:18:40 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Commentary]]></category>
		<category><![CDATA[General Programming]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1751</guid>
		<description><![CDATA[I use ThinkUp as a way to archive some of my social network data and get insight on what&#8217;s going on. It comes with plugins to pull data from Google+, Facebook, and Twitter accounts into a MySql database. Once it &#8230; <a href="http://jasonrowe.com/2012/04/16/understand-your-networks-using-thinkup/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I use <a href="http://thinkupapp.com/">ThinkUp </a>as a way to archive some of my social network data and get insight on what&#8217;s going on. It comes with plugins to pull data from Google+, Facebook, and Twitter accounts into a MySql database. Once it is in the database the app slices and dices the data for you or you can analyze it however you want.</p>

<p>My own personal networks aren&#8217;t comprehensive <a href="http://thinkup.jasonrowe.com/" title="thinkup.jasonrowe.com">thinkup.jasonrowe.com</a> but ThinkUp still comes in handy when I can&#8217;t find an old post from Twitter. It also gives you Klout like information on follower counts and interactions. A fun area to look at is the follower categories which are: Most Popular, Dead Beats, and Chatter Box.</p>

<a href="http://jasonrowe.com/wp-content/uploads/2012/04/mpf.png"><img src="http://jasonrowe.com/wp-content/uploads/2012/04/mpf.png" alt="" title="mpf" width="719" height="148" class="alignleft size-full wp-image-1752" /></a>
<br />

<p>Another feature is you can pull in data from Facebook pages you have liked. You don&#8217;t need to have access to the account to pull in the data since it is already public. For example, I started tracking the MarketWatch Facebook page. Now from the ThinkUp interface I can see what stories have the most social engagement.</p>

<a href="http://jasonrowe.com/wp-content/uploads/2012/04/hot_stories.png"><img src="http://jasonrowe.com/wp-content/uploads/2012/04/hot_stories.png" alt="" title="hot_stories" width="728" height="196" class="alignleft size-full wp-image-1768" /></a>
<br />
<p>Huh? Maybe Apple stock is going to get a little cheaper in the next couple of days. :)</p>
<a href="http://jasonrowe.com/wp-content/uploads/2012/04/apple.png"><img src="http://jasonrowe.com/wp-content/uploads/2012/04/apple.png" alt="" title="apple" width="728" height="228" class="alignleft size-full wp-image-1771" /></a>

<br />
<p>Here is an example of one of the nice stats you can get from the ThinkUp web app.</p>

<p><strong>MarketWatch Facebook Likes</strong></p>
<a href="http://jasonrowe.com/wp-content/uploads/2012/04/mwlikes.png"><img src="http://jasonrowe.com/wp-content/uploads/2012/04/mwlikes.png" alt="" title="mwlikes" width="714" height="315" class="alignleft size-full wp-image-1757" /></a>
<br />
<p>With little effort you get a quick way to connect and pull in social network data. Adding more Facebook pages is as easy as liking the page and then clicking the ThinkUp button shown below.</p>

<a href="http://jasonrowe.com/wp-content/uploads/2012/04/page.png"><img src="http://jasonrowe.com/wp-content/uploads/2012/04/page.png" alt="" title="page" width="661" height="133" class="alignleft size-full wp-image-1761" /></a>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2012/04/16/understand-your-networks-using-thinkup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting back into JavaScript</title>
		<link>http://jasonrowe.com/2011/11/02/getting-back-into-javascript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=getting-back-into-javascript</link>
		<comments>http://jasonrowe.com/2011/11/02/getting-back-into-javascript/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 04:17:32 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[General Programming]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[charting]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1498</guid>
		<description><![CDATA[The last time I did any serious JavaScript was around the time Sizzle was added to JQuery, Google Chrome was brand new, and MarketWatch.com started using canvas charts. Note: Here is a quick overview of JavaScript that is as short &#8230; <a href="http://jasonrowe.com/2011/11/02/getting-back-into-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The last time I did any serious JavaScript was around the time Sizzle was added to JQuery, Google Chrome was brand new, and MarketWatch.com started using canvas charts.</p> 

<p><strong>Note:</strong> Here is a quick <a href="http://www.2ality.com/2011/10/javascript-overview.html">overview of JavaScript</a> that is as short as possible, but explains every major feature. I would also recommend following the <a href="http://www.2ality.com/">2ality</a> website</p>

<p>Today JavaScript projects have the complexity, size, and structure of projects written in languages like C# and Java. Thankfully, the developer tools for debugging and logging are solid across browsers. *<i>Opera is still a little funky about logging using &#8220;opera.postError.apply(opera, arguments);&#8221;</i>. Looking particularly good, <a href="http://code.google.com/chrome/devtools/">Google&#8217;s version of the webkit dev tools</a> and some API&#8217;s they have in <a href="http://code.google.com/chrome/extensions/dev/experimental.devtools.html">beta</a>. I’ve started to use <a href="http://docs.jquery.com/QUnit">quint</a> for unit testing. I’ve also been looking leveraging these frameworks: <a href="http://documentcloud.github.com/underscore/">underscore.js</a>, <a href="http://jashkenas.github.com/coffee-script/">coffee script</a>, <a href="http://raphaeljs.com/">raphaeljs</a>, and <a href="http://code.google.com/closure/compiler/">closure compiler</a>.</p> <p>It’s amazing how much has changed. Now <a href="https://developer.mozilla.org/en/JavaScript/Reference">examples of good JavaScript</a> are much easier to find. Hell, here is a step by step walkthrough of how to <a href="http://dailyjs.com/tags.html#lmaf">build your very own JavaScript framework</a>.</p> 

<p>So to get some practice I went and found some JS that needed cleanup. I wanted to focus on structure and namespaces and this <a href="http://www.elated.com/res/File/articles/development/javascript/snazzy-animated-pie-chart-html5-jquery/">script</a> needed some love. View source on that page and you will notice global variables and one big pile of code.</p> <p>The first thing I did was break up the logic into separate functional script files that will later be compiled and minified into one. You can see the python script I use to minify <a href="https://raw.github.com/JasonRowe/SimpleHTML5.Charts/master/build.py">here</a>.</p> 

<ol> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/animation.js">animation.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/builder.js">builder.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/core.js">core.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/pie.js">pie.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/rendering.js">rendering.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/styles.js">styles.js</a></li>
</ol> 

<p>I then added a <a href="https://github.com/JasonRowe/SimpleHTML5.Charts/tree/master/test">test folder</a> and setup the same file names but which had test cases for each script. Then an index.html file to display the test groups or “modules” as they are called in QUnit. Here is an example of a test that always passes</p> 

<pre class="brush: jscript; title: ; notranslate">
module(&quot;sample test&quot;);

test(&quot;a sample qunit test&quot;, function () {
    ok(true, &quot;always fine&quot;);
});

</pre>  

<p>The next thing I worked on was getting a namespace around the code. I went with the following which seems to work for my needs.</p> 

<pre class="brush: jscript; title: ; notranslate">
var SimpleHtml5 = SimpleHtml5 || {};

SimpleHtml5.namespace = function (ns_string) {
    'use strict';
    var parts = ns_string.split('.'), parent = SimpleHtml5, i;
    if (parts[0] === &quot;SimpleHtml5&quot;) {
        parts = parts.slice(1);
    }
    for (i = 0; i &lt; parts.length; i += 1) {
        if (typeof parent[parts[i]] === &quot;undefined&quot;) {
            parent[parts[i]] = {};
        }
        parent = parent[parts[i]];
    }
    return parent;
};

</pre>  

<p>Stefanov, Stoyan (2010). JavaScript Patterns (pp. 89-90). OReilly Media &#8211; A. Kindle Edition. </p>

<p>So after refactoring, I’ve got the pie chart setup code to the following.</p>

<pre class="brush: jscript; title: ; notranslate">
var pieElm = document.getElementById('pieChart');
var pieData = $('#chartData td');

var pieChart = new SimpleHtml5.Core.Pie(pieElm, pieData);

$('#pieChart').click (pieChart, SimpleHtml5.Pie.Animation.HandleChartClick);
</pre>

<p>To customize the style I allow passing in a custom style object to override the defaults.</p>

<pre class="brush: jscript; title: ; notranslate">

var customStyles = {
    chartSizePercent: 49,
    maxPullOutDistance: 10,
    pullOutFrameStep: 4,
    pullOutFrameInterval: 40,
    pullOutLabelPadding: 42
};

var pieElm = document.getElementById('pieChart');
var pieData = $('#chartData td');
var pieChart = new SimpleHtml5.Core.Pie(pieElm, pieData, customStyles);
$('#pieChart').click (pieChart, SimpleHtml5.Pie.Animation.HandleChartClick);
</pre>

<p>
If you are curious about how the other parts of the chart were organized you can see the source code on <a href="https://github.com/JasonRowe/SimpleHTML5.Charts">github</a>.
</p>

<p>

<blockquote>I can also be found on Google+

<a title="Jason Rowe is on Google+" rel="author" href="http://profiles.google.com/jasonrowe?rel=author" alt="Google+" title="Google+">Jason Rowe</a> and twitter <a title="Jason Rowe is on twitter" rel="author" href="http://twitter.com/jsonrow?rel=author" alt="twitter" title="twitter">@jsonrow</a>
</blockquote>


</p>

]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2011/11/02/getting-back-into-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blogging with Google App Engine</title>
		<link>http://jasonrowe.com/2010/10/17/blogging-with-google-app-engine/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=blogging-with-google-app-engine</link>
		<comments>http://jasonrowe.com/2010/10/17/blogging-with-google-app-engine/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 16:33:23 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[General Programming]]></category>
		<category><![CDATA[GAE]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1400</guid>
		<description><![CDATA[&#160; A recent post and talk on twitter about host providers got me interested in building a blog using Google App Engine (GAE). It&#8217;s free to use and would eliminate having to pay for a hosting provider for a small &#8230; <a href="http://jasonrowe.com/2010/10/17/blogging-with-google-app-engine/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p> <p>A recent <a href="http://www.murphybytes.com/2010/09/29/gae-is-better-than-ec2/">post</a> and talk on twitter about host providers got me interested in building a blog using Google App Engine (GAE). It&#8217;s free to use and would eliminate having to pay for a hosting provider for a small site. My blog turned out like this <a href="http://jsoncharts.appspot.com/">jsoncharts</a>. I&#8217;m pretty happy with it so far.

<p>I got started with Python and GAE by reading the documentation and using the examples on the <a href="http://code.google.com/appengine/docs/python/gettingstarted/introduction.html">Google App Engine site</a>. Then I used this <a href="http://brizzled.clapper.org/id/77/">article</a> and framework for the base of my blog. The major changes I made were adding commenting and friendly URL’s. I can have URL’s like this (<a title="http://jsoncharts.appspot.com/blog/force-directed-graph-with-raphael" href="http://jsoncharts.appspot.com/blog/force-directed-graph-with-raphael">http://jsoncharts.appspot.com/blog/force-directed-graph-with-raphael</a>) and comments on the articles (<a title="http://jsoncharts.appspot.com/blog/force-directed-graph-with-raphael#respond" href="http://jsoncharts.appspot.com/blog/force-directed-graph-with-raphael#respond">http://jsoncharts.appspot.com/blog/force-directed-graph-with-raphael#respond</a>). </p> <p>Adding friendly URL’s was easy enough. Following <a href="http://bret.appspot.com/entry/experimenting-google-app-engine">Bret Taylor’s example</a> here is what my WSGIApplication instance looks like.</p> 

<pre class="brush: python; title: ; notranslate"> 
application = webapp.WSGIApplication(
    [('/', FrontPageHandler),
     ('/tag/([^/]+)/*$', ArticlesByTagHandler),
     ('/date/(\d\d\d\d)-(\d\d)/?$', ArticlesForMonthHandler),
     ('/'+ defs.ARTICLE_URL_PATH +'/(\d+)/?$', SingleArticleHandler),
     ('/'+ defs.ARTICLE_URL_PATH +'/([^/]+)', SingleArticleHandlerBySlug),
     ('/archive/?$', ArchivePageHandler),
     ('/rss2/?$', RSSFeedHandler),
     ('/.*$', NotFoundPageHandler),
     ], 
</pre>

<p>The following line routes incoming request to a class handler named “SingleArticleHandlerBySlug”.</p> 

<pre class="brush: python; title: ; notranslate"> 
('/'+ defs.ARTICLE_URL_PATH +'/([^/]+)', SingleArticleHandlerBySlug),
</pre>

<p>The handler looks like this:</p> 

<pre class="brush: python; title: ; notranslate"> 
class SingleArticleHandlerBySlug(AbstractPageHandler):
    &quot;&quot;&quot;
    Handles requests to display a single article, given its unique ID.
    Handles nonexistent IDs.
    &quot;&quot;&quot;
    def get(self, slug):
        article = Article.get_for_slug(slug)
        comments = None
        if article:
            comments = Comment.get_all_by_articleId(article.id)
            template = 'show-single-article.html'
            articles = [article]
            more = None
        else:
            template = 'not-found.html'
            articles = [] 

        self.response.out.write(self.render_articles(articles=articles,
                                                     request=self.request,
                                                     recent=self.get_recent(),
                                                     template_name=template,
                                                     comments=comments)) 
</pre>

<p>To add the commenting I had to create a new model class for storage. This was very simple.</p> 

<pre class="brush: python; title: ; notranslate"> 
class Comment(db.Model): 

    name = db.TextProperty()
    email = db.TextProperty()
    website = db.TextProperty()
    body = db.TextProperty()
    commented_when = db.DateTimeProperty(auto_now_add=True)
    id = db.IntegerProperty()
    articleId = db.IntegerProperty()
    gravatar_url = db.TextProperty() 
</pre>

<p>Then I added a few functions for finding and deleting and then added them in. I can’t remember ever doing something with storage this fast. I don&#8217;t miss SQL at all. GAE really hides all the storage implementation details for you. Here is an example of the functions used to access the data store.</p> 

<pre class="brush: python; title: ; notranslate"> 
@classmethod
def get_all(cls):
    q = db.Query(Comment)
    q.order('-commented_when')
    return q.fetch(FETCH_THEM_ALL)
@classmethod
def get_all_by_articleId(cls, articleId):
    q = db.Query(Comment)
    q.filter('articleId = ', articleId)
    q.order('-commented_when')
    return q.fetch(FETCH_THEM_ALL) 
</pre>

<p>That’s all it takes and you are ready to go.</p> <p>Overall I was very impressed with the experience. In the future I&#8217;ll probably look into using Django&#8217;s form validation framework for comments and figure out how backups would work.</p>

Post Related Links:
<ul>
<li><a href="https://github.com/JasonRowe/picoblog">JsonChart Fork on GitHub</a></li>
<li><a href="https://github.com/bmc/picoblog">PicoBlog on GitHub</a></li>
<li><a href="http://brizzled.clapper.org/id/77/">Writing Blogging Software for Google App Engine</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/10/17/blogging-with-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shiny New Toys, Visitor Pattern, and Real World Functional Programming</title>
		<link>http://jasonrowe.com/2010/09/06/shiny-new-toys-visitor-pattern-and-real-world-functional-programming/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=shiny-new-toys-visitor-pattern-and-real-world-functional-programming</link>
		<comments>http://jasonrowe.com/2010/09/06/shiny-new-toys-visitor-pattern-and-real-world-functional-programming/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 04:21:41 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Commentary]]></category>
		<category><![CDATA[General Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1333</guid>
		<description><![CDATA[&#160; Last week in the office I thought to my self, “Holiday weekend coming! I’ll have time to play with WP7 or maybe I’ll play with HTML5”. Then I saw this tweet on twitter. We as developers spend too much &#8230; <a href="http://jasonrowe.com/2010/09/06/shiny-new-toys-visitor-pattern-and-real-world-functional-programming/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p> <p>Last week in the office I thought to my self, “Holiday weekend coming! I’ll have time to play with WP7 or maybe I’ll play with HTML5”. Then I saw this <a href="http://twitter.com/jeremydmiller/status/22798775378">tweet</a> on twitter.</p> <blockquote> <p>We as developers spend too much time playing with baubles and shiny new tools and not enough time on core skills and fundamentals</p></blockquote> <p>I thought well, instead of using some free time this holiday weekend to build something why not do a little research. I happened to have a problem at work which someone suggested using the Visitor Pattern. So I spent some time looking over a few resources and <a href="http://en.wikipedia.org/wiki/Visitor_pattern">Wikipedia</a> has a great explanation. I won’t try to repeat that. One area I was stuck on though was the concept of double dispatch. I found this <a href="http://bit.ly/bZRM74">example</a> on <a href="http://stackoverflow.com/questions/479923/is-c-a-single-dispatch-or-multiple-dispatch-language">StackOverflow.com</a> which solidified the concept. For some reason <a href="http://bit.ly/bZRM74">learning by spaceship and rebel alliance</a> works for me.</p> <p>So now that I had a good understand all I needed to was implement it right? I thought about it and figured that could wait. Now is an opportunity to work on my fundamentals. The Wikipedia article mentioned Common Lisp and how the Visitor Pattern simplified when using dynamic languages. This got me to thinking what would this look like in F# or a functional language? </p> <p>While looking into functional languages I came across this Stack Overflow question “<a href="http://stackoverflow.com/questions/3642328/i-am-a-c-developer-should-i-start-looking-more-on-f-closed">I am a C# developer, Should I start looking more on F# [closed]</a>”.&nbsp; Jon Skeet’s answer influenced me and I figured I would pick up a book <a href="http://manning.com/petricek">Real World Functional Programming</a>. It fits into the category of fundamentals because it’s using C# and F# to teach functional programming. Which I haven’t used in many years.</p> <p>So I start reading with the goal in mind that I would make a quick example of the visitor pattern in F#. Don’t think I am a super geek (not that you would be confused because of my skills). I did take time to drink a few of <a href="http://www.surlybrewing.com/beer/year-round-beers.html">these</a> and go to the Crowded House concert this weekend. By the fourth chapter or so things started to sink in with F# and functional programming. </p> <p>If I were using a declarative functional style of programming, I wouldn’t even need the visitor pattern at all!&nbsp; I don’t have objects that would need to be separated from the algorithm. I would only have types and could use pattern matching and discriminated unions to perform my algorithm. The visitor pattern is needed in my current project because I’m using an implicit OO coding approach.</p> <p>It was really shocking to me that this wasn’t obvious right away. I’ve been doing OO for so long now I’ve completely become accustomed to dealing with objects and state. A programming world without objects had completely slipped from my mind. Glad I took the time to get started on this book as it’s already giving me new ideas and techniques I can use in my daily C# and OO programming. Now to start working on some of the other <a href="http://www.indiangeek.net/wp-content/uploads/Programmer%20competency%20matrix.htm">programmer competencies</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/09/06/shiny-new-toys-visitor-pattern-and-real-world-functional-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Turing&#8217;s Lambda Notation</title>
		<link>http://jasonrowe.com/2009/09/05/turings-lambda-notation/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=turings-lambda-notation</link>
		<comments>http://jasonrowe.com/2009/09/05/turings-lambda-notation/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 06:50:26 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Commentary]]></category>
		<category><![CDATA[General Programming]]></category>
		<category><![CDATA[Lambda]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=642</guid>
		<description><![CDATA[I&#8217;m still working through Turing&#8217;s paper on Computability and the Turing Machine.  I am at the end and reading the appendix on Alonzo Church&#8217;s equivalent approach using Lambda Calculus.   His work is so familiar to most programmers since we &#8230; <a href="http://jasonrowe.com/2009/09/05/turings-lambda-notation/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[I&#8217;m still working through Turing&#8217;s paper on Computability and the Turing Machine.  I am at the end and reading the appendix on Alonzo Church&#8217;s equivalent approach using Lambda Calculus.   His work is so familiar to most programmers since we use the concepts in C, C++, Java, and C#.   I decided to use C# Lambda syntax to get familiar before reading through the rest of the paper.

<a rel="attachment wp-att-658" href="http://jasonrowe.com/2009/09/05/turings-lambda-notation/lambda_math_syntax-2/"><img class="alignnone size-full wp-image-658" title="lambda_math_syntax" src="http://jasonrowe.com/wp-content/uploads/2009/09/lambda_math_syntax.PNG" alt="lambda_math_syntax" width="537" height="136" /></a>

I started simply and considered how I could make the following expression be represented by M.

<strong>Math.Pow(x, 2.0) + 5 * x + 7</strong>

Most commonly we see it in this form when programming.

<pre class="brush: csharp; title: ; notranslate">

static double F(double x)
{

return Math.Pow(x, 2.0) + 5 * x + 7;

}

</pre>

So convert it to a lambda expression.

<pre class="brush: csharp; title: ; notranslate">

OneV firstExp = x =&gt; Math.Pow(x, 2.0) + 5 * x + 7;

</pre>

where OneV is defined as (not suprisingly)

<pre class="brush: csharp; title: ; notranslate">

delegate double OneV(double x);

</pre>

In C# the two variable syntax could be something like this:

<pre class="brush: csharp; title: ; notranslate">

TwoV Exp = (x, y) =&gt; Math.Pow(y, 2.0) + 5 * y + 18 * x + 2 * x * y + 7;

</pre>

So thats how I got my head around the very basic syntax.]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2009/09/05/turings-lambda-notation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Intro to Propositional Logic Using C#</title>
		<link>http://jasonrowe.com/2009/08/28/intro-to-propositional-logic-using-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=intro-to-propositional-logic-using-c</link>
		<comments>http://jasonrowe.com/2009/08/28/intro-to-propositional-logic-using-c/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 03:18:20 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[General Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Propositional Logic]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=628</guid>
		<description><![CDATA[I&#8217;ve been reading about propositional (or sentential) logic in the book &#8220;The Annotated Turing&#8221;. I put together a quick console app to write out truth tables. It helped me get the hang of the mathematical notation &#8220;v&#8221;, &#8220;&#038;&#8221;, and &#8220;->&#8221;. &#8230; <a href="http://jasonrowe.com/2009/08/28/intro-to-propositional-logic-using-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[I&#8217;ve been reading about propositional (or sentential) logic in the book &#8220;The Annotated Turing&#8221;.  I put together a quick console app to write out truth tables. It helped me get the hang of the mathematical notation &#8220;v&#8221;, &#8220;&#038;&#8221;, and &#8220;->&#8221;. In C# those would be ||, &#038;&#038;, and !x || y respectively. I hope someone else finds it useful.

<pre class="brush: csharp; title: ; notranslate">
using System;
using System.Collections.Generic;

namespace PropositionalLogic
{
    public class Program
    {
        public class truthvalue
        {
            public bool X { get; set; }
            public bool Y { get; set; }
        }

        public static bool XorY(bool x, bool y)
        {
            return (x || y);
        }

        public static bool XandY(bool x, bool y)
        {
            return (x &amp;&amp; y);
        }

        public static bool Exclusive(bool x, bool y)
        {
            return (x &amp;&amp; y) &amp;&amp; !(x &amp;&amp; y);// always false
        }

        public static bool Tautoloty(bool x, bool y)
        {
            return x || y || (!x &amp;&amp; !y);// always true
        }

        public static bool Contradition(bool x, bool y)
        {
            return x || (y &amp;&amp; !y);
        }

        public static bool MaterialImplication(bool x, bool y)
        {
            return !x || y; 
            //this can also be expressed as the following conjunction !(x &amp;&amp; !y);
        }

        public static bool BiConditional(bool x, bool y)
        {
            return MaterialImplication(x, y) &amp;&amp; MaterialImplication(y, x); //&quot;if and only if&quot;
        }

        static void Main(string[] args)
        {
            var truthTable = new List&lt;truthvalue&gt;
                                 {
                                     new truthvalue() {X = false, Y = false},
                                     new truthvalue() {X = false, Y = true},
                                     new truthvalue() {X = true, Y = false},
                                     new truthvalue() {X = true, Y = true}
                                 };

            var sentences = new Dictionary&lt;string , Func&lt;bool, bool, bool&gt;&gt;
                                {
                                    {&quot;X v Y&quot;, XorY},
                                    {&quot;X &amp; Y&quot;, XandY},
                                    {&quot;(x v y)&amp; -(x &amp; y)&quot;, Exclusive},
                                    {&quot;x v y v (-x &amp; -y)&quot;, Tautoloty},
                                    {&quot;x -&gt; y&quot;, MaterialImplication},
                                    {&quot;x ~ y&quot;, BiConditional}
                                };

            CalculateTruthTable(truthTable, sentences);

            Console.ReadLine();
        }

        private static void CalculateTruthTable(IEnumerable&lt;truthvalue&gt; truthTable, 
Dictionary&lt;string , Func&lt;bool, bool, bool&gt;&gt; sentences)
        {
            foreach (var sentence in sentences)
            {
                Console.WriteLine(&quot;&quot;);
                Console.WriteLine(&quot;|X      |Y      |{0}  |&quot;, sentence.Key);

                foreach (var value in truthTable)
                {
                    var x = value.X;
                    var y = value.Y;

                    var result = sentence.Value(x, y);

                    Console.WriteLine(&quot;|{0}  |{1}  |{2}  |&quot;, PrettyPrint(x), PrettyPrint(y), 
                                       PrettyPrint(result));
                }
            }
        }

        private static string PrettyPrint(bool input)
        {
            return input ? input + &quot; &quot; : input.ToString();
        }
    }
}
</pre>]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2009/08/28/intro-to-propositional-logic-using-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

