• Suspendable computations suspend and resume - without blocking the thread • Coroutines are performant, readable, and compatible with JetPack • launch, runBlocking, async are examples of coroutine builders ! 24
FlightPath(val origin: Point, val destination: Point) {...} val spaceStationPosition = Point(100.0, 100.0) val spaceShuttlePosition = Point(10.0, 10.0) val earth = Point(0.0, 0.0) val flightPath = FlightPath(earth, spaceStationPosition) val onTrack = spaceShuttlePosition in flightPath
FlightPath(val origin: Point, val destination: Point) {...} val spaceStationPosition = Point(100.0, 100.0) val spaceShuttlePosition = Point(10.0, 10.0) val earth = Point(0.0, 0.0) val flightPath = FlightPath(earth, spaceStationPosition) for(checkpoints in flightPath){ println(checkpoints) }
names • Conventions are concise, readable, and maintainable • Consider understandability - use well-known concepts, and check with others using code reviews ! 42
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 focuses on solving problems in a specific domain A domain-specific language is declarative, describing the required result ! 44
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 ! 45
- 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 ! 47
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 ! 51