What is it, Kotlin?

Asked

Viewed 4,649 times

27

I’ve heard a lot about Kotlin.

What is this? Is it a programming language? If so: What are the main features? Can I program on any operating system? And run? How do the guys in it work?

I don’t want to know everything, but basic information about what this is.

1 answer

30


A wonderful language, that’s all I have to say :P

Okay, aside from the fun, it’s a language created by Jetbrains, owner of an IDE that many consider to be the best in the market, such as the Intellij, and that of Resharper, that many consider a plugin indispensable for Visual Studio, among other good products.

It seems that they have created it to have a better tool to develop their own products. Moreover, the original idea was to have a language that generates bytecodes for the JVM and for the CLR, so much of the code used in product could be reused in other. Today they basically develop in Java, and replicate a lot of C# code for Resharper (now they have the Rider which is an IDE for . entire NET of them, but runs with JVM).

They also target Javascript, perhaps to have a web IDE soon. Maybe focus on Webassembly in the future. Indeed it has happened over time.

They are already creating native code that does not depend on the JVM.

Over time they gave up the idea of generating code for the CIL. I do not know if they will resume. They realized that it was difficult to reconcile a good language with these two targets, not only by Runtime, but for every library of every platform. And it would probably have few benefits. I do not know if they are not creating or even using experimentally some converter from Kotlin to C# or even Java to C# for easy development.

But it was still useful to have a better language than Java. Many people criticize the language of Oracle. They wanted a Feel closer to C#, and who knows something even better, and Kotlin That would be good. They wanted something that ran on the JVM, used all the JEE and communicated with all the code that they already had in Java, but that was more pleasant to develop, that gave more productivity and robustness. Who glimpsed having another product in their line also.

They started from Java, but much of the language was inspired by C# and Scala, giving a more functional tone, but still strong in the imperative that is something most programmers are used to. They were also inspired by other languages, they tried to make the code cleaner, as Python does.

Recently Google made the language for use on Android official, and there is much excitement in its use. With this many people think it will be more palatable to program on top of a JVM.

Can I program on any operating system? And run?

You can program where you have a JVM infrastructure, even better if you have an IDE for Kotlin, which is roughly where you have a JVM. Of course you won’t run an IDE on Android.

In theory it runs anywhere it has a JVM. These things are never 100% guaranteed, but that’s basically it, except for the specific incompatibilities, JVM determines where you can run. You can also run where you have Javascript implemented, as long as you generate code for this. I don’t know if this platform is well supported.

Now it’s a little better with the ability to generate native executable. It is not yet suitable to create an OS, but it is not as absurd as it was before.

What are the main characteristics?

  • It interoperates very well with Java. It is also well compatible with almost everything existing.
  • Adopts much of the functional programming but still in imperative style and maintaining the force of object orientation.
  • Has Pattern matching.
  • Facilities to do something similar to LINQ and is not only extension methods. It also features standard implementation on interfaces such as Java 8 and C# 8.
  • Simplified and intuitive syntax, avoids the use of ; for example, no verbiage.
  • Allows delegated properties that is better than events and gambiarras to make the property be observable.
  • Declares variable type optionally at the right place, did not copy C :P
  • Has atomic blocks for transactions in memory that need to occur all or nothing without external intervention.
  • It encourages the use of Dsls. Doing something in itself that looks like XAML or something is relatively simple.
  • Works natively with objects Singleton.
  • Allows class delegation.
  • Best annotation system.
  • Alias of type, as C# does with using.
  • Some things you have in Java are best implemented in Kotlin.
  • Uses interpolation of string.
  • In general language constructions function as expressions.
  • No exceptions checked. TYG.
  • Uses co-routines.
  • And much more, of course.

See more in another question about her.

How the guys work in it?

It’s a lot like Java, but there are some more specific things. Try to pull a little into C# and adopt some things from Scala and other functional languages.

  • Everything derives from Any, as in C#, unlike Java which sells the idea that everything is object but is not. In fact C# has types that are not derived from object, but it works apart.
  • The types are not null unless it is said to be, and this alone is worth the language. C# 8 has this also where it is missing. There are mechanisms to handle better when you want a cancellable type.
  • Privileges immutable objects by default, letting the programmer choose to be changeable.
  • It has facilities such as operator overload, properties, indexers, coercion, etc. equal to C#
  • The generics are real, even though the JVM isn’t helping, it’s similar to C#, but it also has some Java stuff.
  • Has algebraic data types (Adts) that I would love C# to have. That came from Scala.
  • There are data classes, similar to the records you will have in C#.
  • As Amble are typed directly into the language, unlike C# which still seems a bit fishy using types of support even in syntax.
  • Has function inline which is an optimization between normal function and lambda.
  • Although not fully connected to typing, it does not privilege exceptions, it uses a Maybe for example.
  • Although it is based on the JEE, it has many better types that replace what is used in Java. It is still possible to use Java types for compatibility. It is not ideal, but there is for today.
  • It is possible to create a dynamic type, as in C# (but it is limited to the JS target).
  • Has Unit which is better than void, and has Nothing which is better than null, and not just the name no, the semantics is more appropriate.
  • Has ranges.
  • Evita Boxing needlessly.
  • Foul structs, but maybe come along with Java 10.

Completion

Kotlin developers are very good. They’re not Anders Hejlsberg, but they’re not aloprados, they’re willful doing nonsense, it’s not a language that will show problems in droves with time.

I still prefer C# among existing languages, but if I have to work with JVM, Kotlin would be my choice.

  • 3

    Supplementary text: http://www.androidpro.com.br/kotlin/

  • I took a superficial look and liked it. I was surprised that to do something as simple as repeating a thing x times I need to declare an array of x positions (even if empty, because Kotlin only has a loop over enumerable), but otherwise it seems to be much better than Java itself.

  • @Renan I think that’s not it, must have given the wrong impression, she has crease that is not array.

  • @mustache I just saw. for (i in 1..10). Now, with the for traditional I did magic with dates (i.e.: for (DateTime data = DateTime.Today; data < outraData; data = data.AddDays(1)) {...}. You can do it with a range?

  • 4

    @Renan I think not, I miss for normal, I find a bullshit of these new languages, I hate language that wants to protect the programmer from doing what he knows to do well, the protection should be in those things that the programmer errs unintentionally, not in what he errs because he does not want to study.

  • @bigown who knows in the next version Kotlin does not end up supporting the for traditional.

  • 2

    @Renan I remember that this was discussed and deliberate. Swift did worse, had, and ceased to have :D

  • @Maniero in the conclusion the link SO Docs is out of the air. you could adjust that?

  • @Fernandosouza made!

  • Can you do the for java equal in Kotlin this way: for ((index, value) in array.withIndex()) { ... }

  • 1

    @Eduardodornel you just show that it does not give, only that it is possible to have an index, but with an extra cost, the for is just not having to deal with anything extra, especially with an extra abstraction.

Show 6 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.