Nov 16 2006


Neologisms for pattern

Jim Weirich is here at the Rails Edge talking about design patterns. As he and many other people have pointed out, design patterns are language specific. In sufficiently expressive languages, many design patterns become library calls or disappear entirely. For example, does Iterator deserve to be a design pattern in Java? There's an interface for it, after all. Many design patterns have direct library representations in Ruby: Singleton, Observable, Enumerable, etc.

Quite a while back, Peter Norvig proposed some terminology to deal with the gradual disappearance of certain patterns:

  1. An invisible pattern is so much part of your language that you do not perceive it as a pattern. For example, "Encapsulation" is not a pattern in Java.
  2. A formal pattern has an explicit library or macro realization, e.g. Ruby's Observable.
  3. An informal pattern is not captured by the language.

Far too many pattern enthusiasts relish informal patterns, when we should be trying to convert them to formal or invisible ones.

Nov 16 2006


Use class instance variables, not class variables

At the Rails Edge this morning, PragDave spoke out against class variables, and in favor of class instance variables. I totally agree. Look at this code:

  # why I don't like @@attributes
  class Base
    @@shared = 'cattr from base'
    class << self
      attr_accessor :unshared
    def self.shared
    self.unshared = 'attr from base'
  class Derived < Base
    @@shared = 'cattr from derived'
    self.unshared = 'attr from derived'
  class Ouch
    class << self
      attr_accessor :unshared
    def self.shared
  puts Base.unshared
  puts Base.shared
  puts Derived.unshared
  puts Derived.shared
  puts Ouch.unshared
  puts Ouch.shared

Can you guess what this program will do? It demonstrates three of the ways that class variables cause trouble:

  1. The behave differently from instance variables if they are missing.
  2. They are shared across an inheritance hierarchy in a counterintuitive way.
  3. They require a new syntax, when the instance variable syntax is perfect for the task.

But maybe I am wrong. Ola Bini, who says many wise things, appears to be arguing exactly the opposite. Does anybody have a use case where class variables are the best solution?

Nov 16 2006


Pro Ajax and the .NET 2.0 Platform

Pro Ajax and the .NET 2.0 Platform, by Daniel Woolston, attempts to tackle three goals:

  1. explain the history of web development, from start to finish
  2. explain JavaScript
  3. examine the integration Ajax techniques with ASP.NET 2.0

Fortunately, the author is well-versed in ASP.NET development and the idioms and practices that make for well-organized code. If nothing else, the final chapters serve as a good example of what clean, modular ASP.NET can look like. But it is very much better than that. The book provides a wonderful, ground-up walk through of integrating the major Ajax frameworks for .NET into your application. Particularly, he does a great job with demonstrating the marshaling of data back and forth between the server and browser, and dealing with the architecture of your handles/URLs on the server to deal with the non-standard request patterns in Ajax apps.

Less-(or perhaps un-)fortunately, the author also suffers from a common ailment in books of this genre: provincialism. The opening chapters of the book were riddled with examples of the author's lack of experience outside his chosen platform. I won't be a jerk and do a point-by-point analysis of what turned me off, but instead just provide three examples.

In the first chapter, as he is describing the inception of the web, he refers to the first browser as the "Mozilla" browser from NCSA. Three times. Could be a search-and-replace problem, but that browser was called Mosaic. Secondly, he admits that he shied away from learning JavaScript for many years because he just assumed it was Java, which means that he was dissuaded from even a cursory examination of the technology by four letters in its name. And, third, in his timeline for the history of web development, the second major event is "Bill Gates and Paul Allen create BASIC for the Altair". Which might be an important step in the history of ASP, but is hardly seminal for, say, all those people who wrote CGI apps with Perl. In fact, his history of web development only mentions one technology not produced by Microsoft: Netscape.

Now, this doesn't mean that the book is bad. It means, though, that the chapters on actual Ajax implementations are very, very Microsoft-specific. Sure, you say, that's fine, though. Its an ASP.NET 2.0 book, after all. True, but the lack of deep JavaScript coverage, or acknowledgment of alternate strategies, leaves a limited scope to the ideas imparted.

In all, I think the book serves one audience very well: developers who get paid to write ASP.NET code, and aren't looking around beyond their borders. However, I'd love to see a second edition of the book branch out and at least explain the alternate strategies, like incorporating Dojo or Prototype or Rico or some other non-Microsoft framework and really tackling JavaScript as a first-class programming language in its own right.

Overall, for its major purpose, I'd give it an A-. For its two lesser purposes (history and JavaScript), I'll give it a D. If you are starting an Ajax app in ASP.NET 2.0, it is an important book for you. If you want to place the ASP.NET 2.0 tools in context, look elsewhere.

Oct 21 2006


SourceForge is driving me insane

I have had it up to here with the SourceForge Five-Click-to-Download Exploding Head Technique. Can't I just click the "Download my silly script file here" link and, you know, GET A FILE? ARRRGGGHHHHHHH!!!!

Oct 04 2006


