Ruby demo in Seaside: the sequel

Ramon Leon at On Smalltalk has written a couple of posts on how to connect a Seaside application to a database.

First he talks about selecting a database. He chooses PostgreSQL, and talks about his experience in setting it up. He chooses Glorp for object-relational mapping (ORM). Next, he shows how to take his Build-a-blog-in-15-minutes example and instead of using an OrderedCollection to store posts and comments, as was shown in the first demo, he shows how to set up Glorp to interface the blog to tables in PostgreSQL. He also compares/contrasts Glorp with Ruby on Rails’s ActiveRecord framework. Very interesting reading. No screencast this time, but it looks like he posted the necessary code.

Kudos Ramon! This information is really needed.

Pachelbel is the devil!

A while back I said I wouldn’t write about art that often. Not that I don’t like art. I just figured this would be a technical blog and so I wouldn’t think to write much about it. Oh well. So much for that. I found this today and just HAD to post about it. This guy is SO right, in more ways than I once knew. It’s hilarious if you’ve ever been into classical music, or played in an orchestra as I once did. I played Pachelbel’s Canon in D when I took orchestra in junior high school, eons ago. It’s a classic. I didn’t mind it. I thought it was a nice song. I was in the 2nd violin section at the time (I think). I remember feeling sorry for the cellists though. This guy explains why. Let me put it this way. He’s got an extremely bad case of that song you can’t get out of your head.

I had the opportunity to talk to some classical music connoiseurs back then. They also hated Pachelbel’s Canon. I think they were kind of jealous. It gets played all the time, and they think it doesn’t deserve that kind of popularity. Hey, maybe it was a form of pop music a few hundred years ago. Hmm…

The future of programming

For some months I’ve taken time to study dynamic languages, particularly Lisp and Smalltalk. I’ve kind of wondered why though. There is a certain elegance that attracts me to them. I also like the philosophy that Dr. Edsgar Dijkstra espoused, which is that the computer should enable the programmer to express his/her idea to it, and let it figure out how to execute it. That idea sounded great to me. I didn’t quite know what he meant, but I knew it’s something I desired. I knew I liked Smalltalk’s elegance, because I remembered admiring it years ago.

Some time back I read a post by Ramon Leon on domain-specific languages (DSLs), and how Smalltalk fit into that picture. He linked to an online video of a presentation by Martin Fowler, talking about this. It was very interesting. Ramon continued talking about DSLs in subsequent posts. Each time clarifying it in my mind. Over time I’ve come to realize this is the answer to why I’ve been so interested in these languages.

In languages like Lisp, Smalltalk, and Ruby it’s possible to “embed” a domain-specific language within the language. Lisp programmers (“Lispers”) are famous for this (insofar as they are known at all). It’s often been said that Lisp is a language for writing other languages. I wasn’t sure what that meant, but I think I’m beginning to understand. Fowler explained that in a way it’s possible to create DSLs in mainstream languages like Java as well.

Fowler discussed the different options for how to implement a DSL. One way is to create a language native to the problem domain. This is expensive, because you have to craft your own parser and your own virtual machine/interpreter, or code generator. He mostly discussed the technique of embedding a DSL in a general-purpose language.

Using the embedding technique, a DSL is a collection of objects and methods, or functions and variables (in the case of a non-OO language like Lisp), that enable a developer to totally focus on the problem domain, and avoid language primitives and API calls that are built into the general-purpose language platform, unless they directly relate to the domain. It forms a kind of language that is specific to the problem. Depending on the general-purpose language used, you can see the DSL coming through. In Java and C#, it’s more difficult to see, since they require you to use type specifiers and a method call notation that clearly delineates what is considered code and what is considered data. And it’s difficult to add methods to standard classes. This can come in handy when writing DSLs, because it’s all about terminology. Sometimes a term that would be most intuitive is already taken by a standard class, and you’d like to add a few more operations that apply to your problem.

Some might ask, “Why would you want to add methods to standard types? Isn’t this dangerous?” When using the DSL technique, you are only redefining the language for the problem at hand. You are not redefining the standard types to that problem domain from then on for all other projects. Typically you would start with the standard types as they were when the next project comes along.

In Lisp, Smalltalk, and Ruby (in that order) the native language syntax is minimalist, and you can add methods to the standard types like falling off a log (in Lisp you can redefine standard functions). So the DSL has an opportunity to “shine through”.

