Context
Context is one of the characteristics of a DSL. As humans, we rely heavily on context when we communicate. We’re efficient, and context provides for continuity in our conversations. The other day I heard my friend Neal holler, “Venti latte with two extra shots!” He was using the Starbucks DSL. Nowhere did he mention the word “coffee,” but he sure got one, at a high price. That’s context-driven.
Let’s look at Java code to order pizza. This code lacks context. The reference joesPizza is used repeatedly:
CreatingDSLs/OrderPizza.java | |
| //Java code |
| package com.agiledeveloper; |
| |
| public class OrderPizza { |
| public static void main(String[] args) { |
| PizzaShop joesPizza = new PizzaShop(); |
| joesPizza.setSize(Size.LARGE); ... |
Get Programming Groovy 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.