The Artima Developer Community
Sponsored Link

Weblogs Forum
Ruby + DSLs = Power Tool "Ecosystem"

29 replies on 2 pages. Most recent reply: Jan 27, 2008 4:39 PM by James Watson

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 29 replies on 2 pages [ « | 1 2 ]
Jörn Zaefferer

Posts: 22
Nickname: jzaefferer
Registered: Jul, 2007

Re: Ruby + DSLs = Power Tool "Ecosystem" Posted: Jan 25, 2008 9:14 AM
Reply to this message Reply
Advertisement
> I don't know anything about jQuery but a DSL (to me) isn't
> just about making programs easier to read.
>
> A Domain Specific Language is just
> that, specific to a domain. In my mind a domain isn't
> web-programming or database-querying. A domain is
> finance, insurance, retailing...
>
> With DSL you can program in the terms of the users. Then
> the users can read the program in the same terms that they
> think in.

The domain for jQuery is scripting user interactions in the browser, and the user are developers doing that.

Still not a DSL?

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Ruby + DSLs = Power Tool "Ecosystem" Posted: Jan 25, 2008 1:48 PM
Reply to this message Reply
> The domain for jQuery is scripting user interactions in
> the browser, and the user are developers doing that.
>
> Still not a DSL?

Again I know almost nothing about JQuery. I went to the jQuery page and looked at some examples and I would say no, it's not.

That says nothing about whether jQuery is a good language. It looks pretty nice. It's just not a DSL, in my opinion. I realize also that a lot of what is a DSL depends on what you define a 'domain' to be and I don't pretend to be the true authority on what is an isn't a DSL. This is just my opinion on what makes the term DSL useful.

Gregg Irwin

Posts: 16
Nickname: greggirwin
Registered: Jan, 2004

Re: Ruby + DSLs = Power Tool "Ecosystem" Posted: Jan 25, 2008 2:43 PM
Reply to this message Reply
The JQuery site says it's a library, so I would go with that.

One of the defining criteria of a language versus a library is whether the syntax and semantics are the same as the host language. An embedded language may use the same lexical form as its host language, but a library is just a vocabulary. Of course, the vocabulary is a very important aspect of any design.

Designing languages versus libraries also emphasizes the user experience IME.

Here are some examples of dialects I've written for the REBOL language:

stopwatch: make-FSM [
when stopped
click causes start then running
reset causes reset-counter
when running
click causes stop then stopped
reset causes reset-counter
tick causes increment-counter
]

cmd-line-spec: [
--quiet -q {quiet mode}
--verbose -v {verbose mode}
--outfile file {The output file}
]

send-keys [ ; comments
alt f o ; open the file menu
wait 0:0:1 ; give it a second to open
"my-file.txt" ; name of the file to open
enter ; clicks OK
]

edit-ini-file %test.ini [
remove "Obsolete" section
in [General] section
remove "old app"
insert "new app" entry set to "c:\blah\myapp"
set "window mode" to "maximize"
insert "password" entry set to (checksum "Gregg")
]

r-awk sources [
begin [print "begin"]
end [print "end"]
begin-file [print ["begin-file" _filename]]
end-file [print ["end-file" _filename]]
every-line [line-ct: line-ct + 1]
[_nr = 1] [print "record 1"]
[_fnr = 1] [print ["file record 1" _filename]]
]

Eric Armstrong

Posts: 207
Nickname: cooltools
Registered: Apr, 2003

Re: Ruby + DSLs = Power Tool "Ecosystem" Posted: Jan 26, 2008 6:12 AM
Reply to this message Reply
> I don't quite see how DSL is a good replacement for
> framework or library. Whats the difference?
>
The ability to communicate with domain experts who aren't programmers is a big advantage of DSLs that are targeted a end-user problems, rather than developer problems. For Power Tools (DSLs targeted at developer powers), the advantage is expressive power. Rake is a great build tool. I suppose you could call it a general-purpose framework, if you wanted to.

Eric Armstrong

Posts: 207
Nickname: cooltools
Registered: Apr, 2003

Re: Ruby + DSLs = Power Tool "Ecosystem" Posted: Jan 26, 2008 6:31 AM
Reply to this message Reply
> FORmula TRANslator: the original DSL ;-)
>
Very nice. Yes, that is a pretty good example of the evolution of computer languages towards increased expressive power. But of course, while you could easily solve problems the language was designed for, you could not solve other kinds of problems easily, or extend the language to do so.