If nothing else, adopting the DSL mindset will have you creating code that on its face makes more sense, because it directly relates to the problem at hand. Using the technique Fowler talks about, depending on the language, it may seem more like a hat trick, because you are still using the same syntax and semantics of the general-purpose language. You can think of it as “painting over” parts of the general-purpose language and putting new labels on things, new nouns and new verbs. You can get more creative, replacing what should be a noun with an adjective, and replacing a verb with a noun, so it makes more sense. There’s an example of this at a link below, when I mention a package called Albatross.

Fowler in his presentation showed an example of a simple DSL for parsing a text file with fixed-length fields, and how it can be manifested in a general-purpose programming language. He showed two examples, one in Java and one in Ruby.

Ramon Leon came up with his own version of a DSL in Smalltalk for the problem of parsing the same text file that Fowler showed in his presentation. You can see it at the link above.

You can see another example of a Smalltalk DSL, created for a web app. testing package called Albatross at this post on Ramon’s blog, On Smalltalk. Maybe I’m going overboard here, but this last example is a thing of beauty, in my opinion. What it’s doing is so obvious. It’s a pleasure to read. This is kind of the point. It not only makes code more understandable, it’s also easier to construct solutions to problems.

The future of software development

Microsoft is adding features to .Net that will enable easier renditions of DSLs in that platform. The Linq Project team is adding new features to C# and VB.Net that make them more like dynamic languages. They will introduce dynamic types and lambda expressions, plus what they call “extension methods”, which will allow methods to be added to any type, including a standard type, that is used within a certain scope. Lisp, Smalltalk, and Ruby have, in effect, had these features for years. In any case it will save programmers time, and make their code more understandable.

A few years ago I heard that Charles Simonyi, a former Microsoft developer, had started his own company, Intentional Software. He said he was developing a tool for .Net that he hoped would solve a glaring problem in the software industry. I personally haven’t run into this problem on projects, but from what I hear it’s common for a customer or corporate manager to discuss a project with a development team, or pass spec’s to them, and receive a product months later that is nothing like what they asked for. Something got “lost in translation” between the domain expert (the customer or manager) and the implementation from the dev. team.

Simonyi said that in his experience, large applications like Microsoft Word eventually develop into their own sort of language, or API. Simonyi said he was working on a system whereby the domain expert would be able to graphically specify what they want, on their terms, and that it would translate the specification into a domain-specific model in .Net that the developers could work with. They could then fill it with the logic that would make the application work. He didn’t say it, probably because it would confuse most readers (I think it was in BusinessWeek, something like that), but what he was talking about was creating a tool for creating DSLs.

I have a feeling this concept will become the future of software development. It’s been done in dynamic languages for years. In terms of mainstream technologies it’s not here yet, but it’s coming.

The Ruby on Rails demo in Seaside

The classic Ruby on Rails demo that usually gets presented is how to build a blog in 15 minutes. This is what you usually get with the RoR screencasts. Ramon Leon at On Smalltalk did a similar demo in his own screencast, “How to build a blog in 15 minutes”, using Smalltalk (Squeak) and Seaside, of course. A key difference between his demo and the one for RoR is he does not save blog entries and comments in a database like MySQL, but rather in OrderedCollections.

I talked to Ramon about using OrderedCollections, and he said that he only uses this scheme for prototypes. It probably would not be safe if it was in production. He suggested people use object database technologies for that, such as Gemstone, Goods, or Magma. Or, if you want to use a relational database, he suggested using Glorp, for object-relational mapping.

Unlike most screencasts, his have no audio, at least right now. It sounds like he’s working on that for future ones.

Weird Al gets geeks

Weird Al Yankovich has been around for ages. I remember when he was just a budding parody artist back in the 1980s, appearing on the Dr. Demento Show (on radio), when all he had was an accordian, some bandmates, some objects to bang on, and some squeaky cute fart noises. He was singing songs like “I Love Rocky Road” (“I Love Rock and Roll” by Joan Jett), and “Another One Rides the Bus” (“Another One Bites the Dust” by Queen). A few years later he really upgraded his act. He got better instruments, and more people. He started doing music videos, singing songs like “Eat It” (“Beat It” by Michael Jackson), and “Like A Surgeon” (“Like A Virgin” by Madonna). As time passed he just kept getting better and better.

