Info on Smalltalk DSLs or Metaprogramming...
ramonleon at cox.net
Tue Sep 5 02:28:52 UTC 2006
> As an example, Body can take a variable number of Tag objects. Java
> methods can be defined to accept variable numbers of parameters, so
> this isn't a problem. Tag objects can also be nested inside other tags
> (allowing us to express complete html hierarchies). Alternatively, all
> tags (including body) could accept any objects-- and internally it calls
> toString() on the object. This would let you pass in a mixture of Tag
> objects and literal strings.
True, that would seem to work, but only with the addition saying all
setters return "this", so properties of those objects can be set in
every possible combination, inline, equivalent to Smalltalk's ;
operator. I've done this in the past, it's ugly, and non idiomatic, and
confuses other programmers. It works surprisingly well, once accustomed
to it, but feels like you're working very much against the language. I
embedded SQL into csharp using this technique, mostly for the experience
of doing so.
> Given that, I don't see any difference between my nested calls in Java
> and your nested calls in Smalltalk.
I do, the Smalltalk ones are closures that pick up variables from the
surrounding environment automatically, the Java one would require
manually passing all such variables, or the introduction of some ugly
inner classes and all the relevant hacks to make them work.
> While I fully admit that it's easier and cleaner to do bottom-up
> programming in dynamic languages, it is still possible (to some degree)
> to use these techniques in any language.
Agree, but it's the difficulty in doing so, that separates languages
that you'd want to build a DSL in from those you wouldn't.
> Any time you create a function, class or whatever, you are bringing the
> language closer to the problem domain. There's no distinguishable line
> between bottom-up programming and simply creating well- engineered
> classes and functions. Anyone can look at both ends of the spectrum and
> see that they look different--but that ignores how quickly things blur
> in the middle.
I think there is, I don't think it's difficult to see DSL's as a style,
and it's easy to see that style in other people's code. You either
write in the language, or on it. While it's possible to do a mixture of
both, I think most people pick one or the other. I see it as similar to
the API vs framework thing, people tend to like one or the other.
> On the other hand, there is a sharp line between interpreted DSLs and
> regular programming. That's one of the reasons I prefer to use the term
> DSL strictly for interpreted DSLs. The term (when used that way) has a
> clear meaning.
I fail to see that line, whether code is interpreted or not, imho is
orthogonal to the issue of whether or not that code is a DSL. I find
your linking of these concepts, odd, maybe it's me, but they simply
More information about the Squeak-dev