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.