Take the 2-minute tour ×
User Experience Stack Exchange is a question and answer site for user experience researchers and experts. It's 100% free, no registration required.

I'm looking at implimenting a DSL, for managing inventory/orders. In this case it is for a game (Minecraft, with computercraft + Applied Energistics), however it could as reasonably be a real world system, for example manufacturing cars. A large portion of my motivation for making this is to experiment with DSL crafting/design.

It will probably be implemented in Lua, but the user shouldn't nesc realise they are writing Lua code for adding rules.

So I am trying to decide what contructs/functions the DSL should provide.

Current ideas include, as basic primitives:

  • Order(qty, item)
  • CurrentStock(item) = qty
  • OnOrder(item) = true/false

Then I would need some helper functions, KeepStock(qty,item)

which the user could have build out of primitives:

if CurrentStock(item)<qty and not OnOrder(item) then Order(qty-CurrentStock(item), item) end


Examples of how I'm envisioning the DSL could be used:

  • if CurrentStock("wheat")>100 then Order(10, "Bread") end
  • KeepStock(100, "Iron Ingots")

Questions

Syntaxtic Sugar:

What functions should I have, in such a DSL? Perhaps I should have a function StockDeficit(item, qty) helper? equivalent to: math.max(qty - CurrentStock(item), 0)

  • instead of (or as well as) `KeepStock(100, "Iron Ingots")
  • have if StockDeficit("Iron Ingot", 100) then Order("Iron Ingot", StockDeficit("Iron Ingot, 100) end

Perhaps it is important to have methods for querying capacity to have orders filled? Some kind of FreeCapactityFor(item), that could be used: like If FreeCapacityFor("Bread") then Order(1, Bread) end

Is it worth cleaning the syntax, making it more natural language like: so that:

  • instead of: if CurrentStock("wheat")>100 then Order(10, "Bread") end
  • we have: if CurrentStock(wheat)>100 then Order(10, Bread) end
  • or even: if wheat>100: Order 10 bread

back on the earlier example, is it worth making, the language context sensitive:

  • instead of: if StockDeficit("Iron Ingot", 100) then Order("Iron Ingot", StockDeficit("Iron Ingot, 100) end
  • have: if StockDeficit("Iron Ingot", 100) then Order(StockDeficit) end

Overarching these questions is the general case: How do you determine what functionality a user needs from a DSL? I do not expect an answer to this final question as it it too broad. However, answers might reference it to explain how they came to their conclusions. Determining the syntactic requirements doesn't seem too hard, mostly a matter of judging how technically skilled they are (eg in some domains, they would be fine, knowing they are in fact just writing Lua code with a particular set of functions available) However users are notoriously bad at knowing what they want. Are the good techniques, like User Stories, or survaying their current pactices for a few hours/days, that are better than others for capturing requirements, specifically for DSLs?

share|improve this question
    
You are trying to create a DSL for a stock management rule engine. Trying searching for "rule engine language" and check out scratch. –  Danny Varod Oct 7 '13 at 2:05
add comment

2 Answers

up vote 1 down vote accepted

I'd read a book about DSLs. Martin Fowler also talkes about them on his website, which may be helpful.

Also, if you have time before your assignment, try to use a few DSLs.

Is it worth cleaning the syntax, making it more natural language like

Yes. To the best ability your team has.

DSL's are pretty good at helping teams be more productive because they offer a few benefits over more generic languages:

  • improved clarity - the signal/noise ratio is improved because the DSL omits irrelevant syntax
  • improved understandability - the semantics of the DSL are concerned with a specific problem space, so anyone familiar with that problem space will understand the DSL

What functions should I have, in such a DSL?

Whatever would make the team/user more productive.

However, the more complex the DSL becomes, the more difficult it will be to understand and use. So it depends on your audience.

How do you determine what functionality a user needs from a DSL?

Again, the DSL should be focused on productivity. Whatever makes the user more productive.

Hope this helps.

share|improve this answer
add comment

Have you seen Ayende Rahien's use of Boo in .NET to wrap his C# code that does generic programming on arbitrary C# objects? He created a DSL in Boo, which pretty much does what you want and integrates with static type checking to guarantee some basic correctness. He wrote about it in his book on DSLs.

share|improve this answer
    
I have not. Care to inprove this answer with a few quotes? Or a general gist of what he spoke about? –  Oxinabox Sep 7 '13 at 4:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.