Skip to content

Step by Step: A Mortgage Calculator using GWT

The following couple of posts are a first for my blog. I have blogged about client projects before, but never have I been paid to do so. But, I currently have a client who enjoys my blog. He also is a big fan of the Google Web Toolkit, and is interested in exploring the usefulness of this toolkit to his website, Colorado HomeFinder (Updated 6/10 with the name of the client, per his request). (Disclaimer: everything I say on this blog is my fault and mine alone.)

So, in the interest of exploration, I’m going to be building a simple mortgage calculator. We’ll be using GWT 1.0.21, developing on Windows XPSP2 and integrating with a existing backend built using Expresso 5.3, a heavyweight open source framework. (I’ve used Expresso before, and written about it, and while the framework is not without its warts, it can be very useful.) I will also be using Eclipse 3.1 to build the code, and be deploying to Linux. FireFox 1.5.0.4 and IE 6.0 (both on Windows XPSP2) will be used to test the application.

I’ll be documenting my missteps and lessons learned as I go. In addition, the client has kindly offered to let me distribute the source on my website, so I’ll be providing a download each step of the way.

Update, Aug 9: Here’s a list of what I’ve written:

Google does spreadsheets

Check out spreadsheets.google.com. Limited time look at what javascript can do for a spreadsheet. I took a quick look and it seems to fit large chunks of what I use Excel or calc, the OpenOffice spreadsheet program, for. Just a quick tour of what I such spreadsheet programs for, and what Google spreadsheet supports:

  • cut and paste, of text and formulas
  • control arrow movement and selection
  • formatting of cells
  • merging of cells and alignment of text in cells
  • undo/redo that goes at least 20 deep
  • sum/count
  • can freeze rows
  • share and save the spreadsheet
  • export to csv and xls

On the other hand, no:

  • dragging of cells to increment them (first cell is 45, next is 46, 47…).
  • using the arrows to select what goes into a formula–you can type in the range or use the mouse

Pretty decent for a web based application. And it does have one killer feature–updates are immediatly propagated (I have never tried to do this with a modern version of Excel, so don’t know if that’s standard behaviour). Snappy enough to use, at least on my relatively modern computer. I looked at the js source and it’s 55k of crazy javascript (Update, 6/9: This link is broken.). Wowsa.

I’ve never used wikicalc but it looks more full featured that Google spreadsheets. On the other hand, Google spreadsheets has a working beta version…

This and the acquisition of writely make me wonder if some folks are correct when they doubt that Google will release a software productivity suite. (More here.) Other interesting comments from Paul Kedrosky.

I know more than one person that absolutely depend on gmail for business functionality, which spooks me. And in some ways, I agree with Paul, it appears that Google “…takes a nuclear winter approach wherein it ruins markets by freezing them and then cutting revenues to zero.”

Personally, if I don’t pay for something, I’m always leery of it being taken away. Of course, if I pay, the service can also go away, but at least I have some more leverage with the company–after all, if they take the service away, they lose money.

Bloglines and SQL

I moved from my own personal RSS reader (coded in perl by yours truly) to Bloglines about a year ago. The main reason is that Bloglines did everything my homegrown reader did and was free (in $ and in time to maintain it).

But with over 1 billion articles served as of Jan 2006, I always wondered why Bloglines didn’t do more collaborative filtering. They do have a ‘related feeds’ tab, but it doesn’t seem all that smart (though it does seem to get somewhat better as you have more subscribers). I guess there are a number of possible reasons:

  • It’s easier to find feeds that look like they’d be worth reading (I have 180 feeds that I attempt to keep track of)
  • blogrolls provide much of this kind of filtering at the user level
  • privacy concerns?
  • No demand from users

But this article, one of a series about data management in well known web applications, gives another possible answer: the infrastructure isn’t set up for easy querying. Sayeth Mark Fletcher of bloglines:

As evidenced by our design, traditional database systems were not appropriate (or at least the best fit) for large parts of our system. There’s no trace of SQL anywhere (by definition we never do an ad hoc query, so why take the performance hit of a SQL front-end?), we resort to using external (to the databases at least) caches, and a majority of our data is stored in flat files.

