be solved by a computer A general-purpose language is imperative, specifying the operations to solve the problem What is a DSL? Domain-specific language A domain-specific language focusses on solving problems in a specific domain A domain-specific language is declarative, describing the required result ! 7
Requires string concatenation and parsing What is an internal DSL? Internal DSL Restricted by the syntax of a general purpose language No concatenation or parsing necessary ! 8
- removes syntactic noise • Dropping . and ( ) by infixing functions str should startsWith("Space") is more readable than assertTrue(str.startsWith(“Space")) • Extension functions - makes existing code more fluent • No ( ) required for last lambda argument - removes syntactic noise • Lambdas with receivers • Invoke convention ! 10
var rendezvousShuttles: MutableList<Shuttle> = LinkedList() var board = this var launch = LaunchTime() var rendesvouz = this var land = LandTime() infix fun on(ship: Shuttle) { shuttle = ship } infix fun with(destination: Shuttle) { rendezvousShuttles.add(destination) } }
only solutions to problems for a specific domain • DSLs are concise, readable, and maintainable • Language features like lambdas with receivers support the creation of readable DSLs ! 17
• Suspendable computations are functions that suspend at some point, and resume at a later point - without blocking the thread • launch, async are examples of coroutine builders • Flows are cold, asynchronous data streams that sequentially emit values • Channels can be used to communicate between coroutines ! 40
API, without the heap allocations of wrapper classes • Contracts give the compiler extra information about a code - use with caution • Immutable collections prevent the underlying data from being modified ! 51