The Trivia Geek at TechRepublic recently embedded Weird Al’s latest video in one of his blog posts, giving it mucho props. So I figured it was okay for me to embed a couple.

In the late 90s Weird Al really showed off his geek cred with “It’s All About the Pentiums” (“It’s All About the Benjamins” by P. Diddy)

Is it just me? Does the guy in the green jacket (the one waxing his modem to “try to make it go faster”) look like Andrew a younger Anders Hejlsberg?

Weird Al recently came out with his latest and greatest, “White and Nerdy” (“Ridin’ Dirty” by Chamillionaire)

Can you pick out the celebrities in this video? I know the video quality isn’t the greatest, so it can be hard to tell. There are at least 3 that haven’t been in the limelight for a while. And by the way, what is that equation behind him and the other guy dancing? The Trivia Geek said it was integral calculus. I’m embarrased to say I haven’t had that (just kidding). I had (2-dimensional) integral calculus years ago but that equation doesn’t look familiar.

Funny how in both cases Weird Al takes hip hop and turns it into an excuse to poke fun at and celebrate geekdom. Sheer genius! Weird Al understands us. I’m glad somebody out there does, even if he is a comedian. 🙂

Edit 2/1/07: The equation behind Weird Al and the guy dancing behind him is called Schrodinger’s Wave Equation for a hydrogen atom. I found this and answers to many other bits of trivia for this video here.

Battlestar Galactica goes all the way

I’ve been an avid watcher of the new Battlestar Galactica series, partly because I really liked the original series as a kid. They’ve had very good writing on the show. So in a way it stands on its own. 

In the last episode shown on Friday it was revealed that Starbuck and Apollo fell in love with each other, or at least thought they had, on New Caprica, the planet the human fleet settled on when they thought they were safe from the Cylons. They were dating other people, but one night Starbuck and Apollo have a fling. They say they will announce their love, but the next day Starbuck marries the man she had been dating, I guess because she was afraid to carry through with it.

In the present, Starbuck starts going after Apollo again. When he refuses her, she starts taunting him, questioning his manhood as if she had a justifiable beef against him. They are both married. Battlestar Galactica is holding boxing matches to let people let off steam. Apollo and Starbuck eventually go in the ring and fight it out.

I was disappointed. I remember in the first season they showed Starbuck and Apollo as affectionately close, but not lovers. Now they’ve gone “all the way”, so to speak. They had changed the gender of Starbuck to a woman in this series, something that was very controversial to sci-fi fans, who remembered Dirk Benedict as Starbuck in the 1970s series. I didn’t mind, so long as she faithfully portrayed the character. It started off well. I watched the premiere movie back a few years ago. I think she played the Starbuck I remembered well…in a girlie sort of way. Hey, you can’t have everything. I expected that they would keep these characters as close buddies, but not romantic, to keep some flavor of those characters from the original series. But no, now they’re “involved” with each other. Great. Way to destroy the original characters, guys. I hope at some point they come out and reveal that Starbuck was originally a man and had a sex change operation. That would be fun to watch (sigh). 😐

It’s not just that I have memories of the Starbuck character being played by a man. It’s also that I admired that he and Apollo had a close buddy-buddy relationship. They were elite pilots who backed each other up, because they had a personal and professional dedication to each other. This came about because of a recognition of who each of them was, and what they had accomplished. What made the original series worth watching in my opinion were the characters of Adama, Apollo, and Starbuck, with Baltar as their nemesis. They held the story together. Now there are more consequential characters, which I don’t mind at all.

I think this turn of events in the story destroys the original Apollo and Starbuck characters though, because now they’re no longer buddy-buddies, and no longer heroes. Now they’re going to be distracted by emotional issues between them, not to mention their spouses. I guess the story is going to show the consequences of officers getting too close and not living up to their obligations, as the Adama character talked about in this episode. Maybe that’s the point. Maybe what will play out is a tragic series of events, due to a leadership mistake on his part.

Anyway, to see Apollo and Starbuck getting “freaky” with each other was uncomfortable. I wish they hadn’t written the story like this, but oh well. They’ve gone ahead and done it. There’s no taking it back. I won’t say that I’m not going to watch the series anymore, but I’ve lost some respect for it.