That ability to "extend the language" was a characteristic of Forth, as well. Unfortunately, it turned out to be nearly impossible to get a program to work correctly, and stay working if you modified it. And program internals tended to be unreadable by anyone other than the author, because /everything/ outside of a tiny core of statements was a home-grown language.

Ruby kind of hits a sweet spot, that way. It's an object-oriented, high level language with libraries that can be extended. Of course, readability is still an issue. It's always that way. Any language that lets you construct your own language has the capacity to become Forth-like when other people try to understand what you've done.

I look forward to the newest version of Ruby, which is said to remove a lot of Perl-like hieroglyphic symbols. (Single-character idioms that are way easy to write, but impossible to read until you learn them all.)

So I think a better language is still out there, waiting to be discovered (or written). After playing with 20-some programming languages and an equal number of scripting languages (to varying degrees), Ruby became #21 on both lists. I like it a lot for that reason, as well.

I look forward to finding out what #22 will be.
:_)

Eric Armstrong

Posts: 207
Nickname: cooltools
Registered: Apr, 2003

Re: Ruby + DSLs = Power Tool "Ecosystem" Posted: Jan 26, 2008 6:40 AM
Reply to this message Reply
> The domain for jQuery is scripting user interactions in
> the browser, and the user are developers doing that.
>
> Still not a DSL?
>
Since it's aimed at developers, it certainly qualifies as a "power tool". Whether it's a DSL power tool depends on whether it was written in JavaScript.

If it is, then JavaScript is a language with "meta-programming" capabilities (the ability to produce other languages). I don't know a lot about JavaScript, but I know enough to know it isn't.

Still, jQuery is a useful power tool, and part of the JavaScript ecosystem.

The degree to which the ecosystem evolves has a lot to do with language success. One way to get that evolution. One is to invest heavily in it (ex: Sun & Java). Another is the snowball effect, where language popularity leads to lots of offerings. A third factor is the ease with which power tools can be created. Metaprogramming languages have an edge there, because power tool construction tends to become a natural extension of everyday coding.

Eric Armstrong

Posts: 207
Nickname: cooltools
Registered: Apr, 2003

Re: Ruby + DSLs = Power Tool "Ecosystem" Posted: Jan 26, 2008 6:45 AM
Reply to this message Reply
>
> Here are some examples of dialects I've written for the
> REBOL language:
>
<snip>

Very nice stuff! Simple, generally declarative syntax. That is definitely the idea of a DSL. You modify and simplify the syntax used to express a problem.

I also like the term "Dialects". I wish that one had become popular, rather than "DSL". It communicates a lot better, imo. Because a DSL is precisely that: A dialect suited to a particular domain. (It could also be called "jargon", and a metaprogamming language that lets you create new jargon could be called a "jargonizer"--but we better not go there.)
:_)

Eric Armstrong

Posts: 207
Nickname: cooltools
Registered: Apr, 2003

Re: Ruby + DSLs = Power Tool "Ecosystem" Posted: Jan 26, 2008 6:54 AM
Reply to this message Reply
> RoR is not a language. Call it what you like (a "library,"
> but you could be wrong, or a "framework," and you'd
> probably be right), but it isn't a language.
>
According the author of RoR, it is a DSL. My first Ruby conference, he and others spoke about how it grew organically, as he developed solutions to common coding tasks.

Here are some others that think so:

http://memeagora.blogspot.com/2007/11/ruby-matters-frameworks-dsls-and.html
"I'm wondering how extending RoR's DSL to cover..."

Eric Armstrong

Posts: 207
Nickname: cooltools
Registered: Apr, 2003

Re: Ruby + DSLs = Power Tool "Ecosystem" Posted: Jan 26, 2008 7:02 AM
Reply to this message Reply
> > RoR is not a language. Call it what you like (a
> "library,"
> > but you could be wrong, or a "framework," and you'd
> > probably be right), but it isn't a language.
> >
According the author of RoR, it is a DSL. At the first Ruby conference I attended, he and others spoke about how it grew
organically, as he developed solutions to common coding
tasks.

Here are some others that think so:

http://memeagora.blogspot.com/2007/11/ruby-matters-frameworks-dsls-and.html
"I'm wondering how extending RoR's DSL to cover..."

