The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Inconceivable

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Inconceivable Posted: Sep 6, 2007 10:48 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Inconceivable
Feed Title: Cincom Smalltalk Blog - Smalltalk with Rants
Feed URL: http://www.cincomsmalltalk.com/rssBlog/rssBlogView.xml
Feed Description: James Robertson comments on Cincom Smalltalk, the Smalltalk development community, and IT trends and issues in general.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Cincom Smalltalk Blog - Smalltalk with Rants

Advertisement

The title is a reference to "The Princess Bride", and the phrase I wanted was "I don't think that word means what you think it means". I'm taking that from Neal Ford's rather confused post about meta-programming. His example is code generation, and he has a fairly deep misunderstanding of how Smalltalk works (and, quite probably, of how Ruby works as well) - let's have a look. He goes into an implementation of has_many in Ruby on Rails:


class Order < ActiveRecord::Base
  has_many :lineitems
end

For those not familiar with Ruby, this is a method, defined as a class-level initializer (just like an instance code block in Java, a chunk of curly-brace code in the middle of a class definition, which Java picks up and executes as the class is instantiated). So, ultimately, this is the Ruby equivalent of a static method call, which gets called as the class is created.

He then goes into Smalltalk:

Let's talk about Smalltalk, which has first-class meta-programming. You could easily build has_many in Smalltalk, implemented as a button you click in the browser which launches a dialog with properties that allow you to set all the characteristics embodied in the Ruby version. When you are done with the dialog, it would go do exactly what Ruby does in Rails: generate a bunch of methods, add them to the class (stuff like the find_* and count_* methods). When you are done, all the methods would be there, as instance methods of your class.

OK, so at this point, the behavior is the same in Smalltalk as in Rails. But there is one key difference: The Smalltalk version using code generation. It's a sophisticated version of a code wizard, generating the code using meta-programming techniques. The Ruby version uses code synthesis: it generates the code at runtime, not build time. Building stuff at runtime means more flexibility. But that is a minor point compared to this one: In the Smalltalk version, you use the dialog and properties to generate all the methods you need.

I suppose a Smalltalker could do it that way, but it's not how it would normally be done. I've seen a lot of projects that do the kind of dynamic, runtime code generation he's talking about - but let me quote Alan Knight, who was talking about this in the IRC channel this morning:

aknight notes, for jarober's edification, that the GlorpActiveRecord stuff does have a hasMany method
and does no code generation at all from it
and yet, somehow it works

In the Glorp implementation of ActiveRecord (which will be part of our Seaside support, by the way), Glorp reads the database schema, figures out what's there, and then sets up the ability to read the appropriate database records without code generation.

I think a lot of people have strange ideas about how Smalltalk works, simply because the image throws them for a loop. Just because the image allows for some nifty development tools doesn't mean that everything done there is utterly alien.

Technorati Tags: ,

Read: Inconceivable

Topic: Zuckerism is Doomed Previous Topic   Next Topic Topic: DSM for adventure games

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use