Groovy for Domain-specific Languages - Second Edition

(nextflipdebug2) #1
Chapter 12

[ 313 ]

So this chapter is a response to that need. It's been coded part-time over a period of a
few weeks. What I'll present here is a work in progress and it is presented warts and
all. It is, however, a worthy illustration of a real life DSL integrated into lots of the
technologies you might end up using yourselves. Let's look at what the goals were
when writing this DSL and how they impacted the technology choices I made.


A game DSL – goals



  • The first goal for this DSL was to get beyond the console-bound apps that
    we had been building. Something that could work in conjunction with a
    web-based UI would be good but ideally something that would allow a
    mobile app as the UI would be best.

  • We needed to build on the existing skills that the kids had acquired.

  • There would need to be a very simple interaction between the game logic on
    the one hand and the user interface on the other. The kids would need to be
    able, in time, to work on both aspects.

  • We used the Cloud9 online web-based IDE https://c9.io/. So we needed a
    solution that would run on a remote workspace. The mentors typically used
    a premium workspace account but the students worked on free accounts,
    which limited their VMs to 512 MB RAM and 1 GB disk. Ideally, we wanted
    to be able to run the environment and compile the DSL code on the student's
    free accounts.


Architecture and technology choices


We needed a user interface technology that would be familiar to the kids and
support both web and mobile. A combination of HTML5 with jQuery mobile is what
I picked. jQuery mobile has a good page-oriented model for display purposes which
fits well with the page-oriented state model we will implement in the game DSL.


The page content needed to be dynamic based on the current game state, so some
sort of page templating engine was needed. Mustache.js is a good fit here. Mustache
templates are very close to pure HTML so the kids would be on familiar territory
when using them.


The UI works as a single-page app (SPI) and communicates with the game engine
backend via JSON AJAX calls. The game server is a Spring MVC app, which is
bootstrapped easily using Spring Boot and responds to all calls in JSONP.

Free download pdf