
[ad_1]
Being productive with modern programming languages, by a software engineer who has been using Kotlin for more than 5 years

I’ve been writing code for JVMs for over 10 years, many of them using Java. That changed about five or six years ago when I picked up Kotlin. So far, I have managed to completely abandon the Java language in favor of Kotlin. I did it because I think very productive with language. This lets me focus more on the business logic instead of forcing me to write boilerplate code over and over again. In this post, I will share my top 8 reasons why Kotlin makes me a more productive developer.
I certainly know Kotlin much better than Java. For what it’s worth, I was certified as a Java expert by Oracle a few years back. Nevertheless, Kotlin became my core programming language, and I want to encourage you to consider it as well. When I talk about my Kotlin productivity, it is mainly based on personal sentiment and not backed by real data. I’m in a special position because I picked up the language quickly, just before 1.0’s release, and have also worked as a teacher for the language since then. Nevertheless, I believe that some of the arguments in favor of Kotlin apply to many of you, so let’s see what I am talking about.
I used Java extensively for a few years and wrote a lot of productive code with the language. Java was my first language, and I didn’t know other languages very well at the time. In the meantime I have been exposed to many different programming languages such as TypeScript, Go, C#, Swift, and more.
I didn’t really feel much joy when using Java, which changed a bit with the advent of Java 8 in 2014. I immediately fell in love with the functional aspects that were added to the language and the use of lambdas and streams in our code base. Of course, this was not always appropriate.
Still, it was bleeding Java Edge, and I loved it. At that point, I started looking at other JVM languages and started learning Scala at some point. I started by reading its documentation which was fun at first but then quickly got scary. I never really gave it a fair chance, but looking back, I don’t regret giving it away after only a few weeks.
I can’t remember exactly where I first heard about Kotlin. only thing i Doing Remember that JetBrains was mentioned with this. I’ve always been a fan of their products, so it was obvious that I had to check out the language they made.
In addition to Scala, Kotlin comes with quite a lot of digestible documentation, and it never felt intimidating to read. I remember binge-reading it every few days. Only two topics didn’t make sense right away, so I bookmarked them for later.
One of those topics was the backing field, and the other was probably related to delegation support.
Another thing that made it very easy to pick up Kotlin was its excellent support in IntelliJ. I learned the language with the IDE and documentation. Another resource I totally recommend is the book Kotlin in action Which also helped me a lot in understanding the inner workings of the language.
Kotlin has a great standard library. You won’t need external libraries for daily tasks, such as checking whether a String
is empty or copying streams around. Kotlin provides all that and more. It comes with an extremely sophisticated collections API, defines commonly needed extension functions on default types, and finally gives the developer the option to add their own member functions via extensions. You can find an excellent article on grouping of standard functions Here For example.
It should be clear. Especially when you are coming from a language like Java, you will be blessed with the crisp features provided by Kotlin. For example, think about null-protection, extension functions, easy generics, or its attractive concurrency tools provided by coroutines – all of which make us more productive and make the language more enjoyable.
As a result of the fantastic standard library and rich feature set, Kotlin is a very intuitive language. Often, you can try to perform some action on a given type and see what existing functions the IDE suggests. It often happens that you find the function you were defining already. examples of this would be String::before substring, file extension either moveable::to set,
When we talk about the standard library and also how intuitive the language itself is, we want to mention the functional aspects of the language as well. In this part, I want to focus specifically on the functions. As you already know, functions in Kotlin are first class citizens. You can declare variables holding them, pass them and even return functions from other functions. You find lambdas (undeclared and directly passed functions) in every Kotlin code base. They are also heavily used in the Kotlin standard library. An example of this is the very useful set of scope functions. Of course, the lambda is an important component of the collection API, that is, the content is defined kotlin.collections
, Too. I can’t even tell how often I use these functions in my daily work. I shudder at the thought of replacing the collection within the traditional for
How hard it was to do loops and similar functions in Java, especially before Java 8. Let’s see an example in action. We assume that we have some table/grid data as follows:
Example
a Grid
multiple. Is Row
s containing multiple . are there Column
s. The task would be to calculate the sum of each given column identified by name
,
Using functions from the Kotlin standard library, we can do the following:
1. Collect all columns from all rows in a collection flatMap
2. Group these columns by their names groupingBy
3. Sum the grouped columns by sum of their values
The above is just a straightforward example that illustrates well what you can do with the given collection functions. As I said before, I use these functions every day, I use them extensively, and I don’t want to miss them anymore.
One of the most important benefits of the functional programming style is the fact that you have to write less code overall. You use so called inner iterators instead of explicitly specifying how to iterate a given collection. Loops seem easy in the beginning, and almost everyone can implement them correctly. Still, loops can easily lead to hidden bugs, which are a common problem of boilerplate code. The idea of functional APIs is that you can focus on what in return How and thus don’t iterate the collections explicitly but use functions like map
, filter
etc that handle the iteration for you.
Boilerplate code can be a source of errors; Naturally, the more code you need to write, the more potential bugs will be introduced. Kotlin has removed the need for a lot of tedious boilerplate code, the language introduces fewer logic errors than you normally would. A classic example of this is the Singleton pattern. Implementing it correctly is not as easy as you might think. You have to handle simultaneous access to the singleton, which makes it difficult to implement initialization code for such an object. There are different approaches to this issue, all of which can cause potential problems if written manually. Kotlin, via object
Declaration, abstracts it to the developer, and doesn’t require you to write recursive code every time.
Whereas in Java you have to spend more time reading and understanding boilerplate code, in Kotlin this is not a problem for the reasons already stated: a sophisticated set of features and a concise language in general. Moving existing Java code base to Kotlin reduces code size ~40% If done correctly. Of course, this makes Kotlin code much easier to read, debug and maintain. To be fair, a rich feature set can be easily abused and can lead to hard-to-read code if implemented with very little care. Write the code not for yourself but for the people who have to maintain it in the future.
All the reasons mentioned above make Kotlin an entertaining language. A practical, concise and intuitive language is the best tool a programmer can think of, and you shouldn’t use anything else. Having fun also automatically leads to more productivity.
I’d like to note that I find it extremely helpful to know your toolset accurately. Of course, the following can be applied to almost every topic and is just my personal opinion. For other people, it may work differently.
I spent a lot of time learning Kotlin. I looked at how it works and what features it provides and recommended everyone else to do this even before writing serious Kotlin code. As a Java developer, you can write quickly compiling Kotlin code, but it is still different from writing idiomatic Kotlin code. It won’t be enough to google for StackOverflow posts all the time. There are some basic techniques you should cover before you get started. I recommend studying the entire Kotlin documentation, which you can do in just a few days. on top of that, the book Kotlin in action Is the best resource you can find, and I highly recommend it.
[ad_2]
Source link
#Top #Reasons #Kotlin #Productive #Software #Engineer #Simon #Wirtz #September