Basic language syntax and features
Whether you come from Java, C#, Scala, or any other statically typed programming language, you'll find Kotlin syntax quite familiar. This is not by coincidence but to make the transition to this new language as smooth as possible for those with previous experience in other languages. Besides that familiarity, Kotlin brings a vast amount of features, such as better type safety. As we move ahead, you'll notice that all of them are attempting to solve real-world problems. That pragmatic approach is remarkably consistent across the language. For example, one of the strongest benefits of Kotlin is complete Java interoperability. You can have Java and Kotlin classes alongside each other and freely use any library that is available in Java for a Kotlin project.
To summarize, the goals of the language are as follows:
- Pragmatic: Makes things we do often easy to achieve
- Readable: Keeps a balance between conciseness and clarity on what the code does
- Easy to reuse: Supports adapting code to different situations
- Safe: Makes it hard to write code that crashes
- Interoperable: Allows the use of existing libraries and frameworks
This chapter will discuss how these goals are achieved.
Multi-paradigm language
Some of the major paradigms in programming languages are procedural, object-oriented, and functional paradigms.
Being pragmatic, Kotlin allows for any of these paradigms. It has classes and inheritance, coming from the object-oriented approach. It has higher-order functions from functional programming. You don't have to wrap everything in classes if you don't want to, though. Kotlin allows you to structure your entire code as just a set of procedures and structs if you need to. You will see how all these approaches come together, as different examples will combine different paradigms to solve the problems discussed.
Instead of covering all aspects of a topic from start to finish, we will be building the knowledge as we go.