Hi everyone, Can anyone tell me why should we use ...
# announcements
v
Hi everyone, Can anyone tell me why should we use kotlin instead of Java in business application?
h
its much less code and more easy to manage
plus they can also do a gradual change as it’s 100% interoperable, so there isn’t too much to lose
e
I am actually puzzled with the opposite question. Why would anyone use Java nowadays for their business application, when they can use Kotlin? What’s the Kotlin downside that keeps people on Java?
👍 2
h
people just don’t like to change i guess
d
because java sucks 🧌
m
@elizarov Fear of change. Fear of not being able to hire people with experience in it all ready. No (in their mind) compelling reason to do it. Cost of change. All the usual reasons for resisting change, and most of them false. For example, hiring. I see Kotlin as a positive. There are many 'Java' programmers out there that aren't any good. If they already know Kotlin, they've shown they like to learn/explore. If they don't know Kotlin, seeing how quickly they pick it up, or how resistant they are to it gives you good insight into their ability to learn and adapt.
@Hamza It can be less code, but personally, I've stopped focusing on that aspect. I will say if you use Lombok, apache.commons.lang3 or Guava in your project, you've already admitted Java has shortcomings. Lombok requires preprocessors and learning a new 'language' via its annotations. If you're going to do that, why not switch to Kotlin and get all of that as part of the language? From a strictly language perspective, Groovy was/is an easier sell as valid Java is valid Groovy (some minor exceptions exist). Less code is good, BUT not from a writing perspective. If you're any good with your IDE, there's negligible difference writing Java vs Kotlin code. I find the big difference comes when reading the code. The code is more descriptive of what it does, with less boilerplate code. Almost everything is Kotlin code, i.e. part of the language or standard library so once you know it, you know it. With Java, there are many libraries (although Lombok, apache commons seem to be dominant) to handle standard scenarios. Null as a first-level concept is valuable. Still risk if you have any Java code, but the frameworks, and the language keep getting better in this regard. Much better for functional approach to coding, so can leverage that when it makes sense. Many more reasons in my mind, but it isn't free. Takes time for a team to learn it, and get comfortable. You MUST have at least one person that is VERY strong in it, AND whose primary role is mentoring the team. I'm fortunate enough to be at a company that has allowed me to introduce Kotlin, and my primary role is developer mentor. IntelliJ, Git, Kotlin, Spring Boot, CI/CD, etc.
h
The reason short code is a good argument as to why to switch to kotlin is because automatically your code becomes much more maintainable
And that's already a great reason to switch
m
Right. You didn't say it was easier to write because it's less code. I think we agree here.
h
I didn't think about it that way
That's nice idea
m
I'm kinda late to the question, 'Why would anyone use Java nowadays for their business application, when they can use Kotlin?' but here are my two cents:
1.-Java version. If you are working with recent versions of java, you have several of the most common 'highlights' of kotlin, so is not as attractive as it could be.
2.-Environment. Kotlin is interoperable with java, but some kotlin features aren't, and other don't play well with java, and that can discourage kotlin usage.
h
But then you gotta realise majority still use java 8, and u get much less usage of newer versions if you go java 11
👍 1
m
3.-Skill level. Imagine java as a stick, and kotlin as a gun. Guns are a far more powerful weapon, but a monk with several years of training with a stick can lay waste to way more people with it, than with a gun, because of the skill level. If you are time constrained, and you already know your way around java, you are much more likely to come up with a good solution using java than kotlin, specially for low level code.
That is true @Hamza, that's why I talked about recent java versions. Old ones benefit much more from kotlin code
An example for the third case: I usually work a lot with generics. At this point, my skill level with kotlin does not allow me to fully exploit the language at that level, and I end up writing MORE code in kotlin, that I would in java (specially when trying to keep interoperability). Obviously, I expect to reduce the gap with practise, but if I had to create a generic API for, let's say, generic DAOs right now, for production, I would probably try with java first, because I know I can get it done fast and good. For personal stuff, I would use kotlin, because in that case I don't have to worry about screwing up and delaying the delivery
If I'm writing mostly business code, I would go with kotlin, because the top layer of all the languages is kinda equivalent (control flow, data types, math operations, etc), so I know I would have all the benefits of kotlin with low risk
Is logical to think this reasons will become moot with time. Kotlin will gain more features, interoperability will grow even more, the library ecosystem will fully support kotlin, and the skill level of the devs will increase. But as today, you should not assume people is just avoiding kotlin. After all, everybody has to ship stuff.
The best selling point for kotlin is interoperability. Unless you are working at low level, you are VERY unlikely to have trouble. And if you have, just write that in java. Problem solved.
The second best selling point, is the siren song for managers, multiplatform. Check kotlin/native and explain to your manager you can share the business code between web (js), android (kotlin) and iOs. Google now does that by using GWT and parsing java to object c. Kotin native requires no parsing, so when it becomes stable, is gonna be a HUGE thing for sharing no platform-bound code. Be sure to mention you cannot share things like UI so you don't shoot yourself in your foot
and, if they don't bite... just keep practising with personal stuff
👍 1