Java conversion to Kotlin

3

One of the qualities mentioned in the Kotlin language is the creation of clean code, that is, code that is pleasant to read and can accomplish its purpose without curling.

From what I've seen, Android Studio contains a translation for Kotlin, including translating the entire project. Would you like to know how this question is with the plugin translation? Is it advisable to translate the project or would it rewrite it?

    
asked by anonymous 01.08.2017 / 20:59

2 answers

6

Who creates clean code is the programmer. In most languages most programmers make code atrocities because most refuse to learn to actually program.

Kotlin helps to have a more concise code compared to Java, nothing more. In fact the code can be even considered verbose compared to some other languages. And that's not necessarily bad.

I did not see anything that made a good comparison between the codes before and after the conversion, but my experience with this type of converter is that if the semantics are not exactly the same between languages the conversion never gets very good. p>

Convert C # to VB.NET and vice versa is good "80 or 90%", that is, after that you have to make a handy move. But these languages were created almost by the same people, and it was to be practically a different syntax with the same language. It is not 100% because VB.NET descends from VB which had some bad things and there is full compatibility with C #.

Kotlin has important semantic differences in relation to Java, as well as several similarities. My estimate is that you get a good "60, 70%".

Note that you can convert 100% (not all), only the quality is that it will not be 100%. I think it will have gains, but not so much when doing it at hand. It could be an initial step to go through the whole code. Several things can not be well converted as a human would. It may help to learn, but it may help unlearn why there will not be a good code.

In VB.NET and C # the library is the same. Kotlin brings a good portion of the library itself that works best and little or none of it will be converted. So depending on the case may have a quality even lower than it could be.

I think if you're going to program in Kotlin you have to board everything, you should avoid doing any part of Java's way, which is what will happen with the conversion. But that's everyone's opinion.

They are creating a Swift to Kotlin converter , which should give worse results.

    
01.08.2017 / 22:09
5

The recommendation of the Kotlin language, by many, is that you start rewriting your project instead of translating it. To be more direct, there are some advantages between rewriting and translating a code into another language.

It's true that IDEs Android Studio and Inteliij IDEA with the Kotlin language plugin offer tools as well as the language site itself you can do this: try.kotlinlang.org . What we should be aware of regarding this is:

  • Converting code from Java to Kotlin works in almost every case, or I would say it all.
  • Code conversion allows you some time savings and you do not have to worry about rewriting the entire from-scratch code.
  • Converting code sometimes is a simple conversion, meaning it will not really show the power of the language.

What I want to say, in a nutshell, is that code conversion saves you time, but also makes you miss the chance to know a little more about the Kotlin language >. It is a different language, it is not so much like Java and so you should be aware of some details.

Many people recommend that you rewrite your code for the following reason:

  • You will begin to become familiar with the language
  • This is the best way to learn language
  • You will be able to write clean and optimized code with the advantages that the language gives you
  • You will relearn how to program with Kotlin

Yes, from my personal experience, I relearned to like programming / programming and I have a certain love of language. It's a new language, but with tremendous support from the community and developers.

Another important thing, before you want to convert your project to Kotlin, consider whether this will be worth it. What I mean is, conversion will take time, because converting a project to another language like Kotlin is very important. Your project will probably stay cleaner, but that will depend on you. Just using the conversion tools will not make your project " kotlinized ". Look at the language documentation, look at projects that use language, and see how they use them. They are a multi-paradigm language and you can enjoy a lot of it.

You can also modularize your project, that is, by creating small parts of them in kotlin (new functions) or by rewriting a small part of them in kotlin, thus allowing maintenance of the old code.

    
01.08.2017 / 22:13