s-expressions

‘(Amit Rathore blogs about software development)

Programming Clojure - classpath for Emacs and Slime

Posted by Amit Rathore on November 29, 2008

This is probably obvious to a lot of people, but I had a hard time trying to figure out how to get emacs/slime to see my clojure and java stuff. I was able to get it all up and running when I started Clojure from the command line, but when using slime, it was unable to locate all the extra stuff I wanted it to. After a bit of googling, I found out how to do it. Put the following line before calling (require ’swank-clojure-autoload) in your dot emacs:

(setq swank-clojure-extra-classpaths (list "/class/path/1" "/class/path/2" "/class/path/3" "etc"))

Restart emacs, start slime, and it will now find everything on those paths :)

Posted in clojure, code | No Comments »

Software development agility - bottom-up design and domain-specific languages (DSLs)

Posted by Amit Rathore on November 10, 2008

It’s been nearly three months that I’ve been working at Cinch. And in that time I’ve worked with the team to get a lean and agile process in place, and while we’re not there yet, things are getting more and more focused every day.

I’ve also been working to significantly re-factor the code that existed, as we get ready to get the first beta release out the door. In this post, I’d like to talk about one aspect of our design philosophy which I’m glad to say has been working out really well - bottom-up design (and an associated DSL).

Before we decided to change the system, it had been designed in the usual top-down manner. Cinch operates in the online retail space - we provide web-based services to online merchants, and while we have a grand vision for where we want our platform to go, our first offering is a promotions service. It allows merchants to run campaigns based on a variety of criteria. Merchants are a fussy lot, and they like to control every aspect of campaigns - they want to be able to tweak all kinds of things about it.

In true agile fashion, our initial release allows them to select only a few parameters. Our system, however, needs to be extensible, so that as we learn more about what our merchants need, we can implement these things and give it to them. Quickly. And all of this needs to be done in a changing environment with lots of back-and-forth between the business team and the dev team.

So here’s what we came up with - it is an example of what we call a campaign template -


campaign_template :recapture_campaign do
  title is 'Recapture'
  subtitle is 'Reduce cart abandonment rate'
  description is 'This campaign presents offers to shoppers as they abandon their shopping cart.'

  #adding criteria here
  accept required time_period_criteria with defaults start_date('1/1/08'), end_date('12/31/10')
  accept required product_criteria with no defaults

  hardcode visit_count_criteria with number('1')

  #more criteria
  reject optional url_referrer_criteria with no defaults

  inside context :view_badge do
    never applicable
  end

  inside context :abandon_cart do
    allow only customer_type_criteria with customer_type('visitor')
  end

  inside context :cart do
    allow only user_action_criteria with user_action('accepted_recapture')
  end

end

A campaign template behaves like a blue-print of an actual campaign. Sort of like the relationship between a class and an object. In a sense, this is a higher-order description of just such a relationship. The (computer) language now lets us speak in the domain of the business.

There are a couple of reasons why our core business logic is written like this -

a) It lets us communicate easily with the business. Whenever a question about a rule comes up, I bring up the associated template up on the screen, and make them read the ‘code’. Once they agree thats what they mean, it just works, because it is real code.

b) Since this is in essence a way to script the domain model, it has forced a certain design upon it. All the objects evolved in a bottom-up manner, and each does a very specific thing. It lends to a very highly de-coupled design where objects collaborate together to achieve the higher goal, but each is very independent of the other.

c) This notation makes several things easier. One, the actual business rules are described here, and they just work. The other thing is that we’re able to use this same representation for other things - for example, our merchant GUI is completely auto-generated off these template files. Menu items, navigation, saving, editing, error-reporting, everything is generated.

This allows very fast turn around time for implementing new concepts, or making changes to existing ones.

It’s an internal DSL written in Ruby, and does whatever it can without any extra parsing, as you can probably imagine. I will write about the specifics of how this is implemented in future posts. For the moment, I would like to stress, however, the importance of the bottom-up approach. Because our domain model is made up of many small objects (instead of a few larger ones), each representing a tiny aspect of the domain, we’re able to put them together and fashion more complex beasts out of them. And the combinations are limitless, bounded only by business rules. This is where the power of this approach lies.

The DSL itself is almost only a convenience!

Posted in DSL, architecture, code, design, languages, meta, ruby, startup, tech | No Comments »

First week at Cinch

Posted by Amit Rathore on August 24, 2008

