<?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"
	>

<channel>
	<title>unitstep.net &#187; programming</title>
	<atom:link href="http://unitstep.net/blog/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://unitstep.net</link>
	<description>the home of peter chng</description>
	<pubDate>Sun, 05 Oct 2008 17:42:16 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>Decoding Google Maps Encoded Polylines using PHP</title>
		<link>http://unitstep.net/blog/2008/08/02/decoding-google-maps-encoded-polylines-using-php/</link>
		<comments>http://unitstep.net/blog/2008/08/02/decoding-google-maps-encoded-polylines-using-php/#comments</comments>
		<pubDate>Sat, 02 Aug 2008 20:32:39 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[development]]></category>

		<category><![CDATA[google]]></category>

		<category><![CDATA[maps]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[polylines]]></category>

		<guid isPermaLink="false">http://unitstep.net/?p=361</guid>
		<description><![CDATA[I&#8217;ve talked about the Google Maps encoded polyline format before. While there&#8217;s some nice utilities for encoding polylines that take the work out of implementing it yourself, I couldn&#8217;t find many polyline decoders.  
This made it somewhat tedious to decode them, as the only way to get the original list of points was to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve talked about the <a href="http://code.google.com/apis/maps/documentation/polylinealgorithm.html">Google Maps encoded polyline format</a> <a href="/blog/2008/05/11/playing-with-google-maps-and-encoded-polylines/">before</a>. While there&#8217;s some nice utilities for <a href="http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/">encoding polylines</a> that take the work out of implementing it yourself, I couldn&#8217;t find many polyline <em>decoders</em>.  </p>
<p>This made it somewhat tedious to decode them, as the only way to get the original list of points was to create a <a href="http://code.google.com/apis/maps/documentation/overlays.html#Encoded_Polylines"><code>GPolyline</code></a> and then pull out the points from that object.  This is not ideal since the work must always be done on the client side with JavaScript and using Google Maps.</p>
<p>To solve this, I quickly ported the algorithm over to <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> from the JavaScript source.  Please feel free to download/modify/use this script.</p>
<div class="download">
<a class="icon" href="http://unitstep.net/wordpress/wp-content/uploads/2008/08/decodepolylinetoarray.zip">Google Maps Polyline Decoder in <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym></a>
</div>
<p>Since the encoded polyline format offers numerous benefits (and because I had data already stored in this format) I did not want to move away from it. At the same time, I needed access to the points for working with things like <a href="http://code.google.com/apis/maps/documentation/staticmaps/">Google Static Maps</a>, which curiously does not accept the encoded polyline format for displaying paths. (Probably to reduce resource usage on their end, since decoding takes CPU time)</p>
<p>Thankfully the polyline decoding algorithm was <a href="http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/decode.js">already available</a> at Mark McClure&#8217;s site.  I spent a few minutes understanding the process and porting it over to <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym>.  The source is attached above and is released under an MIT license.  Basically, the only change I had to make was to use some <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> functions to convert characters to their ASCII code, since <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> doesn&#8217;t have a <code>charCodeAt()</code> function.</p>
<p>Please let me know if you find it to be useful.</p>
<hr/>Copyright &copy; 2008 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2008/08/02/decoding-google-maps-encoded-polylines-using-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The importance of Draconian validation for method parameters</title>
		<link>http://unitstep.net/blog/2008/05/15/the-importance-of-draconian-validation-for-method-parameters/</link>
		<comments>http://unitstep.net/blog/2008/05/15/the-importance-of-draconian-validation-for-method-parameters/#comments</comments>
		<pubDate>Fri, 16 May 2008 01:55:17 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[development]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[testing]]></category>

		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://unitstep.net/?p=326</guid>
		<description><![CDATA[I recently ran into a problem where the callers of one of my methods was using it improperly by suppling a parameter that did not conform to the required values.  However, the problems did not surface until I changed the implementation; previously, things worked by chance due to an implementation detail.
I had been using [...]]]></description>
			<content:encoded><![CDATA[<p>I recently ran into a problem where the callers of one of my methods was using it improperly by suppling a parameter that did not conform to the required values.  However, the problems did not surface until I changed the implementation; previously, things worked <em>by chance</em> due to an implementation detail.</p>
<p>I had been using input validation, but my validation procedure was not stringent enough to detect the improper parameter.  This was tied to the fact that before the implementation change, things worked perfectly fine even with the improper inputs.  However, the implementation change &#8220;broke&#8221; this work flow.  All of this has led me to believe in the great importance of:</p>
<ol>
<li>Draconian validation: For inputs, only accept what you say you will accept.  Nothing else should pass.</li>
<li>Proper unit testing: Test your method with a variety of inputs, both expected and unexpected or non-conforming.  You never know what callers will pass into your methods.</li>
</ol>
<p>Let me go into some more detail.</p>
<h3>Unintended consequences</h3>
<p>I had written a method that would accept a FQDN (Fully-Qualified Domain Name) as its argument.  The purpose of this method was to retrieve some information over HTTPs from the web server running on the server with the specified domain.  Since domain names are protocol-neutral (i.e. they aren&#8217;t preceded by something like &#8220;http://&#8221;), I ended up forming a <code><acronym class="uttInitialism" title="Uniform Resource Locator">URL</acronym></code> object based on the FQDN, since eventually I&#8217;d be retrieving information over HTTPs anyways:</p>
<pre><code>final <acronym class="uttInitialism" title="Uniform Resource Locator">URL</acronym> url = new <acronym class="uttInitialism" title="Uniform Resource Locator">URL</acronym>("https://" + fqdn + "/path_to_service");</code></pre>
<p>I figured that this was enough protection in terms of input validation, since the constructor for <code><acronym class="uttInitialism" title="Uniform Resource Locator">URL</acronym></code> throws a <a href="http://java.sun.com/javase/6/docs/api/java/net/URL.html#URL(java.lang.String)"><code>MalformedURLException </code></a> if something goes wrong.  (There was other code to check if the web server at the specified <acronym class="uttInitialism" title="Uniform Resource Locator">URL</acronym> could actually be contacted and this was contained in the actual retrieval)</p>
<p>However, it turned out that callers had started using this method by passing in not just an FQDN, but an FQDN followed by a port number in the following format: host.name:portNumber.  This was being used so that servers operating on non-default HTTPs ports could be contacted.</p>
<p>Initially, this worked, as then the statement above was executed with something like this:</p>
<pre><code>// With fqdn == "some.host.name:portNumber", nothing fails.
final <acronym class="uttInitialism" title="Uniform Resource Locator">URL</acronym> url = new <acronym class="uttInitialism" title="Uniform Resource Locator">URL</acronym>("https://" + fqdn + "/path_to_service");</code></pre>
<p>This was because the <acronym class="uttInitialism" title="Uniform Resource Locator">URL</acronym> formed was still valid.  However, this was an invalid use of my method because we had never specified that this sort of input was allowed.  It just <em>happened</em> to work.  The issue of non-default HTTPs ports and the usage here was never discussed and because it seemingly worked, nothing was done about it.</p>
<h3>Changing times</h3>
<p>Some time went on until I decided to make an implementation change.  Instead of retrieving the information from the web server itself, I would instead retrieve it directly from the TLS handshake process using a API provided to me.  (The information was related to the certificates)</p>
<p>This API accepted two parameters: The server host name or FQDN, and a separate port number.  Not realizing that callers were passing in non-default port numbers in the first place, I ignorantly just passed the FQDN supplied to me into this API along with the default HTTPs port. (443)</p>
<p>As expected, this broke the functionality that callers had come to expect of my API, namely, custom HTTPs ports specified alongside the FQDN in the argument.  It was only after these complaints were filed that I realized my API was expected to take not just the FQDN, but something like &#8220;server.host.name:8080&#8243;.</p>
<h3>The causes</h3>
<p>The problem was quickly fixed as the solution was fairly trivial, but the causes have taught me several lessons.</p>
<ol>
<li>
<h4>Be Draconian in your input validation</h4>
<p>Or, don&#8217;t trust your callers to read your documentation.  Initially, I thought my method was to accept only an FQDN.  Even though I was wrong in this respect, the problem could&#8217;ve been identified earlier if I had coded my method to fail (i.e. throw an exception) if anything that <strong>was not</strong> an FQDN was passed in.  (Simply forming a <code><acronym class="uttInitialism" title="Uniform Resource Locator">URL</acronym></code> object around it was not stringent enough) This way, things wouldn&#8217;t have initially worked by coincidence and I would&#8217;ve had an earlier opportunity to correct my mistake.
</li>
<li>
<h4>Unit test for exceptional cases</h4>
<p>My unit testing of my method was not extensive enough.  Though I coded both pass and fail tests using <a href="http://junit.sourceforge.net/">JUnit</a>, I did not test for cases where someone would (very likely) try to pass in a port number along with the FQDN.  This step goes hand-in-hand with the above: Code your methods to accept <strong>only</strong> what you&#8217;ve said they&#8217;d accept, and fail on everything else.  Then, unit test to make sure this contract is fulfilled.
</li>
</ol>
<p>While the problem was frustrating, I&#8217;m glad to have learned these lessons.</p>
<hr/>Copyright &copy; 2008 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2008/05/15/the-importance-of-draconian-validation-for-method-parameters/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Playing with Google Maps and encoded polylines</title>
		<link>http://unitstep.net/blog/2008/05/11/playing-with-google-maps-and-encoded-polylines/</link>
		<comments>http://unitstep.net/blog/2008/05/11/playing-with-google-maps-and-encoded-polylines/#comments</comments>
		<pubDate>Mon, 12 May 2008 01:35:59 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[development]]></category>

		<category><![CDATA[google]]></category>

		<category><![CDATA[maps]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[documentation]]></category>

		<category><![CDATA[google maps]]></category>

		<category><![CDATA[polylines]]></category>

		<guid isPermaLink="false">http://unitstep.net/?p=324</guid>
		<description><![CDATA[
I&#8217;ve been playing around with the Google Maps API for a bit and it&#8217;s turned out to be a great way to get started with &#8220;mashups&#8221; and the like.  One of the best uses of the API is the ability to create paths or routes on the map.
This is done by creating GPolyline object [...]]]></description>
			<content:encoded><![CDATA[<p class="image align-right"><img src="http://unitstep.net/wordpress/wp-content/uploads/2008/05/google-maps.gif" alt="" title="google-maps" /></p>
<p>I&#8217;ve been playing around with the <a href="http://code.google.com/apis/maps/documentation/index.html">Google Maps API</a> for a bit and it&#8217;s turned out to be a great way to get started with &#8220;mashups&#8221; and the like.  One of the best uses of the API is the ability to create paths or routes on the map.</p>
<p>This is done by creating <a href="http://code.google.com/apis/maps/documentation/overlays.html#Polylines_Overview"><code>GPolyline</code></a> object and then adding it as an overlay to the map.  Basically, a polyline is just an ordered list of geographical points/coordinates on the map, each of which is a <a href="http://code.google.com/apis/maps/documentation/reference.html#GLatLng"><code>GLatLng</code></a> object.  For serialization/storage of polylines, there is an <a href="http://code.google.com/apis/maps/documentation/polylinealgorithm.html">algorithm you can use</a> to Base64-encode a series of points; the resultant string can later be passed directly into a factory method to regenerate the <code>GPolyline</code>.  By using encoded polylines, you also get access to a few more interesting and useful options related to rendering and performance issues.</p>
<h3>Encoded Polylines</h3>
<p>Despite the <a href="http://code.google.com/apis/maps/documentation/polylinealgorithm.html">algorithm for encoding polylines</a> being readily available on the Google Maps API documentation site, there is no built-in functionality within the API for generating the encoded polyline string from an existing <code>GPolyline</code> object.  This might be a bit strange, but it&#8217;s probably because the encoding process requires some extra values that aren&#8217;t available in the typical polyline.</p>
<p>As specified on the algorithm page, you also need to specify a list of encoded &#8220;levels&#8221; in addition to the points themselves.  These levels tell the the Google Maps renderer when certain points can be omitted from the polyline depending on the zoom level.  For example, with a polyline with <em>n</em> points, you&#8217;ll <strong>always</strong> want to show the first and last point, no matter what the zoom level.  However, intermediate points can potentially be omitted at low zoom levels and only shown when the map has been sufficiently zoomed in to warrant the detail.  This sort of optimization cannot be done with the typical <code>GPolyline</code> constructor that just takes an array of points. (<code>GLatLng</code> objects)</p>
<h3>Making things easy</h3>
<p>If you&#8217;ve looked at the <a href="http://code.google.com/apis/maps/documentation/polylinealgorithm.html">polyline encoding algorithm</a>, you&#8217;ll probably notice that it&#8217;s a bit tricky unless you&#8217;ve taken course in CS or done a lot of this stuff before. (At least it was tricky for me)  Google has an <a href="http://code.google.com/apis/maps/documentation/polylineutility.html">interactive utility</a> for generating the encoded polyline format for you.  The results can then be stored and later fed into a call to the factory method <a href="http://code.google.com/apis/maps/documentation/reference.html#GPolyline"><code>GPolyline.fromEncoded()</code></a> to regenerate the polyline.</p>
<p>However if you want to generate the encoded polyline format on-the-fly as part of your application, the interactive utility is not really an option.  Instead of coding the algorithm from the ground-up, there&#8217;s a much better way of doing things, thanks to the <a href="http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/">PolylineEncoder class</a> and other utilities provided by <a href="http://facstaff.unca.edu/mcmcclur/">Mark McClure</a>.</p>
<p>The <a href="http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/PolylineEncoderClass.html">PolylineEncoder class</a> is written in JavaScript and is very straightforward in its usage.  (It has been ported to several other languages as listed on <a href="http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/">his site</a>, in case you need to use it in different contexts)</p>
<p>Using this class allows you to quickly and easily convert a <code>GPolyline</code> into a compact encoded format useful for serialization or storage.  You can also use the class to convert arrays of points into encoded polylines, thus gaining the benefit of optimized rendering at different zoom levels.  McClure goes into an in-depth, but easy to understand <a href="http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/algorithm.html">explanation of the encoding algorithm used</a> complete with animations that show exactly how the polyline approximations work.</p>
<p>I highly recommend the usage of his polyline encoder as it saves you the headache of implementing it yourself.  It&#8217;s well-written, thoroughly documented and is free for usage. (It isn&#8217;t licensed under open-source terms but has instead been placed in the public domain - which is perhaps even more &#8220;free&#8221;) McClure also has a few other <a href="http://facstaff.unca.edu/mcmcclur/GoogleMaps/">interesing Google Maps projects</a> that you may want to check out.</p>
<h3>Some documentation warnings</h3>
<p>The Google Maps API documentation is fairly thorough, but it&#8217;s out of date in some places, as <a href="http://groups.google.com/group/Google-Maps-API/browse_thread/thread/e0861bacc7531b08/b5e504771ebb12c4">some people have found</a>.  Indeed, in this case, it appears that the <code>GPolyline.fromEncoded()</code> is documented somewhat wrongly in the API reference, though curiously, is used properly in their <a href="http://code.google.com/apis/maps/documentation/overlays.html#Polylines_Overview">examples page</a>.  </p>
<p>Specifically, you <strong>should not</strong> use:</p>
<pre><code>GPolyline.fromEncoded(color?,  weight?,  opacity?,  latlngs,  zoomFactor,  levels,  numLevels)</code></pre>
<p>if you want to generate a polyline from the encoded format.  Instead, you should use something like:</p>
<pre><code>GPolyline.fromEncoded({
    color: "#FF0000",
    weight: 10,
    points: "yzocFzynhVq}@n}@o}@nzD",
    levels: "BBB",
    zoomFactor: 32,
    numLevels: 4
});</code></pre>
<p>This is because the API has been updated to accept an object of options instead of separate parameters.  This, in my opinion, is better for readability and takes advantage of JavaScript&#8217;s ability to define inline anonymous object literals.  </p>
<p>As a side note, the example actually calls something like <code>new GPolyline.fromEncoded</code>, but I&#8217;ve found that you don&#8217;t need the <code>new</code> keyword, and in fact, it&#8217;s a bit confusing that the example has it and that it would work - after all, you are calling a factory method that returns a type of <code>GPolyline</code>, and not directly instantiating an object. (At least as far as <a href="/blog/2008/01/24/javascript-and-inheritance/">JavaScript uses the <code>new</code> keyword</a>)</p>
<hr/>Copyright &copy; 2008 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2008/05/11/playing-with-google-maps-and-encoded-polylines/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Eclipse: The best and only IDE you&#8217;ll ever need*</title>
		<link>http://unitstep.net/blog/2008/02/10/eclipse-the-best-and-only-ide-youll-ever-need/</link>
		<comments>http://unitstep.net/blog/2008/02/10/eclipse-the-best-and-only-ide-youll-ever-need/#comments</comments>
		<pubDate>Mon, 11 Feb 2008 00:39:16 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[development]]></category>

		<category><![CDATA[eclipse]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://unitstep.net/blog/2008/02/10/eclipse-the-best-and-only-ide-youll-ever-need/</guid>
		<description><![CDATA[
* Sensationalist headline inspired by previous posts
Eclipse is my IDE of choice, as you&#8217;l probably have noticed from some of my previous articles.  I had been wanting to write an article about why I use it (and why I switched to it), but kept putting it off.  Recently, Matt Mullenweg wrote about his [...]]]></description>
			<content:encoded><![CDATA[<p class="img align-right"><img src='http://unitstep.net/wordpress/wp-content/uploads/2008/02/eclipse-ide.thumbnail.jpg' alt='Copyright The Eclipse Foundation' /></p>
<p class="note less">* Sensationalist headline inspired by <a href="/blog/2007/10/16/sirreals-g15-plugin-the-best-and-only-logitech-g15-sdk-applet-youll-ever-need/">previous posts</a></p>
<p>Eclipse is my IDE of choice, as you&#8217;l probably have noticed from some of my <a href="/blog/2008/01/19/using-assemblas-trac-with-eclipse-mylyn-xml-rpc-access/">previous articles</a>.  I had been wanting to write an article about why I use it (and why I switched to it), but kept putting it off.  Recently, Matt Mullenweg <a href="http://ma.tt/2008/02/wither-dreamweaver/">wrote about his problems with Dreamweaver</a>, and this perhaps prompted me to organize my notes on why I&#8217;ve chosen to use Eclipse.  Don&#8217;t get me wrong - I&#8217;m not advocating that you immediately switch and throw out your current editing tool (the headline above, as noted, is purely for sensationalism) - but rather I&#8217;m just urging you to consider Eclipse for your next project.</p>
<h3>Changing Gears</h3>
<p>Like many, before switching to Eclipse I had been using a pure text editor, Ultraedit, for most of my web-development activities.  Ultraedit seemed fine for <a href="/blog/2007/06/10/ultraedit-php-5-and-the-function-list/">most things</a>, offering basic features like code highlight and autocompletion.  However, it lacked a certain finesse when it came to dealing with larger projects.  For example, if you&#8217;d defined a class, its members wouldn&#8217;t be available for autocompletion.  Something else was needed.  I finally decided to take the plunge, and switch over to Eclipse for all my development towards the end of the summer last year.</p>
<p>Some might wonder why I was even using a text-editor in the first place for development.  For those coming from a traditional programming/development background, the idea of not using an IDE (Integrated Development Environment) is silly.  This is because a lot of programming languages are compiled, and in this case, it just makes sense to use an IDE since it&#8217;s easier to write code, compile and debug using one tool instead of multiple ones. </p>
<p>However, for scripting languages, especially those meant to run on a web server, one can &#8220;get away&#8221; with not using an IDE quite easily.  This is because the scripts are not run standalone but are almost always executed in the context of a web server; thus you&#8217;re usually editing code that you then run on a development web server, without the need for a special tool like a compiler.  Additionally, it&#8217;s easy to view the output using any web browser.  These reasons are what allowed me to persist in using a text-editor for so long.</p>
<h3>No turning back</h3>
<p>However, once I started using Eclipse, I was hooked.  I downloaded Eclipse PDT (<acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> Development Tools), which is basically a version of Eclipse bundled with the tools/plugins necessary for setting up a <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> development environment.  Besides offering everything Ultraedit did, it also offered nice features like easy &#8216;Todo&#8217; lists, (just type &#8216;todo&#8217; anywhere in a comment and it&#8217;s automatically indexed by Eclipse into a list), code completion for built-in <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> functions and your own as well as a multitude of other advanced features that IDEs have.  Oh, and it&#8217;s also FOSS. (Free and Open Source Software)</p>
<p>However, perhaps the best part about Eclipse is its robust and well-supported plugin system.  This allows Eclipse to pretty much assume any feature that someone is willing to write a plugin for.  This is what really sold me on Eclipse, because this almost makes its abilities endless.  Some of the plugins I use are <a href="http://subclipse.tigris.org/">Subclipse</a> for SVN integration, <a href="http://www.eclipse.org/mylyn/">Mylyn for Trac integration</a> and <a href="http://labs.adobe.com/technologies/jseclipse/">JSEclipse</a> for JavaScript editing.  This is part of the reason why Eclipse is the <a href="http://en.wikipedia.org/wiki/List_of_Eclipse-based_software">basis for many other IDEs</a> out there.</p>
<p>Some other nice features are the ability to link the IDE in with the <a href="http://www.zend.com/en/community/pdt#debugger">Zend Debugger</a>, thus allowing for proper debugging sessions with <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym>.</p>
<h3>Spoiled</h3>
<p>However, I&#8217;ve been pampered somewhat and have found a few things to complain about, at least when it comes to Eclipse PDT.  I use Eclipse JDT (Java) a work and its advanced <a href="http://en.wikipedia.org/wiki/Refactoring">refactoring abilities</a> are a feature I find myself wanting in the PDT version.  Have you ever found yourself wanting to rename a variable to something more descriptive but putting it off because you&#8217;re afraid you&#8217;ll mess something up by forgetting to change the name somewhere?</p>
<p>With some IDEs, you&#8217;re left having to just do a search-and-replace in order to accomplish what should be a trivial name refactor.  Even if your editor supports regex searches, things can still be tricky - what if you&#8217;ve used the same name, but in a different context, and thus shouldn&#8217;t change the variable there?  The point is, the process still has to be human-supervised and is tedious.  With Eclipse JDT&#8217;s advanced refactoring, you can rename the variable once - and the IDE is smart enough to know where else to change it to keep the code consistent - <strong>very</strong> neat, and I was amazed when I first used it.  Other refactoring abilities include extracting methods out of blocks of code in order to clean up lengthy methods.  All of this makes your life 10 times easier and allows you focus on real programming rather than annoying tasks.</p>
<p>However, Eclipse PDT doesn&#8217;t support this for <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> code, yet.  I hear that it may be supported in a <a href="http://wiki.eclipse.org/PDT/1.5_Features_Proposal">later release</a>, so I have my fingers crossed.  Perhaps accomplishing these refactoring tasks is easier in Java because of its compiled nature or because the JDT project has received more attention.  It&#8217;s definitely possible in <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym>, as some IDEs, such as the <a href="http://www.zend.com/en/products/studio/">Zend Studio</a> (which is based on Eclipse) support this ability.  Zend Studio, however, is a commercial solution and I haven&#8217;t tried it out yet.</p>
<h3>Nothing&#8217;s perfect</h3>
<p>Eclipse does have its downsides as compared to a traditional text editor.  First of all, it&#8217;s a memory hog - though most IDEs are.  I have regularly seen Eclipse eat up 300-400 MB of RAM if I&#8217;ve been using it for a long time.  However, it should be noted that I have not had it crash once, so it&#8217;s been rock-solid as far as stability goes.  Nonetheless, I recommend you to have at least 2 GB of memory if you really want to use it properly, since you&#8217;re likely to have other programs open.  This is especially important if you&#8217;re running Windows Vista.  RAM is quiet cheap nowadays, and you can easily pick up 2 GB for $50 or less and upgrading is a painless process, so there&#8217;s no reason not to.</p>
<h3>Finishing up</h3>
<p>Eclipse has changed my life.  Okay, so perhaps I&#8217;m exaggerating a bit.  But, I can say that development, at least for me, would be much harder without Eclipse.  If you&#8217;re still using a text editor for development, I urge you to give Eclipse a try - just for 30 days, and see how you like it.  I don&#8217;t guarantee results as good as mine, but you may be pleasantly surprised.</p>
<hr/>Copyright &copy; 2008 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2008/02/10/eclipse-the-best-and-only-ide-youll-ever-need/feed/</wfw:commentRss>
		</item>
		<item>
		<title>JavaScript and inheritance</title>
		<link>http://unitstep.net/blog/2008/01/24/javascript-and-inheritance/</link>
		<comments>http://unitstep.net/blog/2008/01/24/javascript-and-inheritance/#comments</comments>
		<pubDate>Fri, 25 Jan 2008 03:22:35 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[guides]]></category>

		<category><![CDATA[inheritance]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://unitstep.net/blog/2008/01/24/javascript-and-inheritance/</guid>
		<description><![CDATA[JavaScript has a complicated history.  The name itself seems to indicate a relationship to Java, when in fact, the two languages share little in common except for a common syntax relationship by way of C.  Add to this the myriad of browser incompatibilities and numerous examples of bad usage, and you have what [...]]]></description>
			<content:encoded><![CDATA[<p>JavaScript has a complicated history.  The <a href="http://en.wikipedia.org/wiki/Javascript#History_and_naming">name itself</a> seems to indicate a relationship to Java, when in fact, the two languages share little in common except for a common syntax relationship by way of C.  Add to this the myriad of browser incompatibilities and numerous examples of bad usage, and you have what is perhaps the world&#8217;s least understood popular programming language.  (I had to add the &#8216;popular&#8217; qualifier, since I am sure there are some esoteric languages out there that only a handful of people know)</p>
<p>This is why inheritance in JavaScript is probably one of the least understood concepts.  While languages like Java have well-defined constructs for inheritance, the topic is of less importance with JavaScript.  In many situations, you&#8217;ll never have to deal with these aspects when programming in JavaScript, simply because it isn&#8217;t required for a lot of client side scripts.  However, for larger-scale web applications, applying object-oriented principles to your code may make it easier to design, improve and maintain.</p>
<p>There have been <a href="http://javascript.crockford.com/inheritance.html">many</a> <a href="http://javascript.crockford.com/prototypal.html">articles</a> <a href="http://20bits.com/2007/03/08/the-philosophy-of-javascript/">written</a> about inheritance in JavaScript and how it can and should be done.  You really don&#8217;t need to read mine to gain an understanding.  Rather, I&#8217;m just going to write about what I&#8217;ve learned, the process I went through and the experience I&#8217;ve gained along the way. </p>
<h3>It&#8217;s all new(s) to me</h3>
<p>If you come from a Java background, you&#8217;ll be no stranger to the <code>new</code> keyword.  Using it allows you to instantiate a new instance of an object from its class by calling its constructor.  The keyword also makes a lot of sense, since you&#8217;re creating a &#8216;new&#8217; object.</p>
<p>JavaScript also has a <code>new</code> keyword, but it doesn&#8217;t do quite the same thing as its Java counterpart, though at first the effects might seem similar.  This is one of the main reasons why JavaScript inheritance tends to be poorly understood.  </p>
<p>Consider the following example.</p>
<pre><code>function Foo(name)
{
  this.name = name;
}

var fooObject = new Foo('I am foo');</code></pre>
<p>If you&#8217;re familiar with Java or JavaScript, this example is fairly straightforward.  In the prototype-based JavaScript, <a href="http://en.wikipedia.org/wiki/Javascript#Prototype-based_features">functions can serve as object constructors</a> in somewhat the same manner as a constructor in Java.  However, <code>Foo</code> in the above example is not a class, since classes do not exist in JavaScript.  So, if <code>Foo</code> is not a class, what exactly happens when the statement <code>var fooObject = new Foo('I am foo')</code> is executed?</p>
<h3>Taking a step back</h3>
<p>Before we dive into the details, I&#8217;ll explain the concepts of a prototype-based language as it applies to JavaScript.  I mentioned above that JavaScript does not use classes like Java does.  This basically means that new objects are not created from instantiation of classes, but rather inherit from existing objects.  Thus, there is no &#8220;class hierarchy&#8221; but rather just an object hierarchy.  </p>
<p>In JavaScript, all objects are descended from the built-in <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Object"><code>Object</code></a> type.  This is similar to how all Java classes implicitly have the Object class as a superclass.  In JavaScript, instead of extending classes, you can inherit by manipulating the <code>prototype</code> property on a type; that is, the <code>prototype</code> property on the function you are using to create an object.  Let&#8217;s see some code to straighten things out.</p>
<pre><code>function Foo(name)
{
  this.name = name;
}
<strong>Foo.prototype.getName = function()
{
  alert(this.name);
}</strong>

var fooObject = new Foo('I am foo');
<strong>fooObject.getName(); // Will alert with 'I am foo'</strong></code></pre>
<p>This example is identical to the first one, except for the lines that are emphasized.  Here, I&#8217;ve set the <code>getName</code> property on the <code>prototype</code> property of <code>Foo</code> equal to a reference to a Function object.  This is effectively the same as defining a method for a class, since any object created from that type can call the method <code>getName()</code> on itself to return the proper value.  But what exactly is happening, and what&#8217;s the deal with the <code>prototype</code> property?</p>
<h3>More new(s)</h3>
<p>In JavaScript, the <code>new</code> keyword actually accomplishes a few things.  When you execute an expression such as <code>var fooObject = new Foo('I am foo')</code>, here&#8217;s exactly what happens.</p>
<ol>
<li>
First, a new generic object is created.  This object is the same as if you created the object using the statement <code>new Object()</code>, using JavaScript&#8217;s <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Object">built in Object type</a>.
</li>
<li>
The constructor function, that is, the function <code>Foo()</code>, is then called with the <code>this</code> keyword set to reference the newly-created object.  The parameters supplied are also passed to the constructor function, in this case, the string &#8220;I am foo&#8221;.  If you&#8217;re familiar with <a href="/blog/2007/12/18/using-the-call-and-apply-methods-to-change-the-context-of-a-function-in-javascript/">context</a>, this is equivalent to:</p>
<pre><code>var fooObject = new Object();
Foo.call(fooObject, 'I am foo');</code></pre>
<p>Thus, the code in <code>Foo()</code> sets a property called <code>name</code> equal to the supplied string.  Up to this point, things are the same as if you had created a new object and then manually set the <code>name</code> property yourself.  The next step is where things change.
</li>
<li>
The last step is where inheritance takes effect.  The constructor function, in addition to executing the specified code above, also sets an internal property called <code>__proto__</code> equal to the value of <code>Foo.prototype</code>.  This is how the new object inherits from the old one.</p>
<p>When you call a property on <code>fooObject</code> now, JavaScript will first check to see if the object has a local value for it.  In this case, the only local property is <code>name</code>. (Besides the internal and implicitly set <code>__proto__</code> property.  However, if it does not exist locally, it will check to see if the property exists under the object referenced by the <code>__proto__</code> property.  In this case, the <code>getName()</code> method exists under here.
</li>
</ol>
<p>Where things get confusing is because of how the <code>new</code> keyword is used.  Perhaps the designers of JavaScript wanted to use a keyword familiar to Java programmers so as to ease the transition to a new language that sounded so similar.  While it accomplishes a similar goal and for the most part you can consider the action to be almost the same, the use of the <code>new</code> keyword conceals the true meaning of prototype-based inheritance in JavaScript.  This ends up causing more confusion when you start digging into code.</p>
<h3>We&#8217;re all the same</h3>
<p>Suppose you created multiple objects from the <code>Foo()</code> constructor, called <code>fooObject1</code>, <code>fooObject2</code> and <code>fooObject3</code>,   In one fell swoop, you could add a new method to all of these objects without having to recreate them.  This is because of the <code>prototype</code> property.  Because each object contains a reference to <code>Foo.prototype</code>, adding a new method here will allow all objects access to it.  For example:</p>
<pre><code>Foo.prototype.yellName = function()
{
  alert(this.name.toUpperCase());
}
var fooObject3 = new Foo('I am Foo 3!');
fooObject3.yellName(); // alerts 'I AM FOO 3!'</code></pre>
<p>This adds another method to all <code>Foo</code>-constructed objects allowing them to &#8220;yell&#8221; their names.</p>
<h3>Extending Types</h3>
<p>I mentioned inheritance above but with just one type definition, the principles weren&#8217;t too clear.  Suppose we decided to extend our <code>Foo</code> &#8220;class&#8221; - how exactly would this work?  First, you need to define the child type and then set its <code>prototype</code> value to a new object of the parent type.  An example:</p>
<pre><code>function FooChild(childName)
{
  Foo.call(this, 'I am a child of Foo and my name is ' + childName);
}
FooChild.prototype = new Foo('');

var fooChildObject = new FooChild('Barbar');
fooChildObject.getName(); // Will alert with 'I am a child of Foo and my name is Barbar'</code></pre>
<p>Let&#8217;s break down what&#8217;s going on here.</p>
<ol>
<li>
First, we define a new constructor called <code>FooChild</code>.  In it, we <code>call</code> the parent constructor function with the context set to the current object.  This allows the <code>name</code> property to be set on the object during creation since that&#8217;s what the parent does.
</li>
<li>
Then, we set the <code>prototype</code> property equal to a new object that&#8217;s an instance of <code>Foo</code>.  This is what allows all of the child objects to have access to the parent&#8217;s properties, such as the <code>getName()</code> method.
</li>
</ol>
<h3>A few more details</h3>
<p>JavaScript provides two special operators for dealing with types and objects.  One is called <code>instanceof</code> and the other is <code>typeof</code>.  The latter, <code>typeof</code>, is less useful since it only deals with built-in JavaScript types.</p>
<p>The <code>typeof</code> operator returns the current variable&#8217;s type, but is limited to predefined types.  For example, <code>typeof fooChildObject</code> or <code>typeof fooObject</code> both return a string with the contents of &#8220;object&#8221;.  Thus, differentiating between the two is impossible.  More information can be found <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Operators:Special_Operators:typeof_Operator">at the Mozilla Developer Center</a>.</p>
<p>The <code>instanceof</code> operator is more interesting.  It takes two arguments and tests whether the first is an instance of the second.  (I guess I didn&#8217;t need to explain that) For example:</p>
<pre><code>function Foo(name)
{
  this.name = name;
}
Foo.prototype.getName = function()
{
  alert(this.name);
}

function FooChild(childName)
{
  Foo.call(this, 'I am a child of Foo and my name is ' + childName);
}
FooChild.prototype = new Foo('');

var fooObject = new Foo('I am foo');
var fooChildObject = new FooChild('Barbar');

alert(fooChildObject instanceof Foo); // true
alert(fooObject instanceof Foo); // true
alert(fooChildObject instanceof FooChild); // true
alert(fooObject instanceof FooChild); // false;</code></pre>
<p>In the above code, it is clear that <code>fooChildObject</code> is an instance of <code>FooChild</code>, and <code>fooObject</code>is an instance of <code>Foo</code>.  However, <code>fooChildObject</code> <strong>is also</strong> an instance of <code>Foo</code>, since its type was inherited from it through the <code>prototype</code> property.  However, <code>fooObject</code> <strong>is not</strong> an instance of <code>FooChild</code> since that type is a child of <code>Foo</code>.</p>
<p>I hope I haven&#8217;t said &#8220;foo&#8221; one too many times for you.</p>
<p>More information about <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Property_Inheritance_Revisited:Determining_Instance_Relationships"><code>instanceof</code> is again available</a> from the excellent Mozilla Developer Center.</p>
<h3>Concluding remarks</h3>
<p>I hope this has helped you to understand the nature of JavaScript&#8217;s built-in inheritance features.  I know I found it very convoluted at first, coming from a class-inheritance background.  I read everything I could find on the subject, and I believe it&#8217;s made me a better JavaScript programmer by understanding some of the &#8220;inner workings&#8221; of the language.  I encourage you to check out some of the references I&#8217;ve provided below.</p>
<h3>References</h3>
<ol class="note less">
<li><a href="http://javascript.crockford.com/prototypal.html">Prototypal Inheritance in JavaScript</a> - Douglas Crockford</li>
<li><a href="http://20bits.com/2007/03/08/the-philosophy-of-javascript/">The Philosophy of JavaScript</a> - Jesse of 20bits</li>
<li><a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Property_Inheritance_Revisited">Prototype Inheritance Revisited</a> - Mozilla Developer Center</li>
<li><a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:The_Employee_Example">The Employee Example</a> - Mozilla Developer Center</li>
</ol>
<hr/>Copyright &copy; 2008 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2008/01/24/javascript-and-inheritance/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Assembla&#8217;s Trac with Eclipse Mylyn XML-RPC access</title>
		<link>http://unitstep.net/blog/2008/01/19/using-assemblas-trac-with-eclipse-mylyn-xml-rpc-access/</link>
		<comments>http://unitstep.net/blog/2008/01/19/using-assemblas-trac-with-eclipse-mylyn-xml-rpc-access/#comments</comments>
		<pubDate>Sun, 20 Jan 2008 02:16:42 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[assembla]]></category>

		<category><![CDATA[eclipse]]></category>

		<category><![CDATA[guides]]></category>

		<category><![CDATA[mylyn]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[trac]]></category>

		<guid isPermaLink="false">http://unitstep.net/blog/2008/01/19/using-assemblas-trac-with-eclipse-mylyn-xml-rpc-access/</guid>
		<description><![CDATA[I recently found out about Assembla, an awesome service for managing software development projects.  It provides free SVN hosting (like other sites such as SourceForge and Google Code) but also provides tools like Trac, a Wiki, Scrum reporting, public or private access and up to 500 MB of disk space. (Additional features/space are available [...]]]></description>
			<content:encoded><![CDATA[<p>I recently found out about <a href="http://www.assembla.com/">Assembla</a>, an awesome service for managing software development projects.  It provides free SVN hosting (like other sites such as <a href="http://sourceforge.net/">SourceForge</a> and <a href="http://code.google.com/">Google Code</a>) but also provides tools like <a href="http://trac.edgewall.org">Trac</a>, a Wiki, Scrum reporting, public or private access and up to 500 MB of disk space. (Additional features/space are available for a cost)  For many, setting up services like Trac can be <a href="http://natmaster.com/articles/installing_trac.php">notoriously difficult</a>, so with <em>free</em> services like this, it&#8217;s hard to find any nits to pick.  </p>
<p>I won&#8217;t go into too much detail about the <a href="http://www.assembla.com/tour">features</a> since I wanted to talk about integrating the Eclipse plugin Mylyn with a Trac setup on Assembla.  There can be some issues getting things to work so I&#8217;ve outlined what I did to get everything running nicely.</p>
<h3>Background: Mylyn</h3>
<p><a href="http://www.eclipse.org/mylyn/">Mylyn</a> is an excellent task-management plugin for the ultimate IDE, Eclipse.  I have been trying it out for a variety of things, since I was trying to find something better than just text files for managing various tasks lists.  However, Mylyn does much <a href="http://www.ibm.com/developerworks/java/library/j-mylyn1/?ca=dgr-eclipse-1">more than just task management</a> as it helps to streamline your work environment with &#8220;context&#8221;.  I haven&#8217;t started using these advanced features though, but what really caught my eye was the integration Mylyn offers with various issue-tracking services such as Bugzilla and the aforementioned Trac.  This is accomplished by various &#8220;connectors&#8221;, with each connector being specific to one of the issue-tracking systems. </p>
<h3>The Problem: <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a>-RPC Integration</h3>
<p>Integration of Mylyn with Trac allows you to view, create and edit tickets in a Trac repository from within Eclipse.  To accomplish this, there are two levels of integration, the first being simple web-based access.  This is the more primitive of the two and has been around for longer.  Basically, items are still edited from a web browser; the only difference is the web browser is spawned within Eclipse.  This isn&#8217;t really ideal and doesn&#8217;t offer a real integration.</p>
<p>The second uses an <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a>-RPC interface to send/receive data and thus offers proper integration with the Eclipse environment.  However, when trying to connect to my Trac setup on Assembla with this choice, I ran into a lot of intermittent 404 (not found) errors.  Basically, synchronization was very flaky and by no means usable.  </p>
<h3>The Fix</h3>
<p>I did some searching and found <a href="http://www.assembla.com/flows/show_comment/cm_YtanJqr3lL8abIlDkbG?parent_id=cm_YtanJqr3lL8abIlDkbG&#038;space_id=c8A2BGQEWr2RUvaaeP0Qfc">this page</a> on the Assembla site where other users had experienced the same problem.  Scrolling through the comments brought me to <a href="http://vitaliel.blogspot.com/2007/08/mylyn-with-assembla-trac-hosting.html">this nice fellow&#8217;s explanation</a> of the problem, where a screencast was provided showing how it had been fixed.</p>
<p>Basically, these are the steps I did to get Mylyn <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a>-RPC integration with Trac working.</p>
<ol>
<li>
<h4>Enable the <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a>-RPC plugin</h4>
<p>Go to your Trac site, then click on Admin.  On the left sidebar go to <strong>General > Plugins</strong>.  There should be a section called <strong>TracXMLRPC</strong>; click to expand it.  You might as well enable RPC access for all of the options provided, though I&#8217;m not sure if this is necessary.  Here&#8217;s a screenshot.</p>
<p class="image">
<a rel="lightbox" href='http://unitstep.net/wordpress/wp-content/uploads/2008/01/assembla-mylyn-trac-01.png' title='Enable the XML-RPC plugin'><img src='http://unitstep.net/wordpress/wp-content/uploads/2008/01/assembla-mylyn-trac-01.png' alt='Enable the XML-RPC plugin' /></a></p>
</li>
<li>
<h4>Enable <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a>-RPC permissions</h4>
<p>After that, you need to enable permissions for <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a>-RPC access.  Go to <strong>General > Permissions</strong> on the sidebar.  In the &#8220;<strong>Grant Permissions</strong>&#8221; area, add a permission for &#8220;<strong>XML_RPC</strong>&#8221; for &#8220;<strong>@editors</strong>&#8220;.  Using &#8220;@managers&#8221; for the subject might also work/be needed if you&#8217;ve setup access for those users.  This is the basically what it should be:</p>
<p class="image">
<a rel="lightbox" href='http://unitstep.net/wordpress/wp-content/uploads/2008/01/assembla-mylyn-trac-02.png' title='Enable XML-RPC permissions'><img src='http://unitstep.net/wordpress/wp-content/uploads/2008/01/assembla-mylyn-trac-02.png' alt='Enable XML-RPC permissions' /></a></p>
</li>
<li>
<h4>Ensure there is at least one ticket in the system</h4>
<p>For some reason, I had weird errors when trying to synchronize/connect to a Trac repository with no tickets.  This was corroborated by <a href="http://vitaliel.blogspot.com/2007/08/mylyn-with-assembla-trac-hosting.html">the fellow who originally found the solution</a> to this problem.  It&#8217;s a minor issue though, just click &#8220;New Ticket&#8221; and create a placeholder.
</li>
<li>
<h4>Add Trac to Mylyn</h4>
<p>This step&#8217;s simply enough; though some suggestions recommended using <code>http://&lt;domain_name_to_assembla_trac&gt;/&lt;space_url_name&gt;/login/xmlrpc</code> as the <acronym class="uttInitialism" title="Uniform Resource Locator">URL</acronym>, I simply used <strong><code>http://&lt;domain_name_to_assembla_trac&gt;/&lt;space_url_name&gt;</code></strong> and it worked fine.  Remember to use <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a>-RPC as your access type or you won&#8217;t get proper integration.</p>
<p class="image">
<a rel="lightbox" href='http://unitstep.net/wordpress/wp-content/uploads/2008/01/assembla-mylyn-trac-03.png' title='Setting up Mylyn to work with Trac'><img src='http://unitstep.net/wordpress/wp-content/uploads/2008/01/assembla-mylyn-trac-03.png' alt='Setting up Mylyn to work with Trac' /></a>
</p>
</li>
</ol>
<p>After that, you should be able to properly connect to your Trac repository using the <a href="http://www.w3.org/XML/" class="ubernym uttInitialism"><acronym class="uttInitialism" title="eXtensible Markup Language">XML</acronym></a>-RPC option of Mylyn.  Then, you can finally enjoy proper Trac integration in Eclipse!</p>
<hr/>Copyright &copy; 2008 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2008/01/19/using-assemblas-trac-with-eclipse-mylyn-xml-rpc-access/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using the &#8220;call&#8221; and &#8220;apply&#8221; methods to change the context of a function in JavaScript</title>
		<link>http://unitstep.net/blog/2007/12/18/using-the-call-and-apply-methods-to-change-the-context-of-a-function-in-javascript/</link>
		<comments>http://unitstep.net/blog/2007/12/18/using-the-call-and-apply-methods-to-change-the-context-of-a-function-in-javascript/#comments</comments>
		<pubDate>Wed, 19 Dec 2007 01:54:04 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[guides]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://unitstep.net/blog/2007/12/18/using-the-call-and-apply-methods-to-change-the-context-of-a-function-in-javascript/</guid>
		<description><![CDATA[In JavaScript, the context that function is executing in is very important.  What is context?  Basically, the context of a function is what object it is &#8220;attached&#8221; to - this object will be the reference of the &#8220;this&#8221; keyword within that function.  Every function has a context -that is to say, every [...]]]></description>
			<content:encoded><![CDATA[<p>In JavaScript, the context that function is executing in is very important.  What is context?  Basically, the context of a function is what object it is &#8220;attached&#8221; to - this object will be the reference of the &#8220;<code>this</code>&#8221; keyword within that function.  Every function has a context -that is to say, every function is attached to an object.  By default it is the <code>window</code> object.</p>
<p>You may have run into this particular aspect of JavaScript when working with event handlers.  For example:</p>
<pre><code>function alertId()
{
  alert (this.id);
}

document.getElementById('someId').onclick = alertId;</code></pre>
<p>This will return the &#8220;id&#8221; attribute of the element that the function has been attached to.  You could attach the same function to multiple objects and each time you called it on a different object, it would return a different value, since the context is different.  (Minor note: using <code>element.attachEvent()</code>, as part of the Microsoft event handler model, <a href="http://www.quirksmode.org/js/events_advanced.html">does not change the context</a> of the function so &#8220;<code>this</code>&#8221; will still refer to the <code>window</code> object)</p>
<p>However, there may be times when you want to change the meaning of <code>this</code> without actually having to attach that a function to an object.  Using the <code>call()</code> and <code>apply()</code> methods of the Function object can allow you to do this.</p>
<h3>Context is everything</h3>
<p>Let&#8217;s backtrack for a moment.  In JavaScript, many (but not all) variables are objects.  This includes the references to all functions as well - they are also objects.  In the example above, using &#8220;<code>alertId</code>&#8221; (<em>without</em> the parentheses) would refer to the <code>Function</code> object that represents <code>alertId</code>.  As the <code>Function</code> object is a predefined object in JavaScript, it has <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Function">methods and properties associated</a> with it.</p>
<p>Two of these methods are <code>call()</code> and <code>apply()</code>.  Using these methods on a Function object allows you to set the context of that function - that is, what the &#8220;<code>this</code>&#8221; keyword refers to.  The two only in how arguments are passed to the function whose context is being redefined.  For example <code>apply()</code> takes an array of arguments like this:</p>
<pre><code>function someFunction(arg1, arg2)
{
  this.id = arg1 + arg2;
}

var arrayOfArguments = ['valueOfArg1', 'valueOfArg2'];

someFunction.apply(objectToBeUsedAsThis, arrayOfArguments);</code></pre>
<p>The values in the second-argument array are then used as the arguments to the <code>someFunction()</code> function.  </p>
<p>The <code>call()</code> method is almost the same except it does not take an array of arguments, but rather just an indeterminate number of arguments that are all passed to the function.  For example, the above could also be accomplished with this code:</p>
<pre><code>function someFunction(arg1, arg2)
{
  this.id = arg1 + arg2;
}

someFunction.call(objectToBeUsedAsThis, 'valueOfArg1', 'valueOfArg2');</code></pre>
<p>I prefer to use <code>apply()</code> sometimes since you can directly use the <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Function:arguments"><code>arguments</code></a> variable that is local within all functions. (The variable <code>arguments</code> stores all the arguments that were passed to the function when it was called, and so this can be used in a situation with where it is desired to have a function with a variable number of arguments.)</p>
<h3>A useful example</h3>
<p>So far, the examples posed have been fairly trivial.  Let&#8217;s look at a real-world use of <code>call()</code> to illustrate its usefulness.  Remember the <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Function:arguments"><code>arguments</code></a> variable?  Basically, you have access to this object variable whenever you&#8217;re inside a function since it stores all the arguments passed to this function.  However, it&#8217;s not exactly an array (although it works like one sometimes) and thus it <em>does not</em> have access to <code>Array</code> methods such as <a href="http://www.devguru.com/Technologies/ecmaScript/quickref/join.html"><code>join()</code></a>.  </p>
<p>We could easily convert it into an array by accessing each property by its index using a loop, but there&#8217;s an easier to way to do this.  Consider the following code:</p>
<pre><code>function someFunction()
{
  var argsArray = Array.prototype.slice.call(arguments, 0);
}</code></pre>
<p>Using this one line, we have successfully converted the <code>arguments</code> into a true Array object and stored the result in the <code>argsArray</code> variable.  How?  First, we access the <a href="http://www.devguru.com/Technologies/ecmaScript/quickref/slice.html"><code>slice()</code></a> method on the <code>Array</code> object through the <code>prototype</code> property and then <code>call()</code> the method telling it to use the <code>arguments</code> object as <code>this</code>.</p>
<p>The <code>slice()</code> method allows us to extract a section of an existing array.  However, by using <code>call()</code> we are able to apply its effects on the <code>arguments</code> object that is similar to, but not exactly an <code>Array</code> object.  The second argument of &#8216;0&#8242; merely indicates that we want to extract not just a part of <code>arguments</code> but all of it.  Since <code>slice()</code> always returns an <code>Array</code> object, we thus get back a true array containing the same data as the <code>arguments</code> object.  And that&#8217;s it!</p>
<p>Note that the above example could be compacted even further.  However, it looks very cryptic and can be confusing. (As if the previous example wasn&#8217;t confusing enough!) </p>
<pre><code>function someFunction()
{
  var argsArray = [].slice.call(arguments);
}</code></pre>
<p>This example works the same as the previous one.  Instead of using <code>Array.prototype</code>, we create a &#8216;dummy&#8217; empty array to get access to the <code>slice()</code> method.  The second argument of &#8216;0&#8242; isn&#8217;t needed, as if it is left out when using <code>slice()</code> the entire contents will be returned.</p>
<h3>Contextual Conclusion</h3>
<p>In short, using these methods to change the scope of a function can allow you to do some neat things with JavaScript that aren&#8217;t possible in some other languages.  However, one should always be mindful to keep code readable and maintainable and to lessen the learning curve for those new to a language.</p>
<hr/>Copyright &copy; 2008 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2007/12/18/using-the-call-and-apply-methods-to-change-the-context-of-a-function-in-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Exception handling in JavaScript</title>
		<link>http://unitstep.net/blog/2007/11/25/exception-handling-in-javascript/</link>
		<comments>http://unitstep.net/blog/2007/11/25/exception-handling-in-javascript/#comments</comments>
		<pubDate>Mon, 26 Nov 2007 01:54:00 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[exceptions]]></category>

		<category><![CDATA[guides]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://unitstep.net/blog/2007/11/25/exception-handling-in-javascript/</guid>
		<description><![CDATA[Exception handling is a topic that may not be well-understood by some web developers, depending on what languages they have the most experience in.  In particular, PHP, one of the most common server-side languages for web development, did not have support for exception handling until version 5.  In the four years between the [...]]]></description>
			<content:encoded><![CDATA[<p>Exception handling is a topic that may not be well-understood by some web developers, depending on what languages they have the most experience in.  In particular, <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym>, one of the most common server-side languages for web development, did not have support for exception handling until <a href="http://www.php.net/exceptions">version 5</a>.  In the four years between the release of PHP4 and PHP5, the language became increasingly popular among developers, and as a result, a lot of code was written without exception handling in mind.  The situation did not even improve much with the release of PHP5, since PHP5 was meant to be backwards-compatible with code developed for PHP4.  Three years later, there are still <a href="http://www.gophp5.org/">movements</a> to get developers to transition to a purely-PHP5 model.</p>
<p>Some of this may have transferred over to JavaScript, a language that is already poorly understood and often implemented even worse.  It is often hard to find well-written, maintainable JavaScript code, as it is often left as an afterthought in a project or otherwise not given much consideration, having been delegated to the realm of popup scripts and mouse-overs.  While exception handling may be overkill for a lot of JavaScript applications, many do not even know of JavaScript&#8217;s exception-handling capabilities.  In this article, I&#8217;ll give a brief overview of exception handling and some recommendations on how to use it in JavaScript to improve the readability of code. </p>
<h2>Exceptional conditions</h2>
<p>I won&#8217;t go too in-depth about the <a href="http://java.sun.com/docs/books/tutorial/essential/exceptions/advantages.html">merits of using exception handling</a> but will instead just give a brief overview.  (While there are some drawbacks, these apply more to the Java language rather than JavaScript)</p>
<p>The main reason for using exceptions is to have a separate channel for communicating errors.  Without this, you must communicate error conditions using the function itself. Consider a function that performs mathematical division:</p>
<pre><code>function divide(dividend, divisor)
{
  var quotient = dividend/divisor;
  return quotient;
}</code></pre>
<p>Division is a fairly simple arithmetic operation, but of the four basic operations it is the only one that has limits on its arguments: the divisor (the term you divide by) cannot be zero, since <a href="http://en.wikipedia.org/wiki/Division_%28mathematics%29">division by zero is undefined.</a>  So, how should you handle cases where the supplied arguments result in division by zero?  (The situation is very likely in an application accepting user input)</p>
<p>Without using exceptions, you have a few options, each of which has its own weaknesses.  Firstly, you could choose not to return <em>anything</em> and just <code>alert()</code> the user of the error.  This isn&#8217;t good since when you call the <code>divide()</code> function, you expect a result, not a warning message.</p>
<p>Secondly, you could choose to return a special &#8220;error code&#8221; indicating that there was a division by zero.  But this creates another problem - what exactly <em>do</em> you return when something goes wrong?  In this case, the only error case is division by zero - since JavaScript is a weakly-typed language, you could just return <code>false</code> on this error, but then in the calling code you&#8217;d have to check if <code>divide()</code> equaled <code>false</code> before using it, probably using the <a href="http://www.webreference.com/js/column26/stricteq.html">strict equality operator</a>.  As you can see, things get messy fast. </p>
<p>Alternatively, you could just check the inputs/arguments every time before you called the function.  However this is clumsy, and adds another layer of complexity where something could go wrong.  </p>
<h2>Another way of doing things</h2>
<p>As mentioned before, exception handling adds a side channel of sorts strictly for communicating errors.  By doing this, it allows for the interruption of program flow for the purpose of dealing with the exception or error situation.  Using exceptions, you would re-write the function above like this:</p>
<pre><code>function divide(dividend, divisor)
{
  if (0 == divisor) {
    throw new Error("Bzlorg! Cannot divide by zero.");
  }

  var quotient = dividend/divisor;
  return quotient;
}</code></pre>
<p>Here we are checking if the divisor equals zero - signifying an invalid input value - and then throwing an exception if this is the case.  How is this different than returning an error code?</p>
<p>The main difference is in the <em>control flow</em> of the program; using exceptions causes a change in the program flow.  In the above example, if the divisor equals zero, the execution of the function stops there and returns to the calling code with the throw exception.  The subsequent statements calculating the quotient and returning will not be executed.  Here&#8217;s an example of how you&#8217;d call the <code>divide</code> function.</p>
<pre><code>try {
  var dividend = 3;
  var divisor = 0;

  var quotient = divide(dividend, divisor);

  alert("The answer is " + quotient);
}
catch (e) {
  alert(e.message);
}</code></pre>
<p>With exceptions, you enclose code that could throw an exception with a <code>try</code> block.  This signifies to the interpreter (in the case of JavaScript) that you will be executing code (in this case, calling a function) that <em>could</em> throw an exception as a result of some error condition.  Thus you are <code>try</code>ing to do something - but as in real life, things may go wrong.</p>
<p>In this example, everything works until the line calling <code>divide</code>.  Since <code>divide</code> throws an exception with the input values supplied, flow will be directed to the <code>catch</code> block.  All <code>try</code> blocks must be followed with a <code>catch</code> block, with the variable in the parentheses specifying the variable to hold the thrown exception object.  In the code above, we merely alert the user to the problem - the message &#8220;Bzlorg! Cannot divide by zero&#8221; is displayed - in a real program you most likely would want to do handle the error differently depending on the context - but that&#8217;s a whole different topic.</p>
<p>If, however, you executed the code with valid values and no exceptions were thrown, once the program had got to the end of the <code>try</code> block it would jump over the following <code>catch</code> block and the user would be alerted with the correct answer.  Code within a <code>catch</code> block is <em>only</em> executed in the event that an exception is thrown.</p>
<h3>Differences with Java</h3>
<p>Since Java is an extremely popular language and one that also uses a similar exception handling model, it would be prudent to discuss some of the differences and similarities with it and JavaScript.</p>
<ol>
<li>
<h4><del>No multiple catch blocks with JavaScript</del></h4>
<p><del>This is perhaps the biggest difference.  If you&#8217;re familiar with Java you&#8217;ll know that different exception objects can be thrown during execution (all subclasses of the root/parent <code>Exception</code> class defined by Java), each signifying different error conditions.  You catch each of them separately by using separate catch blocks, each specifying a particular class or parent class.  However, with JavaScript, as you might have noticed from the code above, there can only be one catch block and thus there&#8217;s no need to specify the exception class. </del></p>
<p><del>If, however, you want the granularity of working with different exception classes, you&#8217;ll have to use the <code>instanceof</code> operator within a catch block, like this:</del></p>
<pre><code>try {
  ...
}
catch (e) {
  if (e instanceof RangeError) {
    ...
  }
  else if (e instanceof TypeError) {
    ...
   }
}</code></pre>
<p><del>It&#8217;s not as elegant as having multiple catch blocks, but it&#8217;s one way to deal with multiple exception types.</del></p>
<h4>Correction:</h4>
<p>It appears I was mistaken.  In JavaScript, you can indeed have <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Exception_Handling_Statements:try...catch_Statement#The_catch_Block">multiple catch blocks</a>, as seen in the <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide">Core JavaScript 1.5 Guide</a> from the Mozilla Developer Center.  My initial example above is still valid syntactically, but this way may be more appealing.  An example is as follows:</p>
<pre><code>try {
  ...
}
catch (e if e instanceof RangeError) {
  ...
}
catch (e if e instanceof TypeError) {
  ...
}
catch (e) {
  // General catch-all block.
  ...
}</code></pre>
<p>It just goes to show that when you think you know something, you probably don&#8217;t!  This is part of why I like JavaScript (and by extension, programming); there&#8217;s always more to learn and experience to be gained.</p>
</li>
<li>
<h4>Exception types</h4>
<p>The discussion of exception types brings us to another point - the different exception types in JavaScript.  JavaScript defines some <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Error">built-in exception</a> types, all based off the parent <code>Error</code> object.  These should suffice for most situations where you&#8217;re checking user input (the most common use), but if you&#8217;re developing a complex application you may want to define your own.  </p>
<p>In that situation, things get a little tricky, especially if you&#8217;re coming from Java.  Despite the outward similarity, JavaScript does not uses classes like Java, but instead uses a <a href="http://en.wikipedia.org/wiki/Prototype-based_programming">prototype-based approach</a> where inheritance comes from existing objects.  In this respect, things can get complicated as there are debates on <a href="http://www.sitepoint.com/blogs/2006/01/17/javascript-inheritance/">what the best way to inherit from objects</a> is and to that degree, a few JavaScript libraries have been written to facilitate the extending of objects in JavaScript.  These points are beyond the scope of this article, but I thought I&#8217;d just point you in the right direction.</p>
<p>Interestingly, you can also <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Exception_Handling_Statements:throw_Statement">throw many different</a> types of expressions, and are not limited to the built-in exception types.  For example, <code>throw false;</code> and <code>throw "Hello World";</code> are valid statements, but in my opinion, it doesn&#8217;t make much sense to throw any type of expression just because you can.  Using the built-in exception types (or defining your own) is a better practice, though throwing just String expressions might be alright in some situations.
</li>
<li>
<h4>Runtime errors</h4>
<p>During execution, you code may trigger runtime errors within JavaScript - for example, when trying to reference a property on a non-existent object.  These will also result in a new <code>Error</code> object being thrown, even though you did not define this throw in your code.  If this happens within a try block, the exception will subsequently be caught in the following catch block, and if you&#8217;re not expecting this error you may miss it.  (If, for example, you&#8217;re only looking for specific exception object types)</p>
<p>This can create problems with some of the JavaScript debuggers out there like <a href="http://www.getfirebug.com">Firebug</a>.  Since the runtime exception is being caught, Firebug will not be able to catch it (it is prevented from &#8220;filtering&#8221; up), so you may not be able to locate the source of your error if you&#8217;re relying on the debugger.  </p>
<p>My recommendation is thus to ensure your code runs properly under normal conditions.  Only then should you start using exceptions and try-catch statements.  This will ensure that no unexpected runtime exceptions get caught.  (The runtime errors are analogous to the unchecked runtime exceptions of Java in that they are not normally caught)
</li>
</ol>
<h3>Summing it up</h3>
<p>The whole point of using exceptions is not to make your code &#8220;work&#8221; better - anything that can be accomplished with exceptions can most likely be done without it, with just the same end result.  The point is to make your code more readable, manageable and flexible.  By using exceptions you get rid of having to use cumbersome &#8220;error codes&#8221;, the values of which you may forget later.  You also get more flexibility with how you handle errors.  You need not handle the error right in the function where it occurs - you can throw an exception to the calling code and handle the error there - or, alternatively, you could let the exception bubble up to a higher-level and handle all errors there.  It really depends on your needs, but using exceptions allows for this to be implemented more readily.</p>
<p>Though exceptions may seem like overkill for JavaScript and despite the limitations of its exception handling model as compared to that of Java&#8217;s, there are still some benefits to using exceptions, especially for complex JavaScript applications that you may implement to improve the interactivity of your site. </p>
<h4>Changes/Fixes</h4>
<ul>
<li><strong>2007-12-06</strong>: Changed <code>throw new Exception(...)</code> to correct statement of <code>throw new Error(...)</code>.</li>
<li><strong>2008-01-08</strong>: Fixed incorrect assertion of &#8220;No Multiple Catch Blocks&#8221; in JavaScript; added remarks about being able to throw any type of expression.</li>
</ul>
<hr/>Copyright &copy; 2008 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2007/11/25/exception-handling-in-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Facebook Application Development - Pros and Cons</title>
		<link>http://unitstep.net/blog/2007/07/16/facebook-application-development-pros-and-cons/</link>
		<comments>http://unitstep.net/blog/2007/07/16/facebook-application-development-pros-and-cons/#comments</comments>
		<pubDate>Tue, 17 Jul 2007 03:35:23 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[api]]></category>

		<category><![CDATA[facebook]]></category>

		<category><![CDATA[privacy]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[social networking]]></category>

		<guid isPermaLink="false">http://unitstep.net/blog/2007/07/16/facebook-application-development-pros-and-cons/</guid>
		<description><![CDATA[
It&#8217;s been a while since Facebook introduced the concept of &#8220;applications&#8221; to their API, providing developers a very flexible set of tools to create and add features to Facebook itself.  Applications on Facebook are best described as &#8220;widgets&#8221;, since they offer functionality that&#8217;s often provided by widgets on other sites, so why Facebook chose [...]]]></description>
			<content:encoded><![CDATA[<p class="image align-right"><img src="http://unitstep.net/wordpress/wp-content/uploads/2007/06/facebook-platform.png" alt="Facebook Platform" /></p>
<p>It&#8217;s been a while <a href="/blog/2007/06/03/facebooks-platform-adds-integration-to-applications/">since Facebook introduced</a> the concept of &#8220;applications&#8221; to their API, providing developers a very flexible set of tools to create and add features to Facebook itself.  Applications on Facebook are best described as &#8220;widgets&#8221;, since they offer functionality that&#8217;s often provided by widgets on other sites, so why Facebook chose a different name is somewhat peculiar.</p>
<p>I&#8217;m not going to debate the merits of these applications, or whether they&#8217;re leading Facebook down the road to a MySpace-hell dominated by personalized profiles that are an eyesore (there&#8217;s already <a href="http://www.downloadsquad.com/2007/06/20/facebook-users-fight-back-against-new-facebook-applications/">enough discourse</a> on that subject, both on Facebook and outside of it), but rather I&#8217;ll take a look at this from a developer&#8217;s point of view.  What is the potential for developing an application for Facebook, and at the same time, what are the pitfalls?</p>
<h3>Pro: Relatively easy to develop</h3>
<p><a href="http://developers.facebook.com/resources.php">Facebook&#8217;s API</a> is easy to work with, especially if you have experience with <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym>.  One of the official client libraries is written in <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym>, and since it&#8217;s intended to be used for web applications, this makes perfect sense.  Using it to develop an application should therefore be a relatively pain-free process.</p>
<p>While the <a href="http://developers.facebook.com/documentation.php">documentation</a> isn&#8217;t always complete, there&#8217;s a <a href="http://wiki.developers.facebook.com/index.php/Main_Page">nice Wiki</a> that covers additional details, and together, these two should allow you to overcome most problems you may run into during development.</p>
<p>Overall, the abilities offered by the API coupled with its ease of use make development relatively straightforward.</p>
<h3>Pro: Access to a large user base</h3>
<p>Facebook&#8217;s current <a href="http://mashable.com/2007/07/10/facebook-users-2/">user base of 30 million</a> is rapidly growing.  It&#8217;s already doubled since the start of this year, and continues to <a href="http://www7.flickr.com/photos/500hats/398658777/in/set-72157594550002847/">grow at close to 3% per week</a>.  If that rate continues, they&#8217;ll double again by the end of this year.  But perhaps the most amazing fact here is the dedication of Facebook&#8217;s user base.  It&#8217;s one thing to have millions and millions of users, with only a small percentage that are actually active.  This isn&#8217;t the case with Facebook, which <a href="http://www7.flickr.com/photos/500hats/398658941/in/set-72157594550002847/">sees over half of its users</a> log in daily.  That&#8217;s an astonishing statistic by any measure, and even more so when you consider Facebook large and fast-growing user base.</p>
<p>Thus, developing an application for Facebook gives it access to a large, and more importantly, active user base.  This gives it a huge potential to grow virally, that is, from person-to-person.  When someone adds your application to their profile or account, it will show up as a News Feed item.  This means that anyone who has this user as a friend will see a message in their News Feed about this user adding your application.  The idea is that they might get interested, click on your application, and then add it to their profile as well, continuing the viral spread cycle.  </p>
<p>They can, of course, also find your application by doing a search - if you&#8217;re lucky enough to get your application listed in Facebook&#8217;s official application directory - more on that later.</p>
<h3>Con: Cost and scalability</h3>
<p>I think Marc Andreessen (of Netscape fame) <a href="http://blog.pmarca.com/2007/06/analyzing_the_f.html">put it best</a> when referring to the popularity of an application on Facebook, namely that <q>success kills</q>.  (The rest of his article, while lengthy, is an excellent read and I suggest you take the time to read it)  Marc gives the example of the <a href="http://ilike.com/">iLike</a> application, one of the first, which experienced an insane growth in the early stages.  During that time, they grew by 300,000 <em>per day</em>, eating up all of their capacity to the point where they had to buy new servers on a daily basis.  </p>
<p>While a company such as iLike, with sources of revenue, may be able to shoulder this kind of burden, it&#8217;s quite unlikely that a lone developer would.  This creates a sort of Catch-22 - you want your application to become popular, so that you could hopefully monetize it.  However, in order for that to happen, you need plenty of resources - which require money.</p>
<p>If all you&#8217;re looking to create is a neat little application for you and your friends, or if your application doesn&#8217;t really create a huge load on your end, you&#8217;ll probably be alright.  But be aware that the same dedication and large user base of Facebook that can be so excellent for spreading an application, can be the same environment that quickly overruns your capacity to support your creation.</p>
<h3>Con: Monetization</h3>
<p>While we&#8217;re talking about monetization, it&#8217;s worthwhile to point out that if this is your main concern, it&#8217;s probably best not to pursue Facebook application development.  Since <a href="http://www.kinggary.com/archives/the-issues-that-ail-facebook-platform/">support costs can be high</a> for Facebook applications, attempting to derive a successful business model on this will most likely be met with limited success, if any.  Some have called for Facebook to <a href="http://www.feld.com/blog/archives/2007/06/the_facebook_pr.html">start a revenue sharing program</a>, but this is unlikely, considering Facebook&#8217;s <a href="http://valleywag.com/tech/mythbusting/facebooks-fake-revenues-278437.php">uncertain financial future</a> - even <em>if</em> the <a href="http://gigaom.com/2007/07/13/facebook-ipo-fact-or-fiction/">IPO rumours</a> turn out to be true.  (Which they likely will be)  </p>
<p>A revenue sharing program, however, would be fair, since by creating a successful application you are adding value to Facebook&#8217;s site, and directly increasing their revenues by nature of increasing the time a user spends on the site.  I would not, however, hold out on this to develop.</p>
<p>This doesn&#8217;t mean that application development is limited to those who just want to create something &#8220;for fun&#8221; or to add something to their portfolio.  On the contrary, I believe the best opportunities the Facebook platform affords is to other businesses based on web services.  By utilizing Facebook, they can create applications that promote their site, or tie into their own API, thus using Facebook&#8217;s large user base as a source for new customers, users, and thus revenue.  Indeed, the first applications developed were made by companies with this very intent.  Other sites could follow this model.</p>
<h3>Other Cons</h3>
<p>Some believe that the viral nature of Facebook apps <a href="http://valleywag.com/tech/hypebusting/facebook-has-thrown-the-entire-startup-world-for-a-loop-273359.php">has been overstated</a>, and that they now don&#8217;t spread as easily.  </p>
<p>Another, more serious aspect, relates to something I <a href="/blog/2007/05/14/facebook-marketplace-debuts/">alluded to</a> when I commented on Facebook&#8217;s introduction of their Marketplace, a classified-listing type service.  It seems that in the TOS of the Facebook Platform, they <a href="http://www.vecosys.com/2007/05/28/working-with-facebook-f8-you-are-not-in-control-of-your-access/">reserve the right to make a similar application</a> to yours, without obligation to you.  I don&#8217;t know if this is standard legalese in a TOS for API usage, but certainly it can be construed to be something more sinister, and would deny you any right you had to something you&#8217;d created.  Of course, if Facebook <em>did</em> do something like this, I&#8217;m sure there would be an uproar from the community, with <a href="http://digg.com">Digg</a> fanning the flames, of course.</p>
<h3>Privacy, as always</h3>
<p>Privacy is also a concern, as it now not only falls on the user to determine what settings to implement, but also whether developers will respect the TOS of the Facebook Platform.  The documentation <a href="http://developers.facebook.com/documentation.php?v=1.0&#038;method=users.getInfo">clearly outlines</a> what user (and user&#8217;s friend) info can be stored, but there is nothing to stop a developer from storing more of that information, either for the purposes of adding another feature to their application, or for malicious intent.  There have <a href="http://valleywag.com/tech/ilike/limitations-and-potential-of-new-facebook-applications-263728.php">already been concerns</a> about this with popular applications.</p>
<p>The issue of privacy here is that when you sign into a Facebook application, it basically has access to all of the friend info that you would - after all, it probably needs this to perform whatever function it does.  Though you may have consented to allow this information to be used, your friends may not have explicitly done this, and may not want their information to be used by 3rd party developers.  </p>
<p>Though users can opt-out of participation in the Facebook Platform altogether (and thus prevent 3rd party developers having access), I&#8217;m guessing that not everyone or even a majority know about this feature.  The privacy settings of Facebook have grown almost as much as the site itself, with settings divided amongst sections and sub-sections, creating somewhat of a convoluted mess.  The best precaution to all of this, of course, is not posting anything on the Internet that you wouldn&#8217;t want to be known in public.  This applies not only to Facebook but other sites as well; I only emphasize this for Facebook because of the notoriety its obtained from such incidents.</p>
<hr/>Copyright &copy; 2008 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2007/07/16/facebook-application-development-pros-and-cons/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ultraedit, PHP 5 and the function list.</title>
		<link>http://unitstep.net/blog/2007/06/10/ultraedit-php-5-and-the-function-list/</link>
		<comments>http://unitstep.net/blog/2007/06/10/ultraedit-php-5-and-the-function-list/#comments</comments>
		<pubDate>Sun, 10 Jun 2007 18:12:27 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[fix]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[regex]]></category>

		<category><![CDATA[ultraedit]]></category>

		<guid isPermaLink="false">http://unitstep.net/blog/2007/06/10/ultraedit-php-5-and-the-function-list/</guid>
		<description><![CDATA[
I was working on some PHP development recently with my editor of choice, UltraEdit.  In my view, UltraEdit is the text editor to use. (Assuming you&#8217;re in a Windows environment)  It basically has everything I need, and is especially well-suited for web development.  Where it may fall short is for developing desktop [...]]]></description>
			<content:encoded><![CDATA[<p class="image align-right"><a href="http://www.ultraedit.com"><img src="/wordpress/wp-content/uploads/2007/06/ultraedit.gif" alt="UltraEdit" /></a></p>
<p>I was working on some <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> development recently with my editor of choice, <a href="http://www.ultraedit.com">UltraEdit</a>.  In my view, UltraEdit is <em>the</em> text editor to use. (Assuming you&#8217;re in a Windows environment)  It basically has everything I need, and is especially well-suited for web development.  Where it may fall short is for developing desktop applications, as then a specific <abbr title="Integrated Development Environment">IDE</abbr> may offer more features, though UltraEdit can be configured to work with compilers and so forth.  (<a href="http://www.ultraedit.com/index.php?name=Content&#038;pid=150">UEStudio</a> is probably a better choice in this case)</p>
<p>While I don&#8217;t want to argue about the merits of UltraEdit, as people&#8217;s passion for their text-editors seem to border on the religious, I wanted to point out a potential solution to a code highlighting problem some of you may have encountered when developing with <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> 5.</p>
<h3>Missing functions in the function list</h3>
<p>UltraEdit supports code highlighting through its <code>wordfile.txt</code> file, which stores the configuration information for highlighting different languages based on their file extension(s).  This file can be found in the directory you installed UltraEdit to, or it can be accessed via the configuration menu.  This file determines what language highlighting options show up in the &#8220;View As&#8221; list.  It also allows the function list to display a list of functions/methods in the current file by defining what strings are function declarations. </p>
<p><a href="http://www.php.net"><acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> 5</a> supports <a href="http://ca3.php.net/zend-engine-2.php">classes and objects</a> better than previous versions.  In particular, setting the <a href="http://ca3.php.net/manual/en/language.oop5.visibility.php">visibility of members</a> is now supported.  So, you can define, for example, methods to be public, protected or private. (The default is public)<br />
However, when using one of these keywords to define a method, the method seemed to disappear from the function list.  This was with using UltraEdit 12.10.  </p>
<h3>Modifying the UltraEdit wordfile file</h3>
<p>You need to get the <a href="ftp://www.ultraedit.com/wf/php5.txt"><acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> 5 word file</a> and then add it to your word file.  Open up <code>wordfile.txt</code> (in UltraEdit, of course!), and delete the entire definition block previously used for <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym>.  It&#8217;ll start at a line of text that begins with:</p>
<pre><code>Lx"<acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym>"</code></pre>
<p>Where &#8216;x&#8217; is a number.  The end will be just before the next language definition, which will be something like:</p>
<pre><code>L(x+1)"LanguageName"</code></pre>
<p>You need to delete everything starting from the the first line to just before that last line.  Then, you can copy and paste in the contents of the <a href="ftp://www.ultraedit.com/wf/php5.txt"><acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> 5 word file</a>, changing the first line&#8217;s <code>L20</code> to <code>Lx</code>, where &#8216;x&#8217; was the number as before.  Public, protected and private-declared methods should now show up in the function list.</p>
<h3>UltraEdit and Regular Expressions</h3>
<p>The UltraEdit word file is actually a bunch of <a href="http://en.wikipedia.org/wiki/Regular_expressions">regular expressions</a> that tell UltraEdit which lines are function declarations (among other things) so that it can populate the function list with them.  In the past, it would <a href="http://simonwillison.net/2003/Mar/23/ultraEditRegularExpressions/#c9953">appear that the wordfile doesn&#8217;t use Unix-style RegExps</a> but instead uses some sort of UltraEdit format.  I don&#8217;t know if this behaviour has been changed since then, but looking at the word file, it appears that this is still the case.  </p>
<p>You see, UltraEdit has its own style of regular expressions.  While you have the option of searching within text files using either UltraEdit&#8217;s style, Unix, or Perl-compatible regular expressions, it seems as though the word file language definitions must use UltraEdit-style regular expressions.</p>
<hr/>Copyright &copy; 2008 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2007/06/10/ultraedit-php-5-and-the-function-list/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
