Java Reference
In-Depth Information
are a special case of loans to people or a different type of loan. So, using this approach could
allow us to model the underlying problem domain more closely.
Lambda-Enabled Domain-Specific Languages
A domain-specific language (DSL) is a programming language focused on a particular part
of a software system. They are usually small and frequently less expressive than a general-
purpose language, such as Java, for most programming tasks. DSLs are highly specialized:
by trading off being good at everything, they get to be good at something.
It's usual to split up DSLs into two different categories: internal and external . An external
DSL is one that is written separately from the source code of your program and then parsed
and implemented separately. For example, Cascading Style Sheets (CSS) and regular expres-
sions are commonly used external DSLs.
Internal DSLs are embedded into the programming language that they are written in. If
you've used mocking libraries, such as JMock or Mockito, or a SQL builder API such as
JOOQ or Querydsl, then you'll be familiar with internal DSLs. In one sense, they're just reg-
ular libraries that have an API designed to be fluent. Despite their simplicity, internal DSLs
are valued because they can be a powerful tool for making your code more succinct and easi-
er to read. Ideally, code written in a DSL reads like statements made within the problem do-
main that it is reflecting.
The introduction of lambda expressions makes it easier to implement DSLs that are fluent
and adds another tool to the belt of those wanting to experiment in the DSL arena. We'll in-
vestigate those issues by building a DSL for performing behavior-driven development
(BDD) called LambdaBehave .
BDD is a variant of test-driven development (TDD) that shifts the emphasis onto talking
about the behavior of the program rather than simply the tests that it needs to pass. Our
design is inspired by the JavaScript BDD framework Jasmine, which has been getting heavy
use in frontend circles. Example 8-27 is a simple Jasmine suite that shows you how to create
tests using Jasmine.
Example 8-27. Jasmine
describe ( "A suite is just a function" , function
function () {
it ( "and so is a spec" , function
function () {
var
var a = true
true ;
expect ( a ). toBe ( true
true );
Search WWH ::




Custom Search