Recent Posts
Archives

Posts Tagged ‘CodeStyle’

PostHeaderIcon [KotlinConf2018] Crafting the Next Great Kotlin Novel: Lisa Wray’s Exploration of Expressive Coding

Lecturer

Lisa Wray is a mobile developer and Google Developer Expert for Android, specializing in user interfaces. Holding a B.S. in music and computer science from M.I.T., she works at Present, a local social network, with prior roles at Google, The New York Times, and Genius. Relevant links: Present Website (professional page); LinkedIn Profile (professional page).

Abstract

This article delves into Lisa Wray’s exploration of Kotlin’s expressive potential, drawing parallels with literary principles from authors like William Zinsser and Stephen King. Contextualized in the transition from Java’s rigidity, it examines methodologies for balancing brevity, maintainability, and domain-specific languages (DSLs). The analysis highlights innovations in Kotlin’s syntax, implications for code quality, and the delicate balance of expressive freedom.

Introduction and Context

Lisa Wray captivated the KotlinConf 2018 audience with a unique perspective, likening Kotlin coding to writing a novel. Transitioning from Java’s prescriptive nature, Wray found Kotlin’s expressive freedom inspiring yet challenging. Her talk, inspired by literary works like On Writing Well and On Writing, navigates the question of how to wield Kotlin’s features—such as concise syntax and DSLs—without sacrificing clarity or maintainability. This narrative unfolds in a context where developers, liberated from Java’s boilerplate, seek guidelines beyond official style guides to craft robust, readable codebases.

Methodological Approaches to Expressive Coding

Wray proposed applying literary principles to coding. Clarity, akin to Zinsser’s advice, demands concise yet understandable code. She advocated selective use of Kotlin’s features: lambdas, extension functions, and optional syntax like type inference. For DSLs, she explored lambda-with-receiver constructs, where a builder class defines a custom interface, as seen in Kotlin’s apply or with. Her methodology emphasized restraint—using DSLs judiciously to avoid complexity. She cautioned against overusing custom DSLs, which add maintenance overhead, while endorsing well-crafted third-party DSLs that leverage Kotlin’s syntax.

Analysis of Innovations and Features

Kotlin’s innovations lie in its expressive syntax: lambdas reduce verbosity, and DSLs create domain-specific interfaces within Kotlin’s grammar. Compared to Java, Kotlin’s flexibility allows poetic code, but Wray warned of Perl-like obscurity. Her golden rule—avoid DSLs where named parameters suffice—curbs boilerplate. Third-party DSLs, when thoughtfully designed, enhance rather than pollute codebases, as they reuse Kotlin’s syntax. Limitations include the tediousness of crafting DSLs and the risk of over-concision, which may obscure intent.

Implications and Consequences

Wray’s approach implies a shift toward intentional coding, where developers weigh brevity against maintainability. It encourages teams to define project-specific style guides, fostering consistency in large codebases. The consequence is a codebase that balances expressiveness with clarity, aiding collaboration and longevity. However, over-reliance on DSLs could deter new developers, necessitating careful documentation.

Conclusion

Wray’s literary analogy reframes Kotlin coding as an art form, urging developers to harness its expressive power thoughtfully. By blending writing principles with technical restraint, she offers a path to crafting maintainable, impactful code—perhaps the next great Kotlin novel.

Links