,

Improving Kotlin Code with Refactoring | Dmitry Kandalov and Duncan McGregor

Posted by



Refactoring to Expressive Kotlin is a concept introduced by Dmitry Kandalov and Duncan McGregor in their talk at KotlinConf 2017. This talk aimed to show how developers can transform their existing Java codebase into more expressive and concise Kotlin code.

Refactoring is the process of restructuring existing code without changing its external behavior. By applying refactoring techniques, developers can make their code more readable, maintainable, and efficient.

In the context of Kotlin, refactoring to expressive Kotlin means leveraging the language features and idioms to write more succinct and expressive code. Kotlin provides several language features that can help developers reduce boilerplate code, eliminate null references, and improve code readability.

In their talk, Dmitry and Duncan presented a series of refactoring examples where they transformed Java code into Kotlin. They showed how Kotlin’s concise syntax, data classes, extension functions, and sealed classes can help simplify the code and make it more expressive.

One of the key concepts they discussed was the use of data classes in Kotlin. Data classes allow developers to define classes with minimal boilerplate code. In Kotlin, a data class automatically generates toString(), equals(), hashCode(), and copy() methods, which can help reduce the amount of code developers need to write.

Another important concept they covered was the use of extension functions in Kotlin. Extension functions allow developers to add new functionality to existing classes without modifying their source code. This can help improve code readability and maintainability by keeping related functions together.

They also discussed the benefits of using sealed classes in Kotlin. Sealed classes are a way to represent a restricted hierarchy of classes. By using sealed classes, developers can enforce exhaustiveness checks when working with sealed class hierarchies, which can help prevent bugs and make the code more robust.

Overall, refactoring to expressive Kotlin is about embracing the language features and idioms to write cleaner, more concise, and more maintainable code. By applying these concepts to existing codebases, developers can take advantage of Kotlin’s expressive syntax and powerful features to improve their code quality and productivity.

0 0 votes
Article Rating
5 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@emmanuelmtali1594
3 months ago

You wasted my time a little bit 🤕 (Renaming)

@mytubekt
3 months ago

Very nice talk! Thanks for sharing.

@lppedd
3 months ago

I always beg my fellow devs not to use also, apply, let (or other scope functions). They make the code a PITA to read.

@three-alpha-six
3 months ago

That definitely was the most excruciating rename of a simple function that wasn’t even necessary in the first place.

@JPilsonSumbo
3 months ago

Fun to watch