Hello to this new post! This is part 3 of my blog post series about “How the book Effective Java may have influenced the design of Kotlin.” I wrote the first and second part about half a year ago and thought that I figured out every aspect of how Effective Java could have possibly influenced the programming language Kotlin.
A few months ago however, I bought and read, what is, in my opinion, the best book on Kotlin: Kotlin in Action. It is written by Dmitry Jemerov and Svetlana Isakova, who are Kotlin core developers working at JetBrains. They definitely know what they are talking about. If you want to advance your Kotlin Knowledge to the next level, I definitely recommend you to read Kotlin in Action 📘!
While reading the book, I discovered new language features and design choices that were also likely to have been influenced by Effective Java.
This is the second part of the blog series about how the book “Effective Java” may have influenced Kotlin’s design. Before continuing, take a look on the first part if you have not already read it.
6. Final classes by default
Item 17 in “Effective Java” suggests that every class should either not be sub-classable or be carefully designed and documented to support inheritance. In Java, every class can be subclassed unless you explicitly specify the class as final. If you forget to make the class final and fail to design and document it for inheritance, there will be trouble when clients think that they can create subclasses, override some methods and assume that everything will still work as expected.
Java is a great programming language but has some known flaws, common pitfalls and not-so-great elements that have been inherited from its early days (1.0 got released in 1995). A well-respected Book on how to write good Java code, avoid common coding mistakes and deal with its weaknesses is Joshua Bloch’s “Effective Java.” It contains 78 sections, called “Items”, that give the reader valuable advice on different aspects of the language.
Code Complete 2 from Steve McConnell surely belongs to one of the bibles of software development. A lot of developers recommended this book to me and so I decided to read it and write about four things that I learned from this book that are valuable in my day to day Android development adventures. In my opinion, it is very important to spend some time reading books that deal with the basics of software construction. As Android developers, we are always tempted to only spend time learning new shiny technologies or libraries like RxJava2 and forget to learn or relearn the foundation of all programming: Writing clean, readable and maintainable code. Although this book is a little bit old (2004), most of the contained knowledge applies to current software development processes and programming languages.