Читать книгу Programming Kotlin Applications - Бретт Мак-Лахлин, Brett McLaughlin - Страница 89

WRITING CODE IS RARELY LINEAR

Оглавление

If you take a step back and consider what you've done over these last two chapters, it's both cool and potentially a little confusing. The cool part is even if you've never written a line of Kotlin before, you've now got a functioning class that exercises some of Kotlin's key and relatively unique features: objects, construction, and overriding superclasses (more on that later), as well as the somewhat unusual requirements Kotlin enforces around property value assignments.

What could be a bit confusing, though, is how you got to the terse code in Listing 2.10. You added properties, removed them, added a couple of custom mutators, removed those, and ultimately deleted nearly as much code as you added. Wouldn't it have been easier to just jump right to Listing 2.10?

Well, it might have, but it wouldn't have been that helpful in getting you to see how Kotlin works. Arguably just as important, it wouldn't be realistic. Seasoned developers are constantly going through this same process: trying things out, then adding something new, having to go back and change old code to accommodate new code, tweaking, and removing as much as is added. It's common to refactor—to restructure code to make it less redundant, more efficient, more organized, and generally just better.

That's really the point if you're learning Kotlin, too: to get more than just a syntactical understanding. You want to be a good developer? Keep adding things, removing things, and taking a fresh look to make sure your code is the right code.

Programming Kotlin Applications

Подняться наверх