Monday, March 31, 2008

Ruby on Rails after 3 days

I've been learning Ruby on Rails at work for the past 3 days. I had never really worked with Rails before, though I had certainly read enough to form misguided opinions about what was good and what was bad. After some hands-on experience, I have a better idea of what I do and don't like.

Routes

Routes are Rails' way to find the handler for a given request. You can establish routes by editing routes.rb. I don't know whether this is common practice, but an advantage of using a Ruby source file over XML is that you can use Ruby language and library features. This makes it easier to add conditional or generated routes, something that the Rails REST support does with abandon.

Routes are also 2-way. They are also used when you want to know the URL to a particular controller/action. This makes virtually impossible for your URL recognition and URL creation code to get out of sync.

RJS

RJS is Ruby's javascript-generation library. It's used as part of infrastructure for AJAX applications. Most of the Ruby AJAX tutorials that I've seen do something that I consider to be very bad practice - they run code on the server that doesn't need to be. The typical pattern seems to be to use an RJS helper method to emit Javascript that attaches a listener to some other HTML element. This listener then issues an XmlHttpRequest to the server, which produces Javascript code. This code is then sent to the client, where it is eval()'d. While there is nothing wrong with that pattern per se, imagine doing that for something as simple as clearing a text box. Imagine thousands of clients contacting the server just so that they can clear their text boxes.

Of course, in typical Rails fashion, there are many ways to use RJS. Rather than use it in response to a lightweight request to the server, you can also use it when you are building up the original HTML page. This can both simplify your application and also increase its perceived performance. Of course, you need to know that you are able to do this.

Unfortunately, the Javascript that is generated isn't that much different from the original Ruby. Compare this RJS Ruby code:
page['query_results'].value = ''
to this hand-crafted Javascript:
window['query_results'].value = '';
I'm generally against code-which-generates-code, and especially when used to avoid learning a new programming language. Web developers usually end up developing a reasonable understanding of HTML, and those in the Ruby community seem to also be reasonably proficient with CSS. I would hate for them to miss out on a fantastic language like Javascript.

Ruby Itself

Finally, Ruby as a language creates some interesting situations. I find its dynamism to be both a blessing and a curse. It's pretty amazing that Aptana Studio seems to be able to "go to declaration" reasonably well. Of course, this only works for methods which are defined statically, in the source code. Some methods are added dynamically (via method_missing or some other black magic of which I am unaware). I believe that it is impossible to even find out what these are - you simply have to know what methods ActiveRecord may have added to your model objects. I'm sure that this gets easier with exposure.

Incidentally, this very dynamism has spawned some very interesting workarounds. Since the routing tables are stored as data, it's hard if not impossible to see the set of routes by looking at the code. However, there is a rake target to see the contents of the routing table:
rake routes
Similarly, the migration nature of Rails database management makes it quite hard to quickly grok the structure of the database. However, Rails generates a schema.rb file which theoretically mirrors the current state of your database schema. Perhaps not strictly necessary, but awfully convenient.

Conclusion

In all, I'm reasonably happy with Rails so far. It's quite different from previous experiences that I've had developing web applications. In a way, it hearkens back to when I was first learning HTML. It was trivially easy to write some HTML and then see what it looked like in a web browser. The code/test cycle was very small. Rails brings the same sort of simplicity to web application development. Rather than spend time writing code, you spend time learning how to write the code in the correct Rails mindset.

I don't know if Rails will scale well. I don't know if Ruby will be able to keep up. I don't know if ActiveRecord will strangle us or liberate us. However, I do know myself, and I know that I will stay skeptical for quite some time. Hopefully, one day I will realize that I've been happily writing Ruby code for years and find that neither it nor Rails have failed me.

Tuesday, March 11, 2008

Windows Home Server

I just received my HP MediaSmart Server (actually, the EX470). I've just finished setting it up and playing with it a bit.

Here are some problems that I encountered:
  1. To get my VMWare Windows XP instance on my Macbook Pro to see the WHS, I needed to put the network connection into Bridged mode.
  2. It didn't initially work with my Airport Extreme base station, but there is a solution (and not a bad solution at that).
Here are some of my findings:
  1. It appeared to be cheaper to buy an extra 500GB drive (even the exact same drive as is in the server) than to buy the EX475. The drive that is in the first slot is a 500GB Seagate ST3500630AS (Newegg search).
  2. It runs IIS 6.0, ASP.net 2.0.50727, PostgreSQL 8.2.1.7007, Firefly media server (build 1.1 svn-1601), .NET 2.0 SP1, and Java 1.4.2_13
  3. Though it is preferable to administer the server only via the Home Server Console and the shared folders (for adding Add-Ins), it is also possible to remote desktop to the server and get a full Windows shell, start menu and all.
  4. The HP Photo WebShare web application appears to be written in Java, and is being served by Jetty under IIS using isapi_redirect.dll. If I knew anything about Jetty or about using a Java application server under IIS, I would tell you more. Otherwise, the app looks pretty much crap. It works, but looks very amateurish. Much like most OEM-supplied software that comes pre-installed on your computer. On the bright side, it seems to have an ActiveX control to bulk upload images, which is a very nice (and essential) touch.
If you don't get giddy about the idea of an extensible, autonomous, unobtrusive computing henchman in your domicile, then I suppose Windows Home Server isn't for you. But I personally relish the idea of making my home network a little more than a web browsing gateway. I have great faith in the ability for computers to improve the way we live, and I see this as a very small step towards a seemingly distant, but bright, future.

Monday, March 10, 2008

Changing Microsoft Office 2008 for Mac Splash Screen Registration Information

I stumbled around a bit before finding this solution. From some post:

  1. Quit all Office programs
  2. Delete these files:
    • /Users/<user name>/Library/Preferences/Microsoft/Office 2008/Microsoft Office 2008 Settings.plist
    • /Applications/Microsoft Office 2008/Office/OfficePID.plist
  3. Start any Office program
  4. Retype your name, company, and product key

It seems that, if you only delete one of them, it regenerates the other.