By Peter Bell

Programming by Wishful Thinking

A nice little posting that describes a great way to get started with Domain Specific Languages (this article assumes a method call concrete syntax, but the approach could be generalized). The trick is to start to scribble out your solution pretending that the magical compiler will turn your wishes into working code. Then once you've refined your language just enough to make it worth coding, go write a parser, translator or a set of method calls to implement your magic compiler :->

I'm a big fan of both top down design like this and bottom up design (where you add concepts to your language to solve ever more specialized problems). The trick is to think of programming as the art of language design and to focus on writing lots of little layers each providing more useful abstractions on top of the lower ones.

Comments
I find this quite helpful. When I am asked to add a new feature to a component or custom tag, I generally respond by asking for the desired syntax to use the new feature.

This is often helpful because sometimes a good syntax is hard to design for a new feature. This often suggests that feature is inappropriate for the tool.

Once the desired syntax is uncovered, then I can investigate whether it makes sense to add the feature.
# Posted By Steve Bryant | 1/29/07 9:51 AM
Definitely! The interesting thing about Language Oriented Programming is that the hard skill is language design. Writing an API that implements a defined syntax is usually straightforward - coming up with the elegant API - now *that's* the difficult thing!
# Posted By Peter Bell | 1/29/07 10:02 AM
I am not sure how this relates to anything, but I am used to programming like this in Eclipse as it then gives me an error on each non-existent function. The key is that once I have done all my thinking of the caller, added all the methods, Eclipse helps my by creating the class, then I can add each method and it will "figure out" what each method has to do, I can then go and fill in the details. I would love to get CFEclipse to this level of coding.
# Posted By Mark Drew | 1/29/07 10:21 AM
Yeah - IDEs can really help with this, but I'm guessing Eclipse has a few more developers than CFE, so we'll take whatever you get a chance to put in!!!
# Posted By Peter Bell | 1/29/07 10:27 AM
I believe this is more commonly known as "Code By Intention" and it is widespread approach used in OOP.
# Posted By Brian Kotek | 1/29/07 11:47 AM
Hi Brian,

Interestingly, if you Google "code by intention", I only got 124 results suggesting people perhaps use a sightly different phrase. One other I've heard is top down design http://en.wikipedia.org/wiki/Top_down, but you're right that whatever you call it, it is a pretty common approach - in the OO and procedural programming worlds.
# Posted By Peter Bell | 1/29/07 11:55 AM
It should be noted, TDD covers this. In essence, you do the same thing, except you get a test as a nice side-effect =). However, you might not neccesarily choose to start from the top-down, although I think I normally do. And then go bottom up refactoring as necessary.
# Posted By Sam | 1/29/07 12:31 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.005.