http://blog.daemon.com.au/archives/000321.html
"Rails is essentially a DSL on top of Ruby. ..."

Searching on "Rails DSL" yields many more. Of course, there are also many cases where it is called a framework, rather than a DSL.

That's not to say that you don't have a point. Of all the examples in my post, RoR is the least DSL-like, primarily because it does so much else. With all the libraries and whatnot, any DSL-ness is going to be pretty well hidden.

So as a matter of purity, I'm willing to give you that one. It's much more recognizable as a framework, rather than as a DSL. (Of all the examples mentioned, it's also the one with which I'm least familiar--a gap in my education that I look forward to rectifying.)

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Ruby + DSLs = Power Tool "Ecosystem" Posted: Jan 26, 2008 7:18 AM
Reply to this message Reply
One of the best examples (IMO) of a DSL tool is the Drools rules engine that allows you to apply DSLs as transformations to the rule syntax so that rules can be written like:

There is a Person with name of "kitty"

Person is at least 42 years old and lives in "atlanta"

Log "boo"

There is a Person with name of "bob" and Person is at least 30 years old and lives in "atlanta"


These are just examples. You can create your own vocabulary.

http://downloads.jboss.com/drools/docs/4.0.4.17825.GA/html/ch06s07.html)

I'm not sure I would hand this off to a non-technical person and have them type up the rules but they could definitely look at something like this (if done well) and tell you if what you have matches their expectations. One of the biggest problems that I've had to deal with many times is miscommunication between the people creating requirements and those fulfilling them. Anything makes this communication easier and more reliable is definitely welcome.

Elizabeth Wiethoff

Posts: 89
Nickname: ewiethoff
Registered: Mar, 2005

Re: Ruby + DSLs = Power Tool "Ecosystem" Posted: Jan 27, 2008 9:24 AM
Reply to this message Reply
> I look forward to the newest version of Ruby, which is
> said to remove a lot of Perl-like hieroglyphic symbols.
> (Single-character idioms that are way easy to write, but
> impossible to read until you learn them all.)

require 'english'

Eric Armstrong

Posts: 207
Nickname: cooltools
Registered: Apr, 2003

Re: Ruby + DSLs = Power Tool "Ecosystem" Posted: Jan 27, 2008 10:05 AM
Reply to this message Reply
Elizabeth wrote:
>
> require 'english'
>
Yup. That adds readable syntax to /your/ programs.
But it doesn't remove them from the vocabulary.

What makes Ruby programs difficult to read is the
astonishing number of idioms. There are several
different ways to do most everything. Given the
huge number of combinations, every developer/
developer team winds up with a set that is not easily
understood by others.

Java still has the advantage in that respect. In
any large, long-term project where programmers come
and go, maintenance dominates the cost equation by
a factor of 10. Readability becomes the most
important aspect of a language, in setting like that,
because the majority of maintenance time is spent
coming up to speed on how the program works so
you can figure out what's going wrong.

So that's the one area I can see Ruby improving.

(That readability factor is the thing that made
Lisp suffer. Like Ruby, it was built up from
primitives. But that means that from the common
libraries up to the topmost levels of an
application, the language tends to be idiosyncratic
to the installation--which makes it difficult to
bring in someone new and get them up to speed.)

Eric Armstrong

Posts: 207
Nickname: cooltools
Registered: Apr, 2003

Re: Ruby + DSLs = Power Tool "Ecosystem" Posted: Jan 27, 2008 10:25 AM
Reply to this message Reply
James Watson posted:
> One of the best examples (IMO) of a DSL tool is the Drools
> rules engine that allows you to apply DSLs as
> transformations to the rule syntax...
>
http://downloads.jboss.com/drools/docs/4.0.4.17825.GA/html/
> ch06s07.html)
>
Nice link! Thanks much. I wasn't aware of that engine.
A little searching led me here:
http://labs.jboss.com/drools/

That page gives us:

Drools is a business rule management system (BRMS) and an enhanced Rules Engine implementation, *ReteOO*, based on Charles Forgy's Rete algorithm tailored for the *Java* language. More importantly, Drools provides for Declarative Programming and is flexible enough to match the semantics of your problem domain with Domain Specific Languages, graphical editing tools, web based tools and developer productivity tools.

Ok. So we're looking at a Java-based implementation of something called ReteOO. Interesting stuff! A little more
searching, and we get:
http://docs.codehaus.org/display/DROOLS/ReteOO

