<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Terminus a Quo &#187; Java</title>
	<atom:link href="http://abing.gotdns.com/posts/category/code-and-consequences/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://abing.gotdns.com</link>
	<description>Because you can never have too many blogs on the Internet...</description>
	<lastBuildDate>Tue, 19 May 2009 00:23:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ditching PHP: Alternatives to PHP</title>
		<link>http://abing.gotdns.com/posts/2008/ditching-php-alternatives-to-php/</link>
		<comments>http://abing.gotdns.com/posts/2008/ditching-php-alternatives-to-php/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 08:46:03 +0000</pubDate>
		<dc:creator>nimrod.abing</dc:creator>
				<category><![CDATA[Code and Consequences]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://abing.gotdns.com/?p=222</guid>
		<description><![CDATA[You have worked around the quirks and you have lived with the inconsistencies. You have stood by and watched your code fail spectacularly between minor point releases. You scrambled to fix your code&#8217;s dependence on register_globals set to on when they got turned off by default in version 4.2.0. You have lived with the disappointment [...]
<p>a</p>
]]></description>
			<content:encoded><![CDATA[<p>You have worked around the quirks and you have lived with the inconsistencies. You have stood by and watched your code fail spectacularly between minor point releases. You scrambled to fix your code&#8217;s dependence on <code>register_globals set</code> to on when they got turned off by default in version 4.2.0. You have lived with the disappointment when version 5 failed to deliver on better object orientation. There have been a lot of warning signs telling you to look for better alternatives, but still you persevered. Then came the recent changes that really make you shake your head in disbelief. Face it, PHP&#8217;s direction as of late has really taken a downturn. You&#8217;re thinking it&#8217;s time to look for alternatives.</p>

<p>If you are one of those folks who have been using PHP <strong>and nothing but PHP</strong> for a long time you will be hard pressed to find an alternative. PHP is, after all, one of those things that are &#8220;easy to get into, but difficult to get out of&#8221;. PHP lures you in with its forgiving nature, vast library of pre-built extensions, ease of deployment and just plain &#8220;instant gratification&#8221;. It&#8217;s easy to forget that there are other languages for server-side programming/scripting.</p>

<p><span id="more-222"></span></p>

<h2>More Tools for your Toolbox</h2>

<p>When I was teaching CS classes back then, I always told my students <strong>never rely on a single programming language and never tie yourself to a single platform</strong>. I have always stressed the importance of learning more than one programming language and making sure that whatever you do, do it cross-platform if possible. By not limiting yourself to one language or platform, you will be able to develop solutions using the right tools for the problem at hand.</p>

<p>The following is a short list of programming languages that I have used in the past. These are my &#8220;bread and butter&#8221; languages in addition to PHP. These are also the reasons why I found it easy to ditch PHP. If you have never used any other programming language besides PHP, perhaps you should take a look at what else is out there.</p>

<h2>One Interface Behind Them All</h2>

<p>In theory, you can use <strong>any</strong> programming language to do server-side programming. You read that right: you can use any programming (or scripting) language. You can use C, C++, Fortran, Haskell, Java, Lisp, Lua, Perl, PHP, Python, Ruby, and so on. You can use whatever you want, as long you are able to receive input and send output via the Common Gateway Interface or CGI.</p>

<p>Server-side programming/scripting essentially involves two basic operations:</p>

<ol>
<li>Receiving and acting on a <strong>request</strong>;</li>
<li>Sending back a <strong>response</strong>.</li>
</ol>

<p>CGI acts as a bridge between your web server and your server-side program/script. When your web server receives a request and it sees that request as a request to execute a program/script on the server, it will set up everything that is necessary to run your program/script. It then runs the program/script, captures its output, if any, and sends it back to the client who issued the request. In Unix terms, any program/script that can take input from stdin and send output to stdout can be used on a web server that supports CGI. This is an overly simplified description. If you wish to learn more about CGI, use <a href="http://www.google.com/search?hl=en&#038;q=common+gateway+interface">&#8220;the Google&#8221;</a>.</p>

<p>Because the server runs the CGI program/script as an external process to handle each request, this means that there is an overhead for each request. To boost performance, modern web servers have come up with ways of eliminating or reducing the overhead from external process creation. For instance, Apache allows you to create modules that act as filters and handlers for requests. In most cases, PHP will have been installed as an Apache handler on your server which embeds the PHP interpreter in the running Apache process, eliminating the need to create an external process to run your PHP script. There is also an extension to the CGI standard called <a href="http://www.fastcgi.com/">FastCGI</a> which takes a different approach. FastCGI runs several instances of your program/script as long-running background processes. The webserver then connects to these processes whenever a requests requires the use of CGI, sends the request and collects the response and sends it back to the client.</p>

<p>Of course, these days you care less about the details and worry more about what your program/script does.</p>

<h2>Is it &#8220;Programming&#8221; or is it &#8220;Scripting?&#8221;</h2>

<p>At the heart of it, programming is programming and scripting is programming using a scripting language. In the early days, it&#8217;s easy to differentiate between &#8220;scripting&#8221; and &#8220;programming&#8221;. Scripts were written using &#8220;interpreted&#8221; programming languages which typically ran inside another program (e.g., CAD with Lisp scripting) or a stand-alone interpreter. &#8220;Programs&#8221;, in the original sense of the word, were written using &#8220;compiled&#8221; programming languages.</p>

<p>These days, the distinction has been blurred with the advent of <strong>compiled</strong> programming languages that are run using an interpreter. Java is just one example of this. You write your Java program and then compile it into machine-independent <strong>byte-code</strong> which you then run using a Java virtual machine or JVM. A JVM is essentially an interpreter but these days, we also have the so-called JVM with Just-in-Time compilation which maps machine-independent byte-code into native instructions for the CPU running the VM.</p>

<p>It&#8217;s all become so confusing these days with all the recent developments in VM technology. The distinction between &#8220;scripting&#8221; and &#8220;programming&#8221; has eroded. Personally I just prefer to call it <strong>programming</strong>. So from this point onwards, I will simply use the term &#8220;programming&#8221; to refer to &#8220;scripting&#8221; as well and &#8220;programs&#8221; to refer to &#8220;scripts&#8221;.</p>

<p>One more thing: Knowing how to write HTML and CSS does not make you a programmer, so please stop calling yourself a programmer or &#8220;coder&#8221; if all you know is HTML and CSS.</p>

<h2>The Duct Tape of the Internet</h2>

<p>Let&#8217;s begin with the grand daddy of server-side programming: <a href="http://www.perl.org/">Perl</a>. Created by Larry Wall in 1987, it has evolved into a true, general-purpose programming language. It was developed primarily to automate system administration on Unix systems. It began to gain popularity in the early 1990&#8217;s as a convenient way to write CGI scripts. PHP can trace it&#8217;s origins back to a CGI script written by Rasmus Lerdorf using Perl. That&#8217;s right, a scripting language begat <em>another</em> scripting language. You can see shades of Perl in PHP, the most visible is the use of the $ symbol to start a variable name.</p>

<p>Perl may come across as a quirky, cryptic language to some. It has also been the butt of jokes in recent times with the advent of newer (and sexier) programming languages. The Perl mantra TIMTOWTDI (there is more than one way to do it) is both a blessing and a curse. Take printing a progress bar for example. As one person found out by asking the Perl monks, <a href="http://www.perlmonks.org/?node_id=396839">TMTOWTDI</a>. But make no mistake. Perl is a very powerful language, with a friendly community and a <a href="http://cpan.org/">huge library of pre-written modules</a>.</p>

<p>The standard Perl installation comes with the CGI module which allows you to get up and running with CGI very quickly. You can use Perl to write a simple CGI script without using the CGI module. However, using the CGI module frees you from having to deal with a raw CGI environment. It also gives you with useful functions for handling query strings and forms, URL escaping, and error handling.</p>

<p>It also comes with a standard for database interfaces and drivers (DBI and DBD). DBI will usually come pre-installed along with commonly used database drivers. If you are familiar with ODBC or if you have played around with PDO, the Perl DBI is similar in spirit. It provides you with a consistent interface for database access and more importantly, it gives you <strong>prepared statements</strong> even if the underlying database does not support it.</p>

<p>More importantly, most virtual hosting shops support already support Perl in addition to PHP. You will probably have two options, depending on your hosting provider. First option would be to write your programs as just plain CGI programs and upload them to a special directory on your account. Second option would be to write your program to take advantage of <a href="http://perl.apache.org/">mod_perl</a> if it is installed by your hosting provider. mod_perl not only allows you to write CGI programs, it also allows you to create Apache modules using Perl.</p>

<h2>Over-Engineered Beyond Help</h2>

<p>Next up we have the programming language that no self-respecting software &#8220;engineer&#8221; can do without: Java. Although it has all the required facilities needed to write CGI programs, if you must do something in Java, you should do it properly. And the proper way of server-side programming in Java is to write a Java Servlet. In order to do that, you need to run it inside a Servlet Container such as <a href="http://tomcat.apache.org/">Apache Tomcat</a>.</p>

<p>Java already has database connectivity covered with its standard JDBC. Odds are that your servlet container can also run JSP&#8217;s which allow you to embed Java code in your markup. Your servlet container then takes these JSP&#8217;s, compiles them into a servlet when handling the first request and uses the compiled servlet to handle subsequent requests.</p>

<p>As you have probably learned by now (or not), it is better to separate your program into distinct areas using the Model-View-Controller paradigm. Java supports this out of the box. You have POJO&#8217;s (plain old Java objects) to use for your model. The servlet serves as controller. JSP provides you with the view. Once you have the basics nailed down, it&#8217;s all very simple onwards. Or not&#8230;</p>

<p>As your program grows in size and complexity you will find the simple MVC approach using POJOs, servlets and JSP&#8217;s become unwieldy at best. You will be looking for a better solution. Java has a standard for developing large scale web applications too. J2EE is a collection of standards that encompass everything you need to develop large scale web applications and service oriented applications (SOA&#8217;s). Newbies will probably be overwhelmed by the amount of complexity involved in developing and deploying large-scale apps using J2EE. It has more acronyms than a bowl of alphabet soup. Once you&#8217;ve finished wading through your acronym soup, prepare to swim in XML tag soup. Almost everything in a J2EE server is configured using XML. But then again, developing and deploying a large-scale J2EE app was never meant to be a job for a lone developer and there are tools you can use to tame all that XML.</p>

<p>As for hosting your Java apps, typically you need to find a specialized hosting service of which there is no short supply.</p>

<h2>Ooooooh! Shiny!</h2>

<p>Then there&#8217;s <a href="http://www.ruby-lang.org/en/">Ruby</a>. First released to the public in 1995 by Yukihiro Matsumoto, it was an obscure programming language from Japan that exploded in popularity in recent years (due to a well-marketed web programming framework). As one fellow so succinctly put: &#8220;Ruby is the language for trendy, non-conformists.&#8221;</p>

<p>Ruby by itself is a very capable language with a large set of libraries included as standard. The CGI library is one of them so you can also get to writing server-side programs in no time. Like Perl and Java, it also comes with a standard library for interfacing with databases.</p>

<p>I tried Ruby some time early last year but I find its reliance on on <code>begin</code> and <code>end</code> to be a major annoyance at best. That&#8217;s the reason why I hated programming in Pascal and VB so much. Come on, if braces worked for C, C++, Java, Javascript, Perl, PHP, etc. why bother using whole words to delineate blocks of code? Another sticking point, at least at the time, was performance. For small one-off scripts, it&#8217;s pretty decent. However, for larger more complex programs which are spread across several files, performance really sucks! The time it takes to launch the interpreter, byte compile your code and run it was simply unacceptable for me. If you&#8217;re going to use Ruby for CGI programming, use FastCGI or some other way of keeping a cached copy of your byte-compiled code in memory.</p>

<p>With those two aside, I find some features that make Ruby hard to resist. There&#8217;s &#8220;monkey patching&#8221;. Ruby classes are open classes. This means two things: you can spread class definitions across multiple files and you can modify built-in or standard library class behavior. Being able to spread class definitions across files helps to make your code more manageable as it grows in complexity and size. By modifying behavior of built-in or standard library classes you&#8217;re able to create semantics that are more suited to the job at hand. This can also be a problem, especially if your program is reliant on third-party libraries, as it is possible that the modified behavior is not what you really want. But when done carefully, it can extend the usefulness of existing classes (like to what <a href="http://mootools.net/">Mootools</a> does for Javascript).</p>

<p>Ruby also makes it relatively simple to map data from a text file or database record into a dynamically generated class at run-time. This proves useful in creating ORM&#8217;s (object-relational mappings). Most Java ORM&#8217;s use a clunky approach glued together with unholy amounts of XML. Ruby makes it easy by providing the facilities necessary as built-ins.</p>

<p>Another great feature is class composition. This is similar to the concept of interfaces and mixins in other languages. You define a set of methods and properties in a <code>module</code>. When you need them in your class, you simply <code>include</code> the module.</p>

<p>As for finding hosting providers that support Ruby, thanks to a popular web programming framework, most hosting providers now support Ruby in addition to PHP and Perl. Just like Java however, you can get better bang for your buck by going with a specialized Ruby hosting package.</p>

<h2>Batteries Included</h2>

<p>Now we come to my programming language of choice: <a href="http://www.python.org/">Python</a>. While using whitespace to delimit blocks of code may seem strange to those who come from the &#8220;bracketed&#8221; programming languages such as C, Java, Perl or PHP, it actually makes your programs easy to read <strong>by default</strong>. You don&#8217;t need to remember any silly coding and indenting conventions. As long as you use a consistent means of indenting your code (4 spaces is recommended), you are pretty much set when it comes to readability. It was a bit uncomfortable at first but blocks delineated by indentation sort of grows on you eventually.</p>

<p>With that <strong>single</strong> &#8220;unusual&#8221; quirk aside, Python has all of the tools you need to get started with server-side programming: &#8220;Batteries Included&#8221;. Simply <code>import</code> the cgi module in your code and start plugging away at your program. However just like in Java, there is a standard way of doing things and the standard way of server-side programming using Python is through the use of <a href="http://www.python.org/dev/peps/pep-0333/">WSGI</a>. Python&#8217;s WSGI is similar in spirit to Java&#8217;s Servlet specification. It defines a standard way of writing programs that have to interface with a web server using a request-response model. It takes the server&#8217;s execution environment, the client&#8217;s request, and the server&#8217;s response and packages it into one coherent specification.</p>

<p>One more thing that I like about programming in Python is that your program sort of describes itself. You spend less time writing descriptive comments as to what a section of your code does, unlike other programming languages. Chances are that you can write a Python program now without any documenting comments, come back six months later and look at your code and you will still be able to read and understand what it does.</p>

<p>Performance-wise, Python has consistently outperformed PHP and Ruby as of late. Python programs are compiled into byte-code before it gets executed by the Python VM (interpreter) just like Java. However, unlike Java, there is no explicit compilation step necessary. Unlike Java, Python can run your code regardless of whether or not it is in the byte-code compiled form. Your byte-compiled Python code essentially acts as an on-disk cache for the VM. When you first run your program, the Python interpreter will byte-compile your code and if it can, it will write the byte-compiled code into a file with a .pyc extension. The next time you run your program, the interpreter will check if there is a .pyc file present. If found, it will check to see if your source file is newer than the .pyc file. If your .pyc file is up to date, the interpreter skips the byte-compilation step and runs the .pyc file instead. If your source file is newer, it will byte-compile it and try to write it to disk. This is another reason why I prefer Python over anything else. I can distribute just the .pyc files without the .py source files. I am all for &#8220;open source&#8221; but there times when you just don&#8217;t want clients to be dicking around with your code.</p>

<p>As for libraries, chances are good that the standard Python installation already has everything you need. Python also comes with a standard for database interfaces called DBI, which like its Perl counterpart, provides you with a consistent interface regardless of what database you are using. It also provides you with prepared statements which can be emulated in the driver in case your database does not support it.</p>

<p>Just like Ruby and Java, you are better off going with a specialized Python hosting package if you are going to do WSGI. If you only need to write CGI programs in Python, then many hosting providers already support Python in addition to Perl, PHP, and Ruby.</p>

<p>So there you have it. I hope this goes to show that PHP is not the be all and end all to programming.</p>

<p>a</p>
]]></content:encoded>
			<wfw:commentRss>http://abing.gotdns.com/posts/2008/ditching-php-alternatives-to-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse 3.4 (Ganymede) First Impressions</title>
		<link>http://abing.gotdns.com/posts/2008/eclipse-34-ganymede-first-impressions/</link>
		<comments>http://abing.gotdns.com/posts/2008/eclipse-34-ganymede-first-impressions/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 05:36:18 +0000</pubDate>
		<dc:creator>nimrod.abing</dc:creator>
				<category><![CDATA[Code and Consequences]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://abing.gotdns.com/?p=186</guid>
		<description><![CDATA[Ever since my last Eclipse 3.3 install broke down due to a botched update, I have given up using it and started using Vim. I still keep an eye out for new developments for the platform though. The recent release version 3.4 codenamed Ganymede had a lot of promise.

I tried the latest version of Eclipse [...]
<p>a</p>
]]></description>
			<content:encoded><![CDATA[<p>Ever since my last Eclipse 3.3 install broke down due to a botched update, I have given up using it and started using Vim. I still keep an eye out for new developments for the platform though. The recent release version 3.4 codenamed Ganymede had a lot of promise.</p>

<p>I tried <a href="http://eclipse.org/ganymede/">the latest version of Eclipse</a> the other night. As usual, I downloaded the &#8220;Eclipse Classic&#8221; tarball for Linux. It&#8217;s an iffy release to say the least, akin to KDE 4.0. There have been major changes in the platform itself. But the most visible part is the way plugins are <a href="http://wiki.eclipse.org/Equinox_p2_User_Interface">managed</a> and <a href="http://wiki.eclipse.org/Equinox_p2_Getting_Started">installed</a>. Personally I had high hopes for the new UI as the old one was a bit unwieldy to work with. Unfortunately, the new UI still needs a lot more work done. The main problem I had with the new UI is that even the plugins that already came with the package I downloaded <strong>still</strong> show up int the Available Software window. There also appears to be a bug where if you check and then uncheck a plugin, it will still install that plugin. There are also some new issues and regressions introduced by the new UI that they still have to work on.</p>

<p>Right now, I&#8217;m back to using Vim. Eclipse 3.4 is just too flaky for me at the moment.</p>

<p>a</p>
]]></content:encoded>
			<wfw:commentRss>http://abing.gotdns.com/posts/2008/eclipse-34-ganymede-first-impressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
