...
Full Bio
Use Machine Learning To Teach Robots to Navigate by CMU & Facebook Artificial Intelligence Research Team
227 days ago
Top 10 Artificial Intelligence & Data Science Master's Courses for 2020
228 days ago
Is Data Science Dead? Long Live Business Science
256 days ago
New Way to write code is about to Change: Join the Revolution
257 days ago
Google Go Language Future, Programming Language Programmer Will Get Best Paid Jobs
578 days ago
Top 10 Best Countries for Software Engineers to Work & High in-Demand Programming Languages
725025 views
Highest Paying Programming Language, Skills: Here Are The Top Earners
669372 views
Which Programming Languages in Demand & Earn The Highest Salaries?
474495 views
Top 5 Programming Languages Mostly Used By Facebook Programmers To Developed All Product
463479 views
World's Most Popular 5 Hardest Programming Language
394998 views
Why Kotlin Is The Next Programming Language Every Programmer Should Know
Kotlin comes from industry, not academia. It solves problems faced by working programmers today. As an example, the type system helps you avoid null pointer exceptions. Research languages tend to just not have null at all, but this is of no use to people working with large codebases and APIs which do.
- Beyond Android, I think Kotlin is highly suitable for enterprise Java shops. If you spend all day working on big Java codebases at even bigger companies, you should investigate Kotlin because:
- It has strong commercial support from an established company. JetBrains is committed to the project, has a large and highly competent team working on it, has a stable business model and is even converting parts of their own flagship product to use it. Kotlin is unlikely to be abandoned any time soon.
- Adopting Kotlin is a low risk: it can be trialed in a small part of your code base by one or two enthusiastic team members without disrupting the rest of your project: Kotlin classes export a Java API that looks identical to that of regular Java code.
- Because Kotlin focuses on readable syntax, code reviews are not a problem: they can still be done by team members who aren't familiar with the language.
- It targets Java 6, so you can use it even if your deployment makes upgrading to a newer JVM difficult.
- We already mentioned null safety (optionality), that lets the compiler systematically flag potential null pointer dereferences. Unlike some languages, this does not involve an option type and is therefore zero-overhead. Other language features ensure it's not inconvenient.
- Lean syntax: type inference works everywhere, one-liner functions take one line, simple structs/JavaBeans can also be declared in one line. Real properties generate getFoo/setFoo methods behind the scenes for Java interop. Functions can exist outside of classes.
- Exceptions are unchecked.
- Adding the data annotation to a class triggers autogeneration of boilerplate like equals, hashCode, toString, a copy method and variable spreading support (restructuring). This gives you convenient immutable classes without the need for builders.
- But if you do need to construct complex structures, a clever intersection of language features makes builders clean and type-safe (read: auto-completable). If you use Google Protocol Buffers to store structured data, that gets easier too.
- Functional programming support with zero-overhead lambdas and ability to do mapping, folding etc over standard Java collections. The Kotlin type system distinguishes between mutable and immutable views over collections.
- Extension functions let you add methods to classes without modifying their source code. This looks at first like a superficial bit of syntax sugar to avoid FooUtils style classes. Then you realize that doing it this way enables you to easily discover the new methods via auto-completion, lets you build powerful language extensions and lets you integrate existing Java APIs with other Kotlin features. Features like ...
- Operator overloading. But the good kind: no Scala / Perl style line noise here. Operators map to special method names so can override the behavior of the existing operators (including function invocation), but you cannot define entirely new ones. This strikes a balance between power and readability.
- Kotlin does not have macros or other ways to redefine the language, but a collection of carefully designed features allow for libraries that act like language extensions far more than they act like collections of objects. A good example: would you like to use fibers, actors, and Go-style channels? A library called Quasar has you covered.
- Markdown instead of HTML for your API docs. This makes writing JavaDocs much more pleasant. The "Dokka" tool, which is the equivalent of JavaDoc, can read both Kotlin and Java source code and generate combined doc websites, both with its own style and also in the standard JavaDoc HTML style.
- Better generics. If you never fully got to grips with what exactly super and extends mean when put inside a type variable, don't worry: it's not you. Java's generics really are just confusing. Kotlin fixes it.
- Delegation (forwarding methods) can be done automatically.
- The == operator does what you actually expect.
- Would you like fast and convenient async programming? Of course, you would.
- String interpolation "works like ${this.example}!"
- Function arguments can be named, optional and variadic.
- Many, many other tweaks and improvements. If something annoyed you about Java, I give it 50/50 that it's fixed in Kotlin.
NOTE: This article was originally written in July 2015. By now this section has become inaccurate as various issues were fixed by JetBrains. I have marked the resolved issues below in bold, but left the text as-is.
- The data class feature is a very useful way to auto-generate JavaBean boilerplate, but it imposes severe limitations: such classes cannot inherit from anything, nor be inherited from. This, in turn, makes the "sealed class" feature rather less useful, as you can't have a sealed hierarchy of data classes. JetBrains say they want to relax the constraints on data classes in a future version when they figured out exactly what the behaviors involved should be. (Kotlin 1.1: data classes may inherit from other classes)
- There are no type aliases yet. So, function types have to be written out redundantly each and every time. (1.1 added type aliases)
- The IDE plugin still throws exceptions more often than it should. These don't ever seem to break anything so are a minor nuisance compared to what a crash in a native-code IDE would be. But the "Internal IDE error" bubble can still be an irritant.
- By default, classes are final. You have to mark them as "open" if you want the standard Java behavior. Some Java frameworks that rely on bytecode synthesis assume classes won't be final and can fail or silently do the wrong thing when encountering Kotlin code. This isn't Kotlin's fault, but I've still had a non-trivial amount of time wasted by having to debug this. As Kotlin gets more widespread I expect such frameworks to improve. (1.1 adds some compiler plugins for popular frameworks that auto-open classes at the right time)
- Kotlin supports compile-time function inlining. This makes the use of higher order functions like map/filter/reduce very cheap at runtime, and so it's common to use it a lot. Inlining also allows you to work around the JVM's lack of reified generics in some cases and do non-local returns, like exiting a function from inside a lambda. These are good things! But they come at a cost: because the JVM doesn't understand what's happened, stack traces can sometimes get messed up. IntelliJ attempts to "un-scramble" stack traces that have been made confusing thanks to function inlining, but it's still common to encounter exception stacks that refer to non-existent line numbers and other bizarre oddities. Ideally, Kotlin wouldn't have to do this because JVMs would have all the features needed. But they don't, so, we're probably stuck with this unless the JVM learns how to handle functions that were inlined by the language frontend.
- Kotlin targets Java 6 bytecode. It does not use some of the improvements in Java 8. One minor issue is that the Kotlin standard library sometimes duplicates things that Java 8's standard library also provides. Also, the compiler doesn't use the "invoke dynamic" bytecode to reduce the number of class files generated by lambdas, so Kotlin JARs that use a lot of non-inlineable lambdas can get a bit bloaty compared to Java 8. Fixing this is high up on JetBrain's agenda so hopefully, it'll get done soon.
- Compilation inside IntelliJ is incremental and extremely fast (as fast as Java). Compilation through Gradle is slow because it's not incremental at all. Avoid compiling through Gradle if you can. Again, this is high up on their list of things to fix. (fixed in 1.1)
- There's no equivalent of macros or compiler plugins, so if you like macros from Scala or things like the Checker Framework from Java, sorry, you'll have to do without.
- The community is small. Whilst the excellent Java interop means you don't really need Kotlin libraries, they're still nice to have and currently there aren't many.
- FP purists may feel the type system is lacking some of the more advanced features that can be found in Scala or Haskell. If you're the sort of person who cares about this more than average, Kotlin may not be for you. The funKTionale library adds some constructs known from Haskell to the language like partial application, function currying, memorization etc.
- Whilst it can compile down to JavaScript, this mode is experimental and a lot buggier/unfinished compared to the Java backend. (done in 1.1)
- There is no standard style guide, and at points, Kotlin gives you several alternative syntaxes to choose from. Kotlin written by different people may look different. This is in contrast to Go, which enforces style rigidly. (there is now a simple conventions document)
- There is an Eclipse plugin for Kotlin, but it is naturally much less sophisticated than the IntelliJ support. Kotlin will work best if your team standardizes on IntelliJ.
- Kotlin is pickier about some things than Java. It will not auto convert integers to longs and such, you are required to specify you want the conversion explicitly. This is because the language has a focus on correctness and attempts to fix the issues found in the famous "Java Puzzlers" book. JetBrains claim they nailed about half of them.
- Because Kotlin targets Java 6 it is restricted to the features that runtime has. Whilst it can match or exceed C# in many areas, it lacks features like value types which aren't yet a part of the Java platform.