This is /very/ interesting stuff. But here is where things get interesting: Is Drools *open* or *closed*? (Martin Fowler uses the terms "internal" and "external", but I don't think they communicate as well as open and closed.)

Here's the difference:

A /closed/ DSL is implemented as a standalone language.
It exists outside of a programming language, so it
is "external", in that sense. But the salient feature
is the fact that you can only do things with it that
the language designers anticipated.

An /open/ DSL is implemented as an extension to a
a programming language. In that sense, it is "internal".
You plugin the new module, and you have access to both
the DSL and the underlying general purpose programming
language (GPL). It's "open" in the sense that you can
do anything you want to in the GPL, you just have the
DSL as a convenience whenever it makes sense.

Of course, there is a downside to the openness. If domain experts like to do their own coding, and they make a mistake, the could conceivable right legal GPL code which would be executed with unintended consequences, instead of diagnosed with an error, as with a closed DSL.

But in return for that risk, you throw off the shackles and can do anything at all you want to do. (The aristocracy had essentially the same argument over democracy!)

So is Drools open or closed? I'm guessing closed, since Java isn't designed to "extend itself" into a DSL. But you're darn right that Drools is a useful tool to have in your bag. And Java remains a very readable, hence maintainable language.

For a large installation then, Java + Drools may be the way to go. For agile coding (the most fun kind!) I'm inclined to stick with (J)Ruby--at least for the moment!
:_)

Elizabeth Wiethoff

Posts: 89
Nickname: ewiethoff
Registered: Mar, 2005

Re: Ruby + DSLs = Power Tool "Ecosystem" Posted: Jan 27, 2008 12:36 PM
Reply to this message Reply
> What makes Ruby programs difficult to read is the astonishing number of idioms.

And using Ruby to invent "DSLs" adds yet more idioms.

> Given the huge number of combinations, every developer/ developer team winds up with a set that is not easily understood by others.

And although a DSL might make for readable code, it still needs to be learned by the new people on a team so that they can write code.

> Java still has the advantage in that respect. In any large, long-term project where programmers come and go, maintenance dominates the cost equation by a factor of 10. Readability becomes the most important aspect of a language, in setting like that, because the majority of maintenance time is spent coming up to speed on how the program works so you can figure out what's going wrong.

Although you are contrasting Java's readability with Perl/Ruby's line noise and plethora of idioms, you have sort of illustrated my previous sentence.

> (That readability factor is the thing that made Lisp suffer. Like Ruby, it was built up from primitives. But that means that from the common libraries up to the topmost levels of an application, the language tends to be idiosyncratic to the installation--which makes it difficult to bring in someone new and get them up to speed.)

It's occurring to me to become concerned that using Ruby to implement DSLs (whatever the heck they are) adds more confusion to learning Ruby. I suspect it becomes hard to tell which bits one is reading are plain ol' Ruby and which bits are invented by the DSL designer.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Ruby + DSLs = Power Tool "Ecosystem" Posted: Jan 27, 2008 4:39 PM
Reply to this message Reply
> So is Drools open or closed? I'm guessing closed, since
> Java isn't designed to "extend itself" into a DSL. But
> you're darn right that Drools is a useful tool to have in
> your bag. And Java remains a very readable, hence
> maintainable language.
>
> For a large installation then, Java + Drools may be the
> way to go. For agile coding (the most fun kind!) I'm
> inclined to stick with (J)Ruby--at least for the moment!
> :_)

I'll go with 'closed' too. I would say that is the case because (as I understand it) Drools merely allows a simple translation from a language that is 'laid' over it. This provides some stability. In my industry, the business changes very fast. Too many variables will surely sink our efforts.

I can definitely see the value in an open language but I'm not ready to take that on. At this point, I'm going to have enough trouble convincing my superiors that we should go with a business rules approach, something I'm pretty close to sure we need. We've been burned by hifalutin ideas in the past so I need to demonstrate value for any complexity that I introduce. I find a 'closed' DSL to be a good way to dip my toe in.

Flat View: This topic has 29 replies on 2 pages [ « | 1  2 ]
Topic: Ruby + DSLs = Power Tool "Ecosystem" Previous Topic   Next Topic Topic: Jini and OSGi, yet again

Sponsored Links



Google
  Web Artima.com   

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