Saturday, March 16, 2019

ALL ABOUT KOTLIN

Image result for kotlin

WHAT IS KOTLIN?

Kotlin is a cross-platform, statically typed, general-purpose programming language with type inference. Kotlin is designed to interoperate fully with Java, and the JVM version of its standard library depends on the Java Class Library, but type inference allows its syntax to be more concise. Kotlin mainly targets the JVM, but also compiles to JavaScript or native code (via LLVM). Kotlin is sponsored by JetBrains and Google through the Kotlin Foundation.
Kotlin is officially supported by Google for mobile development on Android. Since the release of Android Studio 3.0 in October 2017, Kotlin is included as an alternative to the standard Java compiler. The Android Kotlin compiler lets the user choose between targeting Java 6 or Java 8 compatible bytecode.


KOTLIN EVOLUTION:

                   " Language design is cast in stone,
                    but this stone is reasonably soft,
                    and with some effort we can reshape it later. "
              ~Kotlin Design Team
Kotlin is designed to be a pragmatic tool for programmers. When it comes to language evolution, its pragmatic nature is captured by the following principles:
Keep the language modern over the years.
Stay in the constant feedback loop with the users.
Make updating to new versions comfortable for the users.
As this is key to understanding how Kotlin is moving forward, let's expand on these principles.


1.Keeping the Language Modern.


We acknowledge that systems accumulate legacy over time. What had once been cutting-edge technology can be hopelessly outdated today. We have to evolve the language to keep it relevant to the needs of the users and up-to-date with their expectations. This includes not only adding new features, but also phasing out old ones that are no longer recommended for production use and have altogether become legacy.


2.Comfortable Updates.


Incompatible changes, such as removing things from a language, may lead to painful migration from one version to the next if carried out without proper care. We will always announce such changes well in advance, mark things as deprecated and provide automated migration tools before the change happens. By the time the language is changed we want most of the code in the world to be already updated and thus have no issues migrating to the new version.


3.Feedback Loop.


Going through deprecation cycles requires significant effort, so we want to minimize the number of incompatible changes we'll be making in the future. Apart from using our best judgement, we believe that trying things out in real life is the best way to validate a design. Before casting things in stone we want them battle-tested. This is why we use every opportunity to make early versions of our designs available in production versions of the language, but with experimental status. Experimental features are not stable, they can be changed at any time, and the users that opt into using them do so explicitly to indicate that they are ready to deal with the future migration issues. These users provide invaluable feedback that we gather to iterate on the design and make it rock-solid.

Image result for pros and cons of kotlin


ADVANTAGES OF KOTLIN:


1. Language and environment are mature:


Unlike other languages like Swift, the Kotlin release has gone through many stages before releasing the final 1.0 release.This means that there are hardly any problems when working with Kotlin, everything works as you would expect


2. It makes Android development much easier:


If you’ve been reading this series of articles about Kotlin, you’ve probably seen it crystal clear many times.Kotlin is simplicity mixed with power, so you have an new world of possibilities if you’re coming from Java that you couldn’t even imagine.


3.  Shrinks the Base code to Enhance Productivity:


Developers often make certain shortcuts while programming to reach a deadline. This is called technical debt that generally reduces productivity and slows down the development.
Kotlin helps developers to reduce technical debt to a certain extent. It shrinks the base code and which further improves the code quality. If you shift to Kotlin, you will see a reduction in the number of lines of code. This makes code maintenance a lot easier.


4. Kotlin is Concise:


Kotlin is a way more concise than Java. It doesn’t only save time but also promotes readability and code maintainability.
If you are a developer, you won’t have to deep dive into the sea of logic and code to solve a simple bug. With Kotlin, you can read, write and change code more efficiently. Kotlin brings many useful features like smart casts, data classes, type interference, etc.


DISADVANTAGES OF KOTLIN:


Although Kotlin is great, it’s not perfect. Here are a few aspects of the language that I’m not in love with.


1. No namespaces:


