<?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; development</title>
	<atom:link href="http://unitstep.net/blog/category/development/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>Google Chrome: What it offers</title>
		<link>http://unitstep.net/blog/2008/09/02/google-chrome-what-it-offers/</link>
		<comments>http://unitstep.net/blog/2008/09/02/google-chrome-what-it-offers/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 01:03:15 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[Ajax]]></category>

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

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

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

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

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

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

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

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

		<category><![CDATA[internet explorer]]></category>

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

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

		<category><![CDATA[web2.0]]></category>

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

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

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

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

		<guid isPermaLink="false">http://unitstep.net/?p=411</guid>
		<description><![CDATA[
After much speculation yesterday, marked by a leaked web comic and finally an acknowledgment by Google, Google Chrome, the much anticipated web browser, is here.
I encourage you to download it and give it a try, as I did as soon as it came out.  Here are some of my initial impressions.
Overview
Google released a fairly [...]]]></description>
			<content:encoded><![CDATA[<p class="image align-right"><img src="http://unitstep.net/wordpress/wp-content/uploads/2008/09/google-chrome.jpg" alt="Google Chrome" /></p>
<p>After much <a href="http://blogoscoped.com/archive/2008-09-01-n47.html">speculation yesterday</a>, marked by a <a href="http://www.google.com/googlebooks/chrome/index.html">leaked web comic</a> and finally an <a href="http://googleblog.blogspot.com/2008/09/fresh-take-on-browser.html">acknowledgment by Google</a>, <a href="http://www.google.com/chrome/intl/en/features.html">Google Chrome</a>, the much anticipated web browser, <a href="http://googleblog.blogspot.com/2008/09/google-chrome-now-live.html">is here</a>.</p>
<p>I encourage you to <a href="http://www.google.com/chrome/index.html">download it</a> and give it a try, as I did as soon as it came out.  Here are some of my initial impressions.</p>
<h3>Overview</h3>
<p>Google released a fairly long <a href="http://www.google.com/googlebooks/chrome/">web comic</a> that delves into quite a bit of detail about Chrome - it&#8217;s not your typical comic!  Touted as being built &#8220;from scratch&#8221;, Chrome uses the WebKit rendering engine, the same one that powers Safari and Konqueror.</p>
<p class="image"><a href="http://unitstep.net/wordpress/wp-content/uploads/2008/09/google-chrome-2.jpg"><img src="http://unitstep.net/wordpress/wp-content/uploads/2008/09/google-chrome-2-300x207.jpg" alt="" title="google-chrome-2" width="300" height="207" class="alignnone size-medium wp-image-420" /></a></p>
<p>The first thing you notice is how minimal the &#8220;Chrome&#8221; or UI of Chrome is.  If you&#8217;re used to a half-dozen toolbars, buttons and widgets all over the place, Chrome will seem like a greenfield to you.  By default, there is only a tab bar and then an address bar containing back, forward, a combined reload-stop button and the address bar.  There are also buttons for bookmarking a site and for page and browser settings.  The bookmarks bar is not displayed unless you specifically change that setting.</p>
<p>Keyboard shortcuts are also present so that you don&#8217;t have to click through context menus.  If you&#8217;re used to the keyboard shortcuts of Firefox and IE7 you&#8217;ll be pleased to know that most of them transfer over without change: Ctrl-T opens a new Tab, Ctrl-W/Ctrl-F4 closes a tab, Alt-D focuses the address bar and Ctrl-J opens Downloaded Files.</p>
<p>The address bar also functions as a search bar, and this combination just makes sense.  It&#8217;s something I&#8217;ve always been doing using <a href="http://lifehacker.com/software/geek-to-live/geek-to-live-fifteen-firefox-quick-searches-129658.php">Firefox Quick Searches</a></p>
<p>By default the home/start page is set to set to show an Opera-style &#8220;<a href="http://www.opera.com/support/tutorials/flash/speeddial/">Speed Dial</a>&#8221; page containing most recently-accessed pages/bookmarks.  You can also configure Chrome to restore the previous tabs/websites on startup, which is my personal preference ever since I started using Firefox.</p>
<h3>Features</h3>
<p>Chrome integrates Google Gears to speed up supporting web applications and is an obvious effort by Google to self-promote. This is substantial since the download link for Chrome is on the main Google search page - no small feat considering only the most popular/important services get that sort of attention and furthermore the link is positioned dead center beneath the search field.</p>
<p class="image">
<a href="http://unitstep.net/wordpress/wp-content/uploads/2008/09/google-chrome-3.jpg"><img src="http://unitstep.net/wordpress/wp-content/uploads/2008/09/google-chrome-3-300x210.jpg" alt="" title="google-chrome-3" width="300" height="210" class="alignnone size-medium wp-image-422" /></a><br />
The address/search bar
</p>
<p>Chrome allows for quasi-<a href="http://en.wikipedia.org/wiki/Site_Specific_Browser">Site-Specific Browsers</a> by use of &#8220;Application Shortcuts&#8221;, which can be set for any website but are meant to be used mainly with web applications.  These allow you to open the target <acronym class="uttInitialism" title="Uniform Resource Locator">URL</acronym> in a browser window that does not have the menu or address bars and essentially serves as a blank canvas upon which the web application&#8217;s own UI can be displayed.  </p>
<p>This is similar to other SSBs such as <a href="https://wiki.mozilla.org/Prism">Mozilla Prism</a> or <a href="http://fluidapp.com/">Fluid</a> for the Mac, as they aim to bridge the gap between desktop and web applications to make their integration more seamless.</p>
<p>However, like <a href="http://blogoscoped.com/archive/2008-09-01-n47.html">Google Blogoscoped points out</a>, using such non-browser interfaces may condition the user to be more lax when entering their credentials and makes phishing attempts more viable since no <acronym class="uttInitialism" title="Uniform Resource Locator">URL</acronym> is displayed.  This is curious since security, &#8220;sandboxing&#8221; and general safe browsing were so high on Chrome&#8217;s feature list - this feature seems to help undo some good user practices of always confirming the <acronym class="uttInitialism" title="Uniform Resource Locator">URL</acronym> before entering credentials. </p>
<p>There are also some nice little enhancements as well - the combined address bar/search bar is very much like Firefox 3&#8217;s &#8220;awesome bar&#8221;.  Chrome also allows you to dynamically resize any <code>textarea</code> element, without the site designer having to code this specifically in JavaScript or some other client-side technology.</p>
<h3>Performance</h3>
<p>Each tab/window is a separate process and thus will show up separately in Task Manager; Chrome also offers its own Task Manager but the memory usage reported here differs from that in the Windows Task Manager.  To get the full picture, you have to click on the &#8220;Stats for nerds&#8221; link, which takes you to <code>about:memory</code></p>
<p class="image">
<a href="http://unitstep.net/wordpress/wp-content/uploads/2008/09/google-chrome-4.jpg"><img src="http://unitstep.net/wordpress/wp-content/uploads/2008/09/google-chrome-4-300x192.jpg" alt="" title="google-chrome-4" width="300" height="192" class="alignnone size-medium wp-image-424" /></a>
</p>
<p>This page displays the full memory usage details, and also, surprisingly, displays memory usage for any other web browsers also currently running! (I have confirmed that it will display Firefox 2/3, IE7 and Opera 9)</p>
<p class="image">
<a href="http://unitstep.net/wordpress/wp-content/uploads/2008/09/google-chrome-5.jpg"><img src="http://unitstep.net/wordpress/wp-content/uploads/2008/09/google-chrome-5-300x208.jpg" alt="" title="google-chrome-5" width="300" height="208" class="alignnone size-medium wp-image-425" /></a>
</p>
<p>Much talk has been made of this feature; indeed while it does use more resources, it also prevents a single site from bringing down the entire browser as only that tab/window will be affected.  To test this out, just terminate one of the instances of chrome.exe and you will see that tab&#8217;s screen into a &#8220;sad tab of death&#8221; with an amusing message.</p>
<p class="image">
<a href="http://unitstep.net/wordpress/wp-content/uploads/2008/09/google-chrome-1.jpg"><img src="http://unitstep.net/wordpress/wp-content/uploads/2008/09/google-chrome-1.jpg" alt="" title="google-chrome-1" width="346" height="313" class="alignnone size-full wp-image-415" /></a>
</p>
<h3>JavaScript</h3>
<p>Though JavaScript falls under the category of `Performance` I felt it deserves its own section because of the importance of JavaScript in web applications.  Chrome uses the Google-developed V8 JavaScript engine, which has also been <a href="http://code.google.com/apis/v8/">released as open source</a>.</p>
<p>The <a href="http://code.google.com/apis/v8/design.html">main points</a> of V8 are outlined at the Google Code page for the project, and are quite interesting.  One of the main improvements in performance is the use of a Virtual Machine (VM) for processing JavaScript.</p>
<p>The V8 Virtual Machine is different from say, the JVM (Java Virtual Machine) in that it compiles JavaScript source <em>directly to machine code</em>; there is no intermediate byte-code representation used and hence no interpreter is needed for this.  This seems to indicate that JavaScript performance might be faster on Chrome since there&#8217;s no intermediary. Google provides some <a href="http://code.google.com/apis/v8/benchmarks.html">benchmarks</a> to confirm this.</p>
<p>From some informal/unscientific preliminary testing, the V8 JavaScript engine in Chrome <em>does</em> appear to be quite fast; loading the same Digg topic in Firefox took longer than it did in Chrome. (Roughly 14 secs vs. 8 seconds over a few trials - and Chrome did not have the benefit of AdBlock Plus) I&#8217;d be <em>very</em> interested to see how Chrome stacks up against Firefox 3.1, considering the rumoured <a href="http://arstechnica.com/news.ars/post/20080822-firefox-to-get-massive-javascript-performance-boost.html">performance boosts</a> coming with it.</p>
<p>If Chrome has anything going for it, it&#8217;s definitely the lightning fast JavaScript performance.  Coupled with the crash-proofing this makes it ideal for use in web applications.</p>
<h3>Development</h3>
<p>Chrome comes with a nice DOM inspector reminiscent of Firebug.  Using it is dead simple; you just right click and select &#8220;Inspect Element&#8221; and the inspection window will pop up with the element highlighted.  Here you can see the full DOM tree as well as the computed <acronym class="uttInitialism" title="Cascading Style Sheets">CSS</acronym> styles for the element.  </p>
<p class="image">
<a href="http://unitstep.net/wordpress/wp-content/uploads/2008/09/google-chrome-6.jpg"><img src="http://unitstep.net/wordpress/wp-content/uploads/2008/09/google-chrome-6-300x231.jpg" alt="" title="google-chrome-6" width="300" height="231" class="alignnone size-medium wp-image-427" /></a>
</p>
<p>There&#8217;s an included JavaScript console for executing code/commands/expressions on-the-fly and while there is a JavaScript debugger included, it seems at this time to be a command-line only tool, far less user-friendly than Firebug.</p>
<h3>Not ready for prime time yet?</h3>
<p>Of course, Chrome is marked as Beta by Google, something we&#8217;ve come to expect since Gmail has been in beta for longer than the company has been publicly traded.  Nonetheless, there are still some features that are sorely missed.</p>
<p>The one thing I absolutely love about Firefox is the vibrant developer community and subsequent widespread availability of quality, useful extensions.  This has produced such gems as the aforementioned <a href="https://addons.mozilla.org/en-US/firefox/addon/1843">Firebug</a> and <a href="http://adblockplus.org/en/">Adblock Plus</a>.  </p>
<p>For now, extensions/addons are not part of Chrome but may be added in a later version.  In the meantime I don&#8217;t think I&#8217;ll be even close to ready to switch, as I&#8217;m very stubborn.  I don&#8217;t use that many extensions but the few that I do are &#8220;must-haves&#8221; and I just can&#8217;t browse without them.  </p>
<p>Lastly, there are always privacy concerns, especially from a company as big an involved as Google.  Though you can turn off the sending of usage statistics, there will always be some with their tinfoil hats on.</p>
<h3>Conclusions</h3>
<p>All things considered, Chrome is a very good entry into the browser market.  While I don&#8217;t think it&#8217;s ready to take on Firefox or IE yet, it does provide competition.  So as long as Chrome continues to support standards (which I think it will, since it uses the WebKit renderer and Google has also been forthcoming with their <a href="http://www.google.com/chrome/intl/en/webmasters.html">support for web developers</a>), I won&#8217;t have a problem with it.  I won&#8217;t be switching over to it anytime soon, but at the very least it&#8217;ll be a useful development tool to verify/test my websites on to make sure they look proper in Safari/Konqueror/Chrome.</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/09/02/google-chrome-what-it-offers/feed/</wfw:commentRss>
		</item>
		<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>I&#8217;ve been busy</title>
		<link>http://unitstep.net/blog/2008/07/05/ive-been-busy/</link>
		<comments>http://unitstep.net/blog/2008/07/05/ive-been-busy/#comments</comments>
		<pubDate>Sun, 06 Jul 2008 03:17:39 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[asides]]></category>

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

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

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

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

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://unitstep.net/?p=340</guid>
		<description><![CDATA[I haven&#8217;t been posting updates or writing as many articles here as I&#8217;d like to, and it&#8217;s mainly because I&#8217;ve been busy putting the final touches on a website I&#8217;m about to launch.  I don&#8217;t want to give away too many details or build too much hype, because frankly it&#8217;s not that big of [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t been posting updates or writing as many articles here as I&#8217;d like to, and it&#8217;s mainly because I&#8217;ve been busy putting the final touches on a website I&#8217;m about to launch.  I don&#8217;t want to give away too many details or build too much hype, because frankly it&#8217;s not <em>that</em> big of a project and was never intended to be.</p>
<p>However, it was a project that I intended to learn from, and in that regard, I think I&#8217;ve succeeded - and that&#8217;s really what I want to continue doing for the rest of my life.  Furthermore, while the project was an exercise in improving my web and software development skills, the end result will also be something that I will actually use myself - not just some pointless academic exercise.  Another nice effect was the experience of seeing a self-directed project come to fruition over the last few months - albeit at a slow rate, usually only several hours per week, but nonetheless I&#8217;ve improved my self-discipline as a result.</p>
<p>I will say that you can get somewhat of an idea of what this site will be about by browsing through some of my <a href="/blog/category/maps/">previous posts</a>.  But, that&#8217;s all I&#8217;m going to say at this point.</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/07/05/ive-been-busy/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>CakePHP and error/exception handling</title>
		<link>http://unitstep.net/blog/2008/05/11/cakephp-and-errorexception-handling/</link>
		<comments>http://unitstep.net/blog/2008/05/11/cakephp-and-errorexception-handling/#comments</comments>
		<pubDate>Sun, 11 May 2008 18:40:08 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[PHP]]></category>

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

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

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

		<guid isPermaLink="false">http://unitstep.net/?p=321</guid>
		<description><![CDATA[
I&#8217;m currently using CakePHP and finding it to be quite useful.  The &#8220;automagic&#8221; handling of tables is useful for basic relationships, though more complicated setups usually require manual work.  The MVC implementation has also clearly drawn inspiration from Ruby on Rails, which may be advantageous to some, though this has no bearing on [...]]]></description>
			<content:encoded><![CDATA[<p class="image align-right"><img src="http://unitstep.net/wordpress/wp-content/uploads/2008/05/cakephp.png" alt="Copyright CakePHP" title="cakephp" width="150" height="139" /></p>
<p>I&#8217;m currently using <a href="http://cakephp.org/">CakePHP</a> and finding it to be quite useful.  The &#8220;automagic&#8221; handling of tables is useful for basic relationships, though more complicated setups usually require manual work.  The MVC implementation has also clearly drawn inspiration from <a href="http://www.rubyonrails.org/">Ruby on Rails</a>, which may be advantageous to some, though this has no bearing on me.  Though there are a few things that nag me about CakePHP (such as lack of a good testing suite, though that&#8217;s supposedly <a href="http://bakery.cakephp.org/articles/view/testing-models-with-cakephp-1-2-test-suite">fixed in 1.2</a>, which really should be marked as version 2.0), overall it&#8217;s a great framework that adds badly-needed structure to <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> and has saved me time.</p>
<p>One thing I&#8217;d like to see, however, is a proper exception handling model.  I realize this would <a href="http://gophp5.org/">require making it <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> 5-only</a>, but in my opinion, <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> 5 adds some sorely-need features, such as the aforementioned exception handling model and a class/object system more in line with other languages.</p>
<h3>Signaling intent</h3>
<p>I&#8217;ve written about the <a href="/blog/2007/11/25/exception-handling-in-javascript/">benefits of exception handling</a> before, so I won&#8217;t delve into those details again.  In short, using exceptions is a better way for a method to signal to a caller that something went wrong rather than just returning a special/reserved value as an error code.</p>
<p>In particular, saving of models would benefit from this.  Currently, if you want to check if the model was saved properly, you have to do something like this:</p>
<pre><code>if ($this-&gt;ModelName-&gt;save($this-&gt;data))
{
  // Model saved properly, can continue normally here.
  ...
}
else
{
 // Model did not save properly.
}</code></pre>
<p>It&#8217;s a little bit kludgy, but isn&#8217;t actually that bad since Cake simplifies form validation a lot with the <acronym class="uttInitialism" title="HyperText Markup Language">HTML</acronym> helper in views.  You can simply put something like <code>$html-&gt;tagErrorMsg('Post/title', 'Title is required.')</code> in your view to display that error message when a particular field does not validate.  This removes a lot of the tedium out of making your forms return proper error messages in situations with bad input.</p>
<h3>Exceptional cases</h3>
<p>However, in some situations you might want to execute your own logic when a call to <code>Model::save()</code> fails.  In this case, having that method throw a proper exception would allow the error to be propagated to the controller nicely and would remove the need to make a call to <code>Model::invalidFields()</code> to get the reason.</p>
<p>Coming from a Java background, this makes more sense to me, since I consider its exception handling model to be one of the language&#8217;s strong points.  It has numerous benefits to improving readability and maintainability of code.</p>
<p>However, there are some drawbacks, since this requires the use of <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> 5.  As CakePHP is designed to be <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> 4 and 5 compatible, exception handling is really not an option.  However, since <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> 4 is so old, I&#8217;d eventually like to see a <a href="http://gophp5.org/">move to <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> 5</a>, especially for its better OOP model and exception handling.  Additionally, <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> 6 is just around the corner, so I don&#8217;t really see a need to stick with <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> 4 for that much longer.</p>
<p>Additionally, if you&#8217;re just saving one model (as the result of a form submission) it doesn&#8217;t really make sense, nor is it necessary, to have exception handling since CakePHP already takes care of displaying error message for the invalid fields:</p>
<pre><code>// Controller:
...
if ($this-&gt;Post-&gt;save($this-&gt;data))
{
  $this-&gt;flash('Your post has been saved.','/posts');
}
...

// View:
...
&lt;?php echo $html-&gt;input('Post/title', array('size' =&gt; '40'))?&gt;
&lt;?php echo $html-&gt;tagErrorMsg('Post/title', 'Title is required.') ?&gt;
...</code></pre>
<p>In the above example, taken from <a href="http://manual.cakephp.org/view/326/the-cake-blog-tutorial">CakePHP&#8217;s own blog tutorial</a>, you don&#8217;t really need exception handling since the appropriate actions are automatically handling by Cake.  If the save succeeds, a positive message will be displayed and the user forwarded on.  Otherwise, the controller proceeds to render the given view, where <code>$html-&gt;tagErrorMsg</code> displays the given error message if the associated field was marked as invalid by the model during the save attempt.</p>
<p>For more complicated situations where you&#8217;re saving multiple related models in a single controller action, exception handling would be helpful in reducing the number of branches, since you wouldn&#8217;t need to have so many <code>if ... else</code> blocks muddling up the flow of the code.  However, it&#8217;s not straightforward to integrate this into Cake, since for most of the time, people won&#8217;t need the exception handling capability if they&#8217;re just doing a simple save as outlined above. </p>
<p>The easiest way I see of accomplishing this is to define your own method that wraps around the existing <code>Model::save()</code> method so that proper exceptions can be thrown.  This would, of course, create confusion as then there would be <em>two</em> &#8217;save&#8217; methods. </p>
<p>All things considered, Cake is still a strong framework, so I will continue using it.  For all the slight concerns I have, it&#8217;s still very much beneficial to me.  If there&#8217;s one more thing I could ask for from Cake though, it would be for better documentation!  Maybe I should start contributing&#8230;</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/cakephp-and-errorexception-handling/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ThreatFire hanging or slowing down MySQL?</title>
		<link>http://unitstep.net/blog/2008/04/12/threatfire-hanging-or-slowing-down-mysql/</link>
		<comments>http://unitstep.net/blog/2008/04/12/threatfire-hanging-or-slowing-down-mysql/#comments</comments>
		<pubDate>Sat, 12 Apr 2008 16:10:02 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[development]]></category>

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

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

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

		<guid isPermaLink="false">http://unitstep.net/?p=316</guid>
		<description><![CDATA[
After seeing glowing recommendations for the heuristic-based ThreatFire anti-malware app from PC Tools, I decided to install it to complement my antivirus scanner and other anti-spyware tools such as Spybot-S&#038;D and Ad-Aware.
Initially, it worked fine.  While I don&#8217;t know how much protection it really added, it was intuitive, easy to configure and didn&#8217;t slow [...]]]></description>
			<content:encoded><![CDATA[<p class="image align-right"><img src="http://unitstep.net/wordpress/wp-content/uploads/2008/04/threatfire-xampp.jpg" alt="XAMPP and ThreatFire" title="threatfire-xampp" width="200" height="145" /></p>
<p>After seeing <a href="http://www.maximumpc.com/article/internet_security_2_0?page=0%2C3">glowing</a> <a href="http://lifehacker.com/344645/protect-your-pc-from-viruses-in-real+time-with-threatfire">recommendations</a> for the heuristic-based <a href="http://www.threatfire.com/">ThreatFire</a> anti-malware app from PC Tools, I decided to install it to complement my antivirus scanner and other anti-spyware tools such as <a href="http://www.safer-networking.org/en/index.html">Spybot-S&#038;D</a> and <a href="http://www.lavasoftusa.com/">Ad-Aware</a>.</p>
<p>Initially, it worked fine.  While I don&#8217;t know how much protection it really added, it was intuitive, easy to configure and didn&#8217;t slow down my system like many other real-time scanners might have.  However, I ran into some trouble with my web development environment, consisting of Apache, MySQL and <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> (in the form of <a href="http://www.apachefriends.org/en/xampp.html">XAMPP</a>) that I could only attribute to ThreatFire&#8217;s presence.</p>
<h3>The symptoms</h3>
<p>With ThreatFire installed and enabled, requesting any pages from Apache that would result in MySQL access took painfully long.  Accessing static pages or scripts that did not use the MySQL database did not hang. At first, I thought it was a problem with the application/scripts I was working on, but other popular third-party scripts, such as <a href="http://www.phpmyadmin.net/">phpMyAdmin</a>, were also slow or unresponsive.  The server appeared to &#8220;hang&#8221; for about 10-15 seconds before producing any response.  This was on a local server.</p>
<p>I tried several different courses of action, such as:</p>
<ul>
<li>Enabling logging of slow queries with the <code>--log-slow-queries</code> option.</li>
<li>Adding the MySQL binaries (<code>mysqld.exe</code> and <code>mysqld-nt.exe</code>) to the ThreatFire exclusion/ignore list</li>
<li>Reinstalling XAMPP</li>
</ul>
<p>None of these worked.  In particular, logging slow queries did not produce any logs, which seemed to indicate that MySQL was hanging even before the queries were executed.  Surprisingly, logging the execution time of <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> scripts did not seem to indicate any problems either.  The queries I was executing and that datasets I was working on were also small and unlikely to be a contributing factor - any query, no matter how simple, seemed to hang.  </p>
<p>When I suspended or removed ThreatFire, the problems immediately went away.  Strangely, as I noted above, adding the MySQL binaries to the exclusion list did not help.  What was more interesting is that ThreatFire did not popup any warnings.  Usually, when &#8220;suspicious behaviour&#8221; is detected, ThreatFire will prompt you for a decision.  I did not notice any of this.</p>
<h3>ThreatFire is not bad</h3>
<p>The purpose of this is not to bash ThreatFire; it&#8217;s clearly a good tool and has definitive advantages, but just may not be well-suited to development environments where multiple servers are running.  I also wanted to provide this information to anyone else who may have been struggling with a slow/unresponsive server because of the same situation as mine.</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/04/12/threatfire-hanging-or-slowing-down-mysql/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>
	</channel>
</rss>
