Saturday, November 25, 2006

AJAX tools for multiple development platforms

I feel like I have come full circle (almost) in AJAX development: I started out a few years ago adding some simple AJAX enabled forms to a JSP based application. When first starting out, it took hours to get something working. Then a year ago, I discovered how simple it is to use AJAX in Rails: fine, except that Ruby does not have high enough performance for some applications (unless large parts are written in C - Ferret, for example).

I have spent many evenings playing around with various release versions of the Google Web Toolkit (GWT) and it is very compelling, especially if you already are used to developing GUI applications in Java - the only new wrinkle worth mentioning is getting used to handling events asynchronously. The problem with GWT is that it really does tie you to the Java platform. I spend most of my time developing AI applications, but that said, who does not want basic knowledge and competence at building web applications?

I use Common Lisp, Java, and Ruby for development, so for the occasional AJAX tasks that I have, I have settled with the well respected dojo Javascript toolkit because it plays very well with both Lisp and Java JSP based web applications. Dojo is also easy to use with Rails, if you want an alternative to Rail's great AJAX support.

By using Dojo, I basically have to deal with just one learning curve no matter what platform I am developing on. Here is a simple example for a JSP page (assuming that this would be more interesting to most people than a Lisp example):

Add this to your <head> section on a top level JSP page:

<script type="text/javascript">
var djConfig = { isDebug: true };
<script type="text/javascript" src="dojo.js"></script>
<script type="text/javascript">
Then try putting this somewhere on your JSP page (note: this assumes that you have another JSP page ajax.jsp that gets the form values and returns content to be placed into the DIV element with ID=ajxplydiv. Anthing that ajax.jsp writes using out.print() gets inserted asynchronously into the "ajxplaydiv" DIV element):

<h3>test AJAX Form:</h3>
<form id="myForm">
<input type="text" name="input_test_form_text" />
<input type="button" name="button1"
value="Try AJAX form" id="ajaxButton" />

<div id="ajxplaydiv">
initial context for AJAX play div

<script type="text/javascript">

var buttonObj = document.getElementById("ajaxButton");
dojo.event.connect(buttonObj, "onclick",
this, "my_onclick_button");