Kotlin allows you to define functions and properties at the top level of your files. That’s a great feature, but it can cause some confusion when combined with the fact that all top level declarations are referenced unqualified from Kotlin. This can sometimes make it difficult to tell what a function is when reading one of its usages


2. No static modifier:


Following on the previous point, Kotlin has unusual handling of static function and property declarations that are called from Java. It’s not bad, but it feels dirtier than necessary.


3. Automatic conversion of Java to Kotlin:


This was the first topic in the list of things I like about Kotlin, and it works well. But because it work so well 80% of the time, many of the cases where it fails can be frustrating.


4.Closed by default:


Every downside to Kotlin I’ve talked about so far are mostly small syntax details that are not quite as clean I’d like, but aren’t a big deal overall. But there’s one design decision that is going to cause a huge amount of pain in the future: All classes and functions in Kotlin are closed by default. It’s a design decision pushed by Effective Java, and it might sound nice in theory, but it’s an obviously bad choice to anyone who’s had to use a buggy or incomplete third-party library.

Image result for kotlin

WHY YOU SHOULD SWITCH TO KOTLIN:

Why would a Java Developer switch to Kotlin?
Java is a widely used programming language and forms the basis of Android development. There can be many reasons why Java cannot always be considered the best choice for Android development.


Reasons can be:


o   Java is not a modern language.
Android only supports a subset of Java 8 features. In a way, Android developers are not able to reap full benefits of Java. In case they require making use of Java, then they will have to stick to Java 7.

o   Java comes with some well-documented language issues like endless try-catch blocks, null-unsafety, NullPointerExceptions and lack of extendability.

o   Java is still a procedural language although it is starting to add lambda expressions and functional interfaces recently

o   The syntax of Java is very complex and writing longer code can always be prone to more errors and bugs

o   Java can create issues with Android API design

o   Do you still need to remember most of the code while you code in Java? It can be creepy and messy sometimes!


Image result for kotlin and android


WHY IS GOOGLE SUPPORTING KOTLIN FOR ANDROID DEVELOPMENT?


1. The Modernity:


Having Java integrated in your work life is a good thing, but more than often you look at a problem, stop for a second to think to yourself : “Is this really the best way I can do it in Java?”.
Well, Kotlin has all the features of modern languages you’d want! Kotlin has a safe Nullability system, Lambdas and Method references for clean connections between parts of your App, a built in Mutability/Immutability property system, a clean and easy to use Stream operators(filter, map, reduce..), to improve your development life and productivity!


2.  The Interop:


Yeah all the features above sound pretty decent, and one might think, okay, but how will this affect my legacy code, or current state of a newly started project? You don’t have to worry a single bit, Kotlin and Java are 100% interoperable, meaning you can have any percentage of code written in Kotlin, and the rest in Java, and it will all just work together!
Even better, there is a tool in AS that allows you to instantly “translate” Java into Kotlin, which works quite well most of the time, so you can have a glimpse into what does a method in Java look like in Kotlin.


3. The Community:


Java is great, it has a large number of users, the tutorial sea is vast, and you can pretty much find an answer to any problem on SO right? But the language itself is very closed, it’s development is hardly influenced by the needs of Java developers. Kotlin is quite the opposite! Jetbrains team takes every idea and proposal from the community and keeps them in mind while developing the language.
The language is also Open sourced on Github, so you can check it out anytime!


4.  The Native:


This might not be an Android specific reason, but it’s definitely worth the mention. Kotlin Native is a milestone Jetbrains is working on reaching, with the idea of running Kotlin code in mutliple platforms, without having to compile it down to JVM, making it much faster, and not requiring Java. The platforms to be are Web (both backend and frontend), iOS (yes!) and Game development.


TO KNOW WHICH BOOKS TO REFER GOTO:

REFERENCES:

7 comments:

R ~ NOT JUST AN ALPHABET

R is a programming language and software environment for statistical analysis, graphics representation and reporting. R was created...