Incidentally, all of the articles in the ‘Database War Stories’ series are worth reading.

Using Grids?

Tim Bray gives a great write up of Grid Infrastructure projects. But he still doesn’t answer Stephen’s question: what is it good for?

I think the question is especially relevant for on demand ‘batch grids’, to use Tim’s terms. A ‘service grid’ has uses that jump to mind immediately; scaling web serving content is one of them. But on demand batch grids (I built an extremely primitive one in college) are good for complicated processes that take a long time. I don’t see a lot of that in my current work–but I’m sure my physics professor would be happy to partake.

Verifying the state of an image download in an javascript event

Well, I was going to write a rant, explaining how as far as I could tell, there was no way to make sure an image was downloaded, or degrade gracefully if it wasn’t–within an event like onclick. But, it all boils down to the fact that there is no Thread.sleep() equivalent in javascript. See this for a fine explication or read on for an overview of what I tried that failed.

The problem is that the only real way to do it in javascript is to use setTimeout (Mozilla docs, IE docs). The problem with setTimeout is that after calling it, your event handling code merrily continues to execute, and that your setTimeout callback will probably not finish before the event code is finished.

The other way I thought of was to loop waiting for a specified number of seconds (like this). Unfortunately, in my tests, the javascript engine in IE6 doesn’t appear to be multithreaded, and while this wait code executes, the image is not being downloaded.

I did not try the modal window approach, or the java applet (which seems a bit like using a sledgehammer to hit a mosquito) outlined here, but I’m not sure that either of those is really production ready (I’m not alone).

Familiarity Breeds Content

With tools, at least.

James Governor raises an interesting question: Is Smalltalk Set for a Renaissance. He discusses some of the new things that are being built on this old language.

However, the most interesting thing to me is his comment, the title of this post, that ‘familiarity breeds content’ for tools. I’ve touched on this 2 years ago, when I wrote why I thought struts would be around for a good while. Incidentally, history has shown me out–currently there are 1958 hits on dice for ‘struts’, compared to 58 for ‘webwork’ and 29 for ‘ruby on rails’. (Past performance is no guarentee of future results…)

Of course, that’s no judgement on the benefits of the tools; badly written cgi scripts are still around too. In fact, part of a developer’s job, I believe, is to at least play around with new tools and options that may make them more productive. The important takeaway is that, just as many users are reluctant to change office suites, even to upgrade, many developers have enough on their plates without learning new tools.

Book Review: What Just Happened

I recently read ‘What Just Happened’, by James Gleick. I’m a big fan of his–I read ‘Chaos’ years ago. This book covered the history of chaos theory; I was engrossed by the fluid writing and deft handling of such a tough subject.

‘What Just Happened’ is not such a book–rather than a coherent look at recent history, this book is a collection of stories spanning that time (from 1992 to 2001). From spam to bugs to online pornography to passwords to email forwards, Mr Gleick covers a number of issues that are still relevant for us today. I will say that the number of forwards I’ve gotten since I left college has fallen dramatically, but the amount of spam has not. The internet still ‘makes it all too easy to fling random illiterate drivel across the planet’.

There are also a number of neat historic references. There is a five page article about Y2K, written in Jan of 1999, where Mr Gleick was already saying that we had nothing to worry about come 1/1/2000. Another suggests ways to ‘make Microsoft for capitalism’, written just around the release of Windows 95. Remember when we thought we could count on the US government to deal with monopolists?

On a personal note, I have to link to Zia Consulting, because one of their principals was mentioned in this book; you could apparently page Bindu Wavell over the Internet in December 1995.

The format of this book makes it a nice bus read. None of the articles are longer than forty pages and many are a good deal shorter. Whether you nod your head in agreement with some of the issues covered that are still present, or are wistfully transported back to the days when you were still interested in checking the status of a Coke machine over the Internet, this book has its moments. If you enjoy pop tech at all, or if you’ve been caught up in the wave the Internet has created over the past 15 years, chances are you’ll enjoy this book.

“What Just Happened” at Amazon.