"Continue" snippets in your IDE

When I have a few minutes of down time, I like to browse the snippets in TextMate--it is a great way to discover idioms. I was doing this the other day and noticed that there were two separate snippets for creating a column in a Rails migration. By default, mcc tab completes to

  t.column "${1:title}", :${2:string}$0

So why is there a second snippet bound to mccc that does the same thing? Well, not quite the same thing:

  t.column "${1:title}", :${2:string}

Very cool. I like to think of myself as a power user of IDEs, but this idea had simply never occurred to me. And the "continue" idea is completely general, you can use it in any IDE. (I have been writing "continue" style live templates for IntelliJ IDEA too.)

It could be even better. Why not have the IDE infer "continue" mode for any tab completion with a "c" suffix? Are there any IDEs that do this?

Sep 29 2006


Why DRM Sucks

So I am sitting in an airport shuttle heading from Boston to Framingham. Looks like the ride might take a bit, so I fire up iTunes to play an Audible book on the way.

Oops. I haven't yet enabled Audible for this machine. No problem, I always have the latest tools. In goes the EVDO internet card. Of course I am savvy enough to keep passwords in secure storage, so I even can lookup my rarely used Audible password.

I type in my credentials, to prove that I own what I own, and this comes up: "You cannot enable this Audible account on any more computers. To enable on this computer, you must first remove the Audible account on at least one of the other computers."

Well, thanks a lot. As a power user and a technophile, I go through a lot of computers. Two of the others are in my office in Chapel Hill, backups in case this one goes down. I buy premium (priced!) hardware and software, and I buy lots of it. I am an intellectual property Boy Scout, because it is the right thing to do, and because it is in my professional interest. And what thanks do I get? A big fat "You don't own what you paid for until you travel home and prove it (again)."

Damn it!

Sep 27 2006


Streamlined on JRuby on Rails

I am giving a Streamlined talk tonight at the NovaRUG, and I am giving a JRuby talk next week at the Atlanta No Fluff, Just Stuff symposium. I sense a chocolate-and-peanut-butter opportunity here...

(2 hours pass)

Success. Following Charles's instructions here, I got JRuby, Rails, and a Rails scaffold up and running without major incident. Streamlined, however, balked at the code generation phase. I posted a question on the jruby-user list, and within minutes had the answer from Charles: the following syntax is not OK in JRuby, and apparently will be removed from Ruby 2.0 as well:

  "Use authentication, and choose library (AAA)") {|options[:auth_lib]| }

A quick regexp replace to this form did the trick:

  "Use authentication, and choose library (AAA)") { |val| options[:auth_lib] = val }

Note: Typo mentioned in the comments has been fixed. Thanks Jim.

Streamlined (trunk or 0.0.6) now runs on JRuby on Rails. Bring on those funky enterprise databases!

Sep 22 2006


Java Concurrency at NovaJUG

I'll be giving a talk on Java Concurrency at the NovaJUG ( Bad expect jokes conditions race about!

Afterwards I will show David how to get Tomcat off port 8080. :-)

Sep 22 2006


Relevance Review #11: Ajax Design Patterns

I approached Ajax Design Patterns, by Michael Mahemoff, with some trepidation. I am suspicious of design patterns, because like many useful ideas, design patterns are often overused, followed dogmatically, or used as a substitute for understanding.

I needn't have worried. Ajax Design Patterns (ADP) is an excellent book, and for many people may be the best Ajax book currently available. There is a lot of solid technical advice. Michael knows, and knows how to explain, JavaScript and Ajax. But the technical details are only the foundation. Michael uses the vocabulary of patterns to continually ground Ajax in usability. Ajax is never just for Ajax's sake, but always about improving the user experience in some way. It is fairly easy to find the technical details OR the design focus, what's nice here is that ADP gives you both, and the technical details are in service of design goals.

Michael isn't afraid to bend the definition of "design pattern" where it makes the book more useful. Ajax programmers need to know the diagnostic tools that are available, so that gets a chapter. The JavaScript world urgently needs better unit testing, so that gets a chapter too.

The book packs an enormous amount of information. It is probably heavy for a beginner, but ADP does a great job of starting at the beginning and moving all the way to advanced topics. There are tons of references throughout, so ADP functions not just as a book but as a roadmap.

Finally, there is one particular detail that I loved about this book. Rather than bury me under sample code, the samples include just enough code to make the point. The complete sample code is online, so this tradeoff is perfect for me. If you are looking to work through the code in the book yourself, you will have to fill in the blanks or get the code online.

This book joins my other favorites, Ajax in Action and Pragmatic Ajax. Now if somebody could please write the killer "JavaScript: The Language" book...

Sep 20 2006


Testing JavaScript

Thomas Fuchs has posted his slides from RailsConf Europe. Very nice stuff: unit testing, BDD, debugging, multi-environment setup, tools.

Now if somebody would just open-source an add-on that runs the tests in Spidermonkey or Rhino, we would have CI goodness for JavaScript. :-)

Popular Tags