function my_onclick_button() {
var ajaxargs = {
url: "ajax.jsp",
load: function(type, data, evt){
dojo.byId('ajxplaydiv').innerHTML = data;
error: function(type, data, evt){
alert("Error occurred!");
mimetype: "text/plain",
formNode: document.getElementById("myForm")
The call to sends a request containing the form data to the ajax.jsp page, and whenever the results are returned then the Javascript functions "load" or "error" defined in the data block in my_onclick_button() is called. This is just one example of processing form data and adding HTML below the form without refreshing the page - but is a common use case for using AJAX. This example assumes that I have both the dojo "src" directory and dojo.js in my top level web resources directory. The great thing about dojo is that it encapsulates all asynchronous event handling, offers a good supply of visual components (that map to HTML elements) and is simple to use no matter what programming language you are using for a web application.

Monday, November 20, 2006

'Perfect' Mac OS X backup procedure

Backing up my user files under Linux is easy, if everything in /home/mark fits on a DVD-R. A Linux re-install is quick and then overwrite /home/mark. I usually install applications that I build from source in my ~/bin directory and Ubuntu's package manager makes it quick enough to restore other required apps (PostgreSQL, etc.)

The Mac is not so simple because installed applications store frameworks in the system library, etc. Still, it it easy to make a reliable backup, assuming that you have an external FireWire (or I suppose an USB) disk drive:
  • Make sure that there is room on your external disk for your home directory and another 5 gigs
  • Plug in your external backup disk, and restart with your install DVD
  • Install OS X, choosing the external drive
  • When the installer asks if you want to import previous user data, say yes and select your internal disk that contains your system and user account
  • Reboot using your external disk and run software update
  • Pack away your external disk as a backup of your working environment - preferably off site for extra protection.
If you run this procedure while you are reading or watching TV, this is a low overhead operation - cumulatively just takes about 10 minutes of time (about 1 hour wall clock time). An external disk can obviously also contain other backups of large video files, etc. in addition to your OS X and user setups.

Nothing is for sure in life, but external disks are likely to have longer shelf life for your digital assets than CDR-R and DVD-R media, but using both, and off site backup on remote servers, etc. is also a good idea.

Because of the (hopefully) very high reliability of external FireWire (or USB) disk drives, I also copy important Windows and Linux backup files to an external disk using either my LAN or DVD-R backups. Replicating really important files to multiple computers on your network using rsync is also a good idea.

Sunday, November 19, 2006

Offshoring vs. increasing the number of H1-B visas

I believe in a world economy, so if safeguards are in place that penalize corporations for unfair treatment of workers in areas with much lower cost of living, then I definitely support the concepts of off-shoring "white color" jobs and manufacturing jobs. I would like to financially penalize corporations for moving work to take advantage of a lack of local environmental laws. Business should be done in the least expensive and most productive way possible, but we need to factor in the importance of maintaining good working environment and environmental standards.

Although I support, with some small caveats, off-shoring work when it makes economic sense, I am very much against greatly increasing the number of allowed H1-B visas. I have heard too many stories of abuse of imported guest workers. For those H1-B workers that we allow in to the US every year, I think that they should be free to job hop, and try to maximise their salaries as can US citizens. Unfairly treating H1-B guest workers also has the effect of artificially lowering salaries for US workers - a bad thing. It might not seem fair, but I would allocate H1-B visas based on excellence - with the view that it is likely that many of these people will eventually become citizens and why not attract the very smartest people?

There is one thing that I would like to see done to help US workers, present and future: during the Bush administration we have seen a huge shift of wealth to the very richest via tax cuts and some sectors of the economy to support the war in Iraq. I would very much rather have seen most of this money not spent at all (smaller deficits!) and a little of it (perhaps 30%) spent for more effectively preparing our country for dealing with 4th generation war (nation state vs. organized groups) and to provide more scholarships and extended education funds for US workers.

Ha! Compare Nintendo Wii to Sony PS3 rollouts!

I am a bit biased, having worked on two Nintendo U64 games (mostly game AI). That said, Nintendo seems to be doing everything right:
  • Concentrate on game play: Shigeru Miyamoto (who was at Angel Studios the first morning that I started there - many years ago) felt that the key to better game play was a new controller metaphor, not expensive graphics hardware. Start with a concept (game play/controller vs. graphics hardware) and carry that through from development to launch
  • Profitable console! Compare to > $200 loss on selling PS3 console.
  • Launch with sufficient units: satisfied Nintendo customers vs. many disappointed Sony customers
Well done Nintendo. While I sometimes enjoy gaming on my Sony Portable Playstation, I was disappointed by the very high cost of movies in the UMD format. While I am tempted to buy a Wii (my stepson, son in law, and grandson will all be visiting for Christmas, and a new gaming machine would be fun for us!), I am not inclined at all to buy a PS3.

Friday, November 17, 2006

New World Order: things that will effect its outcome

I was reading people's opinions on Slashdot this morning about Microsoft's indirect attack on Linux through Novell and saw an example of the New World Order at work: an entrenched corporation fighting against a distributed movement for free and open source software. If you enjoy history, then you know that the rich and powerful have always bought and influenced governments but I believe that the New World Order of Corporate Power is something different:
  • More transparent: with the Internet, it is too difficult to contain information and free speech - a good push-back against corporate consolidation and control of news media for their own interests. With more transparency, it is possible for people to be more aware of corruption and control.
  • The world is even less of a "zero sum game". When Spain recovered huge deposits of gold, emeralds, etc. in the New World, they increased the money supply (gold) but also spurred other European nations to other areas of technological inferiority that had valuable resources. Although slowed down by energy costs, we now see opportunities around the world open up - someone winning does not always mean that someone has to lose. (In the context of this blog: I see a win-win situation between proprietary software and with free and open source software, with competition between the two approaches as a good thing.)
  • Countries/corporations that move early to alternative energy sources will have a large long term advantage as the price of oil increases
  • Real value vs. vapor: with the fiat U.S. currency (I have seen estimates that the privately owned Federal Reserve has increased the supply of dollars by about 20% so far this year - the cost of printing money is much less than the current "value" of money!) common people do not own much real equity value: any money they hold has dubious value when a private group of individuals has control over inflation, etc.; people tend to not have much real equity anymore in their homes and are at extreme economic risk when inevitable real estate value crashes occur (they always occur - it is just difficult to say when they might occur). Real value is in industrial production capability, education that enables "high up the food chain" employment and entrepreneur-ship, intellectual property, trade and business partnerships, etc. It is not difficult to see that except for high valued education/job skills and the entrepreneurial success stories, that most real value lies in the control of large corporations and the individuals who have capital and ownership of these corporations.
  • Formally third world countries are enjoying a major upswing in the percentage of middle class workers while established industrial nations are seeing a greater separation between the very rich and a shrinking middle class and the poor. This is natural: areas of very low cost of living that can supply well educated and motivated workers draw in business development, research and development, manufacturing infrastructure.
I think that as much as the world looks more "global", that we will see a huge difference in economic success between countries (and trading blocks that share laws affecting business and trade) that either:
  • Allow corporations to do business but do impose minimal laws to encourage business growth at all levels. Or:
  • Allow corporations to do business and through corruption or other processes discourage business growth and development for all but the largest corporations.
Minimal government is best but some government and fairness in laws and enforcement of laws is required to maximize economic growth and the general good.

I believe that in the future talented people will naturally migrate to countries that provide minimal but fair government and give people good value for their (hopefully small) taxes. Countries like the USA (my country) where a very large fraction of people's federal income taxes goes to pay interest (on previous government expense overruns) to the private individuals who own the Federal Reserve will be at a competitive disadvantage as taxes have to keep rising to pay off previous debts. In a very real sense, government spending overruns enrich the most wealthy people. Small surprise.

What can people do to build more value instead of vapor? A few things come to mind:
  • If possible prefer to reside in regions of low tax and high economic growth.
  • Prefer more education to less. Prefer training in high skilled jobs that must be performed "on site" and can not be done remotely.
  • Prefer investment in corporations with real production value, real property, scarce resources, etc. Prefer to not take out a second loan on your home to buy a new SUV that is better than the one your brother in law bought last week.
The great thing is that we all have control over our decisions in life. While external events can affect the results of our decisions, we still get to decide how to allocate our personal resources and how to live our lives. Self Responsibility = Self Empowerment.

Monday, November 13, 2006

GPL license for Java

This is a good thing, to be sure! However, I have to wonder how this might affect Sun's revenue for Java in embedded devices, etc. Sun has a huge investment in Java and as a corporation they really do need to generate revenue from Java.

One thing that I would like to see happen is tight JRE integration with Linux systems: a mechanism for running a shared JVM instance for small Java utilities and porting Apple's contributions for sharing more memory between JVM instances running on the same system.

Saturday, November 11, 2006

Pricing of Microsoft Windows Vista

Seeing the very high list prices for the "complete" versions of Vista is a little disappointing. I don't use Windows very much, but I find the flexibility of a dual boot Linux/Windows PC to be useful. For my work, I use fairly inexpensive PCs and Macs because except for rare machine learning runs, I don't need many fast CPU cycles for my work. Because I tend to buy low cost commodity PCs, the relative price of an increase in the "Microsoft tax" is noticeable.

If Microsoft does anything to prevent easy dual booting between Linux and Windows, then that will be the day that I stop using Windows (or at least stop buying new PCs with Windows). With the latest version of Ubuntu, I prefer Linux as a development platform even to OS X.

Wednesday, November 08, 2006

Some dissatisfaction with Ruby

I use Ruby a lot for small database tasks (love ActiveRecord!) and for using Rails for some web applications (not with scaffolding, mostly generating controllers and writing my own code).

That said, for a lot of what I do, Ruby is much more than an order of magnitude slower that compiled Common Lisp. I find myself still using Ruby and Java when appropriate, but for most tasks, I am going back to using Common Lisp. Better language, and the learning curve is not so bad (I have been using Lisp for over 25 years, and I am already up to a 'moderate' level of competence :-)

Democratic mandate: investigate corruption

Exit polls shows that 3/4 of voters favored Democratic candidates because of government corruption. I hope that the new House of Representatives lives up to its responsibilities to thoroughly investigate and act on:
  • Illegal lobbying
  • Illegal lobbying by foreign governments
  • Outlaw riders on bills in Congress: lately some obscene riders have been attached to important bills
  • Outlaw voice votes on Bills: let us always know how Congress people vote!
My sincere hope is that no single political party ever again controls both houses of Congress and the Presidency.