Info on Smalltalk DSLs or Metaprogramming...
Rich Warren
rwmlist at gmail.com
Tue Aug 22 08:18:43 UTC 2006
On Aug 20, 2006, at 7:20 AM, Ramon Leon wrote:
>> In Ruby, "See" could be an object, "spot" a method and "run" a
>> local variable.
>> As far as I know, you couldn't interpret the same thing directly
>> in Smalltalk. You would need to write "See spot: run", which is
>> where the colons become a problem.
>> Of course, there are other cases where the colon would come in handy.
>> Having thought about both languages a lot over the last few days,
>> I'm pretty sure of the following:
>> 1) Regardless of which language you use, there will be DSL
>> elements that appear awkward or clunky (provided you do no string
>> processing).
>> 2) Some things will always be easier to write in the other language.
>> -Rich-
>
> Ruby might allow parens to be optional allowing run to be sent to
> spot, however, it'd look more like...
>
> See.spot run
You're right. I got confused skipping from one language to the other
(and, as I previously mentioned, most Ruby DSLs are based on method
calls within a class, not method calls on a class). Typically this
would be done as chained method calls
see(spot(run)) => see spot run
>
> Hardly any better than
>
> See spot: run
>
> Besides, you could always setup spot as a member of see, then...
>
> See spot run
Of course. This is another valid way of chaining--only running the
other way (#run is sent to the value returned by #spot.
>
> However you work it, I think the Smalltalk will come up with a more
> natural English looking syntax due to it using spaces where ruby
> would use periods and it using periods as a statement separator.
>
> See spot run. Spot go home. Spot wag tail.
>
> Is a perfectly valid Smalltalk statement, can Ruby do that?
>
>
As I tried to say before, my main point really, I think it depends on
what you're familiar with. The more I look at both of them, the more
I see good points (and annoying points) about both.
Basically you have to design the DSL around either language. And I
really don't see anything in either that's a big win over the other.
Smalltalk's period can be nice, if you can design around it. It's
better than Ruby's semicolon--but Ruby also lets you use line breaks--
which can lead to very nice multi-line constructions.
Smalltalk works better for multi-parameter methods--Ruby for single
parameter.
Smalltalk's insistence on self for method calls within a class
require you to have a class object (which often means an additional
item you need to plan around--or one more item to use, depending on
how you look at things).
Smalltalk's continuations are nice, but since Ruby lets you make your
calls within a class, you can do the same thing with multiple calls.
Ruby's literal hashes are not great from a non-geek legibility
viewpoint, but if you're making a DSL for coders, they're brilliant.
Overall, I don't see enough of a difference to really argue over.
-Rich-
More information about the Squeak-dev
mailing list
|