During my last week at ThoughtWorks, my colleagues were asking me what I would be doing at my new job, and what technologies I might be working on.

I told them that the job involved Rails for the consumer-focused piece, and a combination of other technologies at the backend - Ruby, Java (along with Hadoop), Erlang, and possibly others depending on the task at hand. I wasn’t sure if they were impressed or not, but they did joke about how I would actually end up working on PHP and ColdFusion. I indignantly denied any such thing.

So of course, my first week at the new job saw me working on PHP and ColdFusion.
:|

Basically, since a part of Cinch is a set of services for merchants, the consumers of these services could be using PHP, ColdFusion, or any other platform. Hence the need for us to ensure our code works with all of them, and indeed, for us to develop libraries for every major e-commerce platform out there. Anyway, that’s what I worked on through Week 1.

Heh, just thought this was funny!

Posted in code, languages, startup | No Comments »

Against all Oddities

Posted by Amit Rathore on May 5, 2008

I just remembered, over this past weekend, that a long time ago I had submitted an article for the ThoughtWorks Anthology. I had actually gotten accepted for the book - with a sort of caveat. Martin Fowler told me that I’d have to improve the essay - to make it actually helpful to people reading it. Great advice, of course!

Except that I’m way too lazy and couldn’t be bothered.

So here it is, in it’s original unedited glory. Against All Oddities by Amit Rathore. I’m also too lazy to convert it into HTML, let Google do that, I say!

Posted in organizational, process, project management | No Comments »

Startup School 2008

Posted by Amit Rathore on April 19, 2008

I attended this year’s Startup School - and all eight of the talks were really awesome. I got to hang out with a ton of people who had either already started their companies, or people that were looking to do so. The energy and the buzz was fantastic. Most importantly, however, I got to see three of my heroes -

paul_graham.jpg

Paul Graham - talking about the idea of being a benevolent startup.

jeff_bezos.jpg

Jeff Bezos - talking about Amazon Web Services as a way forward for startups.

peter_norvig.jpg

Peter Norvig - talking about extracting data from the web, and leveraging it in startups.

Posted in conference, learning, startup | No Comments »

BlueScreenOfDeath on Parallels

Posted by Amit Rathore on July 2, 2007

Man, just when I started to think I was done with the Windows BSOD, it just happened on my Parallels Desktop! Thankfully, it just restarted the one window on the otherwise rock-solid Mac OS X.

Bah.

Posted in tech, tools | 1 Comment »

The age of the mobile web is here

Posted by Amit Rathore on June 12, 2007

This is it. If there was any doubt the future of handheld devices was the mobile web, it should be laid to rest now. As a strategy for allowing 3rd party developers to write applications for the iPhone, Apple has embraced the mobile web. And they plan to support all the ‘Web 2.0′ standards - which is just another way of saying that the mobile browser’s DOM will be predictable, and that Javascript will work as expected. Why won’t it, after all, the ‘mobile’ browser is a full-fledged desktop version!

If any of you have ever tried to develop mobile web-apps that used AJAX (esp. through the use of the popular AJAX libraries for the purpose - Prototype/Scriptaculous or Dojo), you know what I’m talking about. None of the mobile browsers really work well at all. They are all broken in some way or the other - and to add to the fun, they’re broken in different ways.

So - how is Apple going to fix the issue? By side-stepping the mobile browser entirely. Just take a desktop browser and make it available on the mobile. Perfect! And this is Apple’s official strategy for externally developed applications! So the critical mass is ready to happen…

And this will also see the beginning of the end of the walled-gardens of the carriers. If they don’t own the access to mobile applications, then they can’t control it. The reason they do control it, is that for the most part, no one wants to download and install things on their phone. Either they’re not technical enough, or things break after you install the wrong or badly developed application. So most people just use whatever is ‘on-deck’. And those applications are completely controlled by the carriers. No more! If the mobile web becomes popular, that’s the end of that!

Yet another way the iPhone will change the world.

Posted in mobile-web, mobility, tech | 9 Comments »

Easy external DSLs for Java applications

Posted by Amit Rathore on April 27, 2007

Or JRuby for fun and profit

I’ve been developing software for some time now, and have recently found myself applying ideas from various esoteric areas of computer-science to every day tasks of building common-place applications (often these concepts are quite old, indeed some were thought of in 1958).

One powerful idea that I’ve been playing with recently is that of embedding a DSL (domain specific language) into your basic application framework - and writing most of the features of the application in that DSL.

This is simply an implementation of the concept of raising the level of abstraction. The point, of course, being that when writing code in a DSL implemented in such a fashion, one can express ideas in terms of high-level abstractions that represent actual concepts from the problem domain. In other words, it is like using a programming language that has primitives rooted in the domain.

A lot of people have been writing about this kind of software design - and most implement these ideas in a dynamic language of their choice. How does one go about doing the same in a language like Java? That is what this article is about. And I cheat in my answer. Consider the following design stack -

Creating DSLs in JRuby

I propose that you only implement basic and absolutely required pieces of functionality in Java - the things that rely on, say, external systems that expose a Java interface, or some EJB-type resource, or some other reason that requires the use of Java. The functionality you develop here is then exposed through an interface to the layers above. You can also add APIs for other support services you might need.

The layer above is a bunch of JRuby code that behaves as a facade to the Java API underneath. This leaves you with a Ruby API to that underlying Java (and other whatever, really!) stuff - and makes it possible to code against that functionality in pure Ruby. The JRuby interpreter runs as part of the deployable and simply executes all that Ruby code transparently. As far as your Ruby code is concerned, it doesn’t even care that some of the calls are internally implemented in Java. Sweet!

We can stop here. At this point, we are in a position to write the rest of our application in a nice dynamic language like Ruby. For some people, a nice fluent interface in Ruby suffices - and keeps all developers happy. This is depicted on the top-left part of the diagram.

However, we can go one step further, and implement a DSL in Ruby that raises the level of abstraction even more - as referred to earlier. So on top of the Ruby layer, you’d implement a set of classes that allow you to write code in simple domain-like terms, which then get translated into a form executable by the Ruby interpreter. This is shown in the top right part of the diagram. Ultimately, potentially any one (developers, QA or business analysts) could express their intent in something that looked very much like English.

So where to write what?

How much to put in your Java layer depends on the situation - some people (like me) prefer to write as little as possible in such a static language. Others like the static typing and the associated tool support, and prefer to put more code here. When merely shooting for a little bit of dynamism through the DSL engine in the layers above, most of the code could be written in Java, and a fluent API in the dynamic language could be enough. When shooting for rapid feature turn-around and a lot more flexibility, most of the code could be in the DSL or in the external dynamic language.

The answer to this question really depends on things like the requirements, team structure, skill-sets, and other such situational factors.

OK, so where’s the code?

My intention with this post was to stay at a high level - and talk of how one could structure an application to make it possible to embed a scripting engine into it, and to give an overview of the possibilities this creates. In subsequent posts, I will talk about how actual DSLs can be created, tested, and also how a team might be structured around it.

Posted in DSL, code, java, jruby, languages, meta, multi-paradigm, ruby | 1 Comment »

Gotham Ruby Conference 2007

Posted by Amit Rathore on April 22, 2007

I attended GoRuCo 2007 yesterday, and it was a fine conference - where I met a bunch of old friends I hadn’t seen in a while. Here’s what the agenda looked like - I enjoyed the talks on Adhearsion, JRuby, and BNLs. And the conference took place in Google’s offices in NYC, and that was neat.

It was cool how many people knew of ThoughtWorks, and were interested in talking about what it was like to work there. (Probably less than the number that were interested in Google in the same way, but hey…) We ended the conference by finishing up with the afterparty in the wee hours of the morning. It was fun! Amazingly, both Deepthi and I won swag at the event - I got this neat laptop bag, and Deepthi got Rails Recipes. Oh, and here are some pictures.

You might want to read some live-blogging from the event.

Posted in conference, rails, ruby | No Comments »

The joys of large-screen monitors

Posted by Amit Rathore on April 16, 2007

In my ideal world, I’d have two 30″ Apple Cinema Displays, but my less than ideal world ain’t so bad either. My souped-up 24″ iMac serves me well for my day to day work, quite well indeed.

I’m positive that my productivity gains are large - I always have emacs open with at least 4 frames, or eclipse with several views open without anything important having to stay annoyingly minimized. I also have a browser open with lots of tabs, a bunch of terminals open with iTerm, and a bunch of other what-nots, and managing all this is easy. This multiple desktop manager makes it even easier. Finally, if all those windows distract you, use Think!

Anyway, if you want a quick and relatively cheap way (in the long run) to become more productive, get a large screen monitor. Or three.

Posted in code, tech, tools | No Comments »