<?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>lunaru.com &#187; Programming</title>
	<atom:link href="http://www.lunaru.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lunaru.com</link>
	<description>Thoughts on Development</description>
	<lastBuildDate>Wed, 13 Jul 2011 05:54:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Teasing out great development concepts from Rails</title>
		<link>http://www.lunaru.com/2008/03/teasing-out-great-development-concepts-from-rails/</link>
		<comments>http://www.lunaru.com/2008/03/teasing-out-great-development-concepts-from-rails/#comments</comments>
		<pubDate>Sun, 16 Mar 2008 23:29:14 +0000</pubDate>
		<dc:creator>Lu Wang</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.lunaru.com/2008/03/16/teasing-out-great-development-concepts-from-rails/</guid>
		<description><![CDATA[When DHH teased out Rails from the Basecamp source, the process was described as &#8220;experience-based design&#8221; &#8211; meaning that everything Rails provided from day one was born from the need to solve common development headaches met by everyday developers working on everyday development projects. The idea was to extract the largest common denominator of all [...]]]></description>
			<content:encoded><![CDATA[<p>When DHH teased out Rails from the Basecamp source, the process was described as &#8220;experience-based design&#8221; &#8211; meaning that everything Rails provided from day one was born from the need to solve common development headaches met by everyday developers working on everyday development projects. The idea was to extract the largest common denominator of all common projects and throw them into one prescriptive framework.</p>
<p>The funny thing about that is, this particular cuddliness of Rails has seemed to split the Rails camp into two groups of people. Yes I know, generalization is bad, but it&#8217;s convenient. In one corner, we have the hardcore developers who know the entire framework inside and out. These are the ones that can break Rails down into it&#8217;s actual and somewhat separable components. They know and understand how ActiveRecord (M) is separate from ActionPack (VC), which is separate from ActionMailer, which is separate from ActiveSupport, etc. They see both the forest and the individual trees that make the forest possible. The other corner of developers couldn&#8217;t care less. They&#8217;re using Rails as an all-in-one packaged deal. Like (some of) the old MFC developers of yore, they couldn&#8217;t tell how things work under the hood, they just care that it does.</p>
<p>Having said all that, in the spirit of &#8220;experienced-based&#8221; teasing out of great ideas, I think Rails has gotten to the point where it&#8217;s interesting to take a look at some of the concepts from which it is comprised and acknowledge them each individually. It&#8217;s time to not just look at the largest common denominator, but each reasonably sized denominator as well. I&#8217;ll skip the obvious cookie-cutter cliche ones like MVC and ActiveRecord. I&#8217;m going for the more underrated things.</p>
<p>Granted, I haven&#8217;t put much thought into this. This post is just a result of me thinking: &#8220;These ideas would and should work anywhere and everywhere&#8221;. Here&#8217;s my top 5:</p>
<p>5) Unit-testing and testing in general. I guess this falls under &#8220;cliche&#8221;, but the fact that Rails comes with testing ready out of the box speaks worlds of how important it is to all software projects. This is a should have/must have for any project</p>
<p>4) Mongrel (included in Rails 2.x I believe). It&#8217;s not this particular piece of software that I like, it&#8217;s what it represents. It screams &#8220;acknowledge your entire stack&#8221;. Mongrel was written to address the specific performance issues with Rails apps, but every project should have its Mongrel &#8211; its underlying engine that makes it run and run fast.</p>
<p>3) DB Abstraction/Migrations. MySQL, Oracle, SQLite, PostgreSQL, WhoTheHellCaresSQL. They should all be made to behave the same. Yes, I run SQLite on development and test, but MySQL on production. As long as I keep in mind the performance characteristics (see #4), who cares which DB is running?</p>
<p>2) Development, Test, and Production environments. Every project has some variation of these three environments. Every project should formalize that fact! Make it configurable in a YAML file! The fact that Rails comes with this out of the box makes development so, so easy.</p>
<p>1) Documentation. &#8216;Nuff said. If you don&#8217;t document it, it never happened.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lunaru.com/2008/03/teasing-out-great-development-concepts-from-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It&#8217;s not so much an Object. It&#8217;s a Type.</title>
		<link>http://www.lunaru.com/2007/09/its-not-so-much-an-object-its-a-type/</link>
		<comments>http://www.lunaru.com/2007/09/its-not-so-much-an-object-its-a-type/#comments</comments>
		<pubDate>Tue, 25 Sep 2007 05:51:57 +0000</pubDate>
		<dc:creator>Lu Wang</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.lunaru.com/2007/09/24/its-not-so-much-an-object-its-a-type/</guid>
		<description><![CDATA[If you ever sit down to wonder why object-oriented programming is the dominant paradigm in software design, you might have also wondered whether there were any alternatives. That is, not alternatives as in that which is theoretically possible (because there are many), but alternatives that offer the elegance of OOP in a pragmatic sense. The [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever sit down to wonder why object-oriented programming is the dominant paradigm in software design, you might have also wondered whether there were any alternatives. That is, not alternatives as in that which is theoretically possible (because there are many), but alternatives that offer the elegance of OOP in a pragmatic sense. The simple argument is that computer science, and thus programming, revolves around data structures, and an object is a natural way to think about data structures in an actionable way. We can build our applications by reasoning about the data that the application works with, and that trend lends itself well to things like objects where they seem to be a natural extension of the same idea.</p>
<p>While I am quite happy to leave it at that in describing OOP to novices, that explanation itself never suffices for me. The above explanation does not explain interfaces, abstract classes, and class hierarchies. The explanation leaves no room to think about proper design of interfaces, object relationships, and above-all, separation of concerns, which are all fundamental concepts in OOP.</p>
<p>In truth, I believe the answer lies in the fact that we&#8217;re not so attached to Objects as we are to Types. For example, if we take time to the most basic of expressions, like:</p>
<p><code> x * y </code></p>
<p>We might infer that we are working with integer or float types. In fact, this is basic <a href="http://en.wikipedia.org/wiki/Type_inference">type inference</a> operating in the human brain. However, taking an expression like:</p>
<p><code>"Hello" * "World"</code></p>
<p>We might be much less inclined to give a proper explanation for what this might do. This is because we understand string types don&#8217;t naturally implement multiplication.</p>
<p>From the most basic examples like this, we come to understand that we don&#8217;t rely on values so much as we rely on behavorial contracts. Even at the most basic primitive types, we understand the types that implement &#8216;+&#8217; and the types that implement &#8216;*&#8217;. Extending this to the higher level objects, we come across the most elegant way to describe our logic in programming statements.</p>
<p>By thinking about types, from the simplest Printers to design-pattern favorites like Factories, we can reason about our code in a way that lends itself well to implicit understanding. We can also reason about our code not necessarily from the point of view of the object (which is just an instance, just a &#8220;value&#8221;) but the interface for which that object implements. And because we reason about interfaces, we are really reasoning about complex types &#8211; a concept that is much more universal and broad than objects.</p>
<p>So really, when we talk about object-oriented programming, we&#8217;re basically presenting a misnomer for type-oriented programming, which is a much stronger and older concept than objects. While this explanation might seem trivial to those not necessarily curious about the details, to me, it helps classify and generalize concepts which may seem to be pure convenience (Objects) to concepts that are more universal (Types).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lunaru.com/2007/09/its-not-so-much-an-object-its-a-type/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating to Apache2 for Mac OS X Tiger (Apache 1.3)</title>
		<link>http://www.lunaru.com/2007/07/updating-to-apache2-for-mac-os-x-tiger-apache-1-3/</link>
		<comments>http://www.lunaru.com/2007/07/updating-to-apache2-for-mac-os-x-tiger-apache-1-3/#comments</comments>
		<pubDate>Mon, 23 Jul 2007 19:03:42 +0000</pubDate>
		<dc:creator>Lu Wang</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.lunaru.com/2007/07/23/updating-to-apache2-for-mac-os-x-tiger-apache-13/</guid>
		<description><![CDATA[This past weekend, I wanted to update the built-in Apache 1.3 (Darwin) build with a more recent Apache 2.2.4, all while preserving the Mac OS X&#8217;s Personal Web Sharing capabilities transparently. Here are the simple steps:

Download the latest apache src from http://www.apache.org. In my case it was version 2.2.4
Extract the src to a directory where [...]]]></description>
			<content:encoded><![CDATA[<p>This past weekend, I wanted to update the built-in Apache 1.3 (Darwin) build with a more recent Apache 2.2.4, all while preserving the Mac OS X&#8217;s Personal Web Sharing capabilities transparently. Here are the simple steps:</p>
<ul>
<li>Download the latest apache src from http://www.apache.org. In my case it was version 2.2.4</li>
<li>Extract the src to a directory where you keep all your src files, cd to that directory</li>
</ul>
<p><code>./configure –prefix=/usr/local/apache2 –enable-so –enable-mods-shared=most<br />
make<br />
make install</code></p>
<ul>
<li>Replace /usr/local/apache2 with the directory you&#8217;d like apache to be installed in. I named mine apache2. The above command will build apache2.</li>
</ul>
<p><code> cd /usr/sbin<br />
sudo mv httpd httpd.apache1.back<br />
sudo ln –s /usr/local/apache/bin/httpd httpd<br />
sudo mv apxs apxs.apache1.back<br />
sudo ln –s /usr/local/apache/bin/apxs apxs<br />
sudo mv apachectl apachectl.apache1.back<br />
sudo ln –s /usr/local/apache/bin/apachectl apachectl</code></p>
<ul>
<li>httpd (the binary for apache) version 1.3 is installed in /usr/sbin/. You can see the version by typing &#8220;httpd -v&#8221; in the command line. Replace this (after backing it up) with a symlink to our new apache2 httpd binary. This should also be done for apachectl and apxs.</li>
<li>At this point. apache2 is already running on your system, but the conf files are not quite ready. Add the following to your httpd.conf (found under /usr/local/apache2/conf). The PidFile is where the Personal Web Sharing manager looks to see if an apache instance is running.</li>
</ul>
<p><code> PidFile "/private/var/run/httpd.pid" </code></p>
<ul>
<li>You should also add the following to enable user directories.</li>
</ul>
<p><code> &lt;IfModule mod_userdir.c&gt;<br />
UserDir Sites<br />
&lt;/IfModule&gt;<br />
Include /private/etc/httpd/users/*.conf</code></p>
<ul>
<li>At this point, you are all set. Try toggling the Personal Web Sharing on and off. The next steps you might want to take (optionally) is to add MultiView support and change your DocumentRoot. These can all be done in the httpd.conf file. You might also want to uncomment the line that includes support for http://localhost/manual/</li>
<li>You can also find the previous 1.3 conf file at /private/etc/httpd. Notice how much more verbose this conf file is compared to the apache2 conf file. This is because most of the additional conf settings can be includes via conf/extra directory.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.lunaru.com/2007/07/updating-to-apache2-for-mac-os-x-tiger-apache-1-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working in Binary</title>
		<link>http://www.lunaru.com/2007/04/working-in-binary/</link>
		<comments>http://www.lunaru.com/2007/04/working-in-binary/#comments</comments>
		<pubDate>Sun, 22 Apr 2007 22:57:33 +0000</pubDate>
		<dc:creator>Lu Wang</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.lunaru.com/2007/04/22/working-in-binary/</guid>
		<description><![CDATA[I&#8217;ve been trying to implement a web-client for a server (implemented in C/C++) that has to deal with a lot of encrypting and decrypting of data with Rijndael/AES. Obviously, the weapon of choice for the web-end is javascript (and a little bit of Flash XMLSockets via Aflax).
Unfortunately, another requirement is that the client must deal [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been trying to implement a web-client for a server (implemented in C/C++) that has to deal with a lot of encrypting and decrypting of data with <a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard">Rijndael/AES</a>. Obviously, the weapon of choice for the web-end is javascript (and a little bit of Flash XMLSockets via <a href="http://www.aflax.org/">Aflax</a>).</p>
<p>Unfortunately, another requirement is that the client must deal with Unicode perfectly. After all, in today&#8217;s international world, it&#8217;s just plain wrong to implement anything with purely 8-bit ASCII in mind. Specifically, in this implementation, the plaintext is encoded in utf-8, then encrypted in AES, followed by an encoding to base64. The web client is of course then responsible for receiving that base64 blob out of the XMLSocket and attempt to display the original plaintext properly.</p>
<p>It sounds easy enough, but the shopping for various open source parts took me longer than expected. In light of that, I&#8217;ve decided to document the various implementations I found useful.</p>
<p>The first step is to take that base64 blob and convert it to something useful. In C, we&#8217;d want to tear it down to 8-bit bytes in order to feed it to our AES implementation. Unfortunately, in JavaScript the notion of a byte is &#8220;nicely&#8221; abstracted away, so we&#8217;ll have to deal with strings.  Using webtoolkits <a href="http://www.webtoolkit.info/javascript-base64.html">Base64</a> and <a href="http://www.webtoolkit.info/javascript-utf8.html">Utf8</a> implementations, we can convert the blob to a garbled ASCII string. (i.e. 5Lit5paH -> 中文 -> [some unreadable 6-byte string] ). We can then feed this string into <a href="http://www-cse.ucsd.edu/~fritz/rijndael.html">this Rijndael implementation</a>. We&#8217;re now left with another string, which we can decode to JavaScripts internal Unicode representation. Voila!</p>
<p>The key to the particular Rijndael implementation I&#8217;ve chosen is that it has a well documented approach to dealing with bytes in JavaScript. In particular, it converts any ASCII string to its byte representation as an array of integers (i.e. &#8220;Hello&#8221; -> [104, 101, 108, 108, 111]) and then operates on those &#8220;bytes&#8221; following the AES algorithm. While this is slow, it is clearer than other implementations I&#8217;ve found.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lunaru.com/2007/04/working-in-binary/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Technology Soup</title>
		<link>http://www.lunaru.com/2007/02/technology-soup/</link>
		<comments>http://www.lunaru.com/2007/02/technology-soup/#comments</comments>
		<pubDate>Fri, 09 Feb 2007 08:03:31 +0000</pubDate>
		<dc:creator>Lu Wang</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.lunaru.com/2007/02/09/technology-soup/</guid>
		<description><![CDATA[As a wise man once told me, &#8220;the advancement of computer science can be measured in levels of abstraction.&#8221; Okay, I lied, no wise man ever told me anything like this, although it&#8217;s not far-fetched and not too hard to believe.
Now that I am done fibbing, I&#8217;ll jump straight to my beef. The problem with [...]]]></description>
			<content:encoded><![CDATA[<p>As a wise man once told me, &#8220;the advancement of computer science can be measured in levels of abstraction.&#8221; Okay, I lied, no wise man ever told me anything like this, although it&#8217;s not far-fetched and not too hard to believe.</p>
<p>Now that I am done fibbing, I&#8217;ll jump straight to my beef. The problem with abstractions is that they naturally take a multitude of forms, because not everyone can agree on how to abstract away simple mechanisms into higher level concepts. What usually ends up happening is as the levels of abstraction stack higher, the path to a simple task becomes simpler, but we lose sight of the overall picture.</p>
<p>If I take the first level of abstraction as assembly code/machine code, which abstracts away physical CPU instructions into some binary representation, I can argue that this first level of abstraction is as simple as anyone will ever get. It&#8217;s just add, subtract, multiple, and maybe a divide here and there. Add in some reads and writes and you&#8217;ve got yourself the basic LEGOs of every modern day system.</p>
<p>Our problems start here. The next logical progression is to complain that we need higher order constructs to be more expressive and more elegant in our approach to problems. This gives rise to higher level languages like C. Our complaints continue until we finally reach the pinnacle of general expressiveness, a strongly-typed, polymorphic, object-oriented, virtualized language (like Java) having lost all direct connection to those loveable adds, subtracts, multiplies, and divides.</p>
<p>Next we grow unhappy with how the general approach has become so &#8230; general&#8230; so we develop languages made for specific tasks. Out pops the glut of scripting languages, PHP, PERL, Ruby, JavaScript, VBScript, Python, and [insert your language du jour here]. We live with this lack of generality because we say things like, &#8220;Oh, but PHP makes it easier for you to do [Task A] and, oh, PERL is so much easier for [Task B],&#8221; all while sounding totally knowledgeable.</p>
<p>Don&#8217;t get me wrong. I like choices, but sometimes I think there is just too much emphasis placed on being &#8220;politically correct&#8221; in choosing the weapons of war.</p>
<p>Exhibit A. I&#8217;m building a web site to track financial portfolios in real time. This project entails (from back to front) interacting with several web services exposing interfaces via WSDL/SOAP then wrapping that functionality along with some peripheral necessities into another WSDL web service that manages entire portfolios made up of sets of stock symbols. Next this web service must have a client that can translate and expose these features as an HTTP service. The HTTP/HTML documents generated are then rendered in the end-user&#8217;s browser where we would like to have all the snazzy web 2.0 goodies to provide a GUI. That&#8217;s the at-a-glance high-bit description of the problem.</p>
<p>Now let&#8217;s count the alphabets in our soup (again from back to front). We&#8217;ve got WSDL, so I&#8217;ll choose to use a specific implementation of XQuery (mxquery by Donald Kossman et al.) to query the web services of interest, process the XML, and spit out more functionality in the web service extensions provided by mxquery. So far I feel good because I&#8217;ve tackled a 2 front problem using 1 (non-standard) technology. Next I need a SOAP client, since browsers don&#8217;t have direct SOAP functionality. I&#8217;ll choose PHP to do this for me since, again, I tackle two fronts with one language &#8211; SOAPClient on one end of PHP and bad-ass HTTP functionality on the other end. Afterall, PHP is the Hypertext Preprocessor. Next we need to 2.0 goodness so we&#8217;ve got to have AJAX running, making HTTP GET/POST requests to my PHP. Lastly, we&#8217;ll need CSS to make sure this whole ordeal doesn&#8217;t look like something from circa 1990.</p>
<p>Depending on how you count, you&#8217;ll get a total of 4 to 6 technologies/concepts in that quick little sketch. Although it might seem like it while reading through that grocery list of implementation decisions, the choices for what technologies and languages to utilize at what step are not easy decisions. Remember, you want to be able to say, &#8220;X makes Y easy to do.&#8221;</p>
<p>The problem? That was great and all for an individual project at such a small scale, but imagine having to build companies on these evolving technologies. You want to stay nibble, so you want to utilize all the newest technologies. &#8220;X makes Y easy to do.&#8221; But, you also want to have a go-to move that you can hang your hat on, because, frankly, the only way you&#8217;ll ever be flexible enough to utilize the perfect technology X to solve Y in the real world is if you churn through employees at a high rate. This doesn&#8217;t sound like a good solution.</p>
<p>Speaking of XQuery, it officially became a W3C recommendation less than 3 weeks ago. I don&#8217;t want to pick on XQuery, because I honestly love some of the decisions they made with the specification &#8211; it&#8217;s almost as flawless as a commitee decision can be, but it is fresh on my mind, and it was what brought up my angst. XQuery, like all computer science, is an abstraction. It&#8217;s an abstraction built to handle the very specific task of wrangling the wild world of XML and taming it in elegance. PHP was an abstraction, an abstraction to wrestle and tackle the evolving problems in an evolving world of HTTP. JavaScript was an abstraction, likewise, to provide the richness to the browser. See where I am going?</p>
<p>No? Okay. Well, I never was a convincing person. The problem here is that these technologies are here to provide the layer of abstraction that is the essence of progress in this field. However, in doing so at such specific means, they diffract our efforts to generalize lower level problems into higher level solutions. Because as we tackle the problems we want to solve, we inevitably take on a whole host of specific solutions and are forced to piece them together. As I said before, this is essentially correct and great. Who doesn&#8217;t like to have rectangular LEGOs to make walls and square LEGOs to make floors? The problem arises when you&#8217;ve got a work force thats used to using square LEGOs all their lives and are now looking at rectangular LEGOs in that odd manner. Don&#8217;t believe me? Try talking to SQL folks about XQuery.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lunaru.com/2007/02/technology-soup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

