|
Page 1 of 1 |
Frant
King's Bounty
Posts: 24590
Location: Your Mom
|
Posted: Sat, 25th Sep 2021 05:02 Post subject: Kotlin - Newer multi-platform programming language |
|
 |
So I've been thinking about learning app development on Android and I was looking up different options, languages etc. and found out about Kotlin, a new programming language that has quite a few advantages over Java including Null Exception safety, much more efficient code and smaller file/memory size etc. while at the same time being interoperable with Java and it runs on JVM.
It's a bit more "dense" to learn since the syntaxes for doing the same things as in Java are very condensed and precise.
Example 1, in Java:
Code: |
class Book {
private String title;
private Author author;
public String getTitle() {
return title;
}
public void setTitle(String title)
{
this.title = title;
}
public Author getAuthor() {
return author;
}
public void setAuthor(Author author)
{
this.author = author;
}
}
|
Example 2, same class function in Kotlin:
Code: |
data class Book(var title: String,
var author: Author)
|
The different is ridiculously obvious. Java has such a convoluted and bloated programming syntax/style while Kotlin does away with a lot of redundancy. The negative side of that is that Java is easier to read than Kotlin since Kotlin is so condensed and tight.
Here's an article comparing Java and Kotlin called "Kotlin vs Java: Which is Better for Android App Development?"
https://www.xenonstack.com/blog/kotlin-andriod
I never learned Java but since I learned C# way back I know it's very similar; Javas language as far as syntax and is pretty much based on C++ while improving on some things, omitting others and being an interpreted language as opposed to a machine code compiled language. Kotlin is in the same class of languages as Java but as you've already seen has a very optimized syntax and resulting bytecode size.
We'll see. Any thoughts? Anyone with experience of Kotlin?
Link to the Kotlin homepage: https://kotlinlang.org/docs/home.html
Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn!
"The sky was the color of a TV tuned to a dead station" - Neuromancer
|
|
Back to top |
|
 |
LeoNatan
☢ NFOHump Despot ☢
Posts: 73194
Location: Ramat Gan, Israel 🇮🇱
|
Posted: Sat, 25th Sep 2021 14:28 Post subject: |
|
 |
For Android, you should obviously use Kotlin.
But "much more efficient code and smaller file/memory size" doesn't make sense; on Android, it compiles to JVM bytecode, and is limited by the featureset that this JVM provides. The end result is bytecode that is similar between Kotlin and Java.
The only advantage Kotlin has is at development time. At runtime, it's minimal at best.
Not a particular fan of new languages such as Kotlin, Swift, etc. They suck the joy out of coding to me. Not that Java itself had any joy in coding, so it's a no brainer. But C# (which is very much not like Java at all at this point), ObjC, etc.—I'd prefer the latter, rather than Kotlin/Swift. I am a dinosaur, I guess.
|
|
Back to top |
|
 |
|
Posted: Sat, 25th Sep 2021 14:34 Post subject: |
|
 |
Last edited by paxsali on Thu, 4th Jul 2024 23:04; edited 2 times in total
|
|
Back to top |
|
 |
Frant
King's Bounty
Posts: 24590
Location: Your Mom
|
Posted: Sun, 26th Sep 2021 05:03 Post subject: |
|
 |
LeoNatan wrote: | For Android, you should obviously use Kotlin.
But "much more efficient code and smaller file/memory size" doesn't make sense; on Android, it compiles to JVM bytecode, and is limited by the featureset that this JVM provides. The end result is bytecode that is similar between Kotlin and Java.
The only advantage Kotlin has is at development time. At runtime, it's minimal at best.
Not a particular fan of new languages such as Kotlin, Swift, etc. They suck the joy out of coding to me. Not that Java itself had any joy in coding, so it's a no brainer. But C# (which is very much not like Java at all at this point), ObjC, etc.—I'd prefer the latter, rather than Kotlin/Swift. I am a dinosaur, I guess. |
I loved learning and using C# (best/most enjoyable high level language I've ever learned). All the tedious tasks of dealing with garbage collection and the nitty gritty nonsense which took time away from writing useful constructive code was taken care of and I could focus on whatever I was trying to accomplish. When I looked at Java (also with garbage collection etc.) I didn't feel "yay, time to learn me some java".. So I didn't. I know C# can be used to develop for Android but I have no idea what it actually entails when it comes to platform support, SDK etc.. I guess I should read up on it. While writing this reply I did spend 5-10 minutes looking at some basic info and found Xamarin.Android (Mono for Android) which means I can use VS to develop Android apps.
Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn!
"The sky was the color of a TV tuned to a dead station" - Neuromancer
|
|
Back to top |
|
 |
|
Posted: Sun, 26th Sep 2021 08:37 Post subject: |
|
 |
I'm into Android programming since 2011 (no Kotlin back then, obviously), our company wrote both regular apps for third-party clients, and some specific apps (essentially homescreen replacements) for devices developed in-house.
In Android API, most of the coding work is implementing interfaces and abstract classes (click/touch listeners, AsyncTasks etc) so it forced me to learn Java in depth, which in turn increased my skill level in "regular" Java programming (desktop and web backend). Thus I recommend Java solely because it's handy to know in different fields (if it matters to you), and Kotlin is still essentially Android-only.
The Android code was messy until Java introduced lambda expressions (reduces boilerplate code when implementing interfaces as anonymous classes) and stream processing (easier manipulation of e.g. lists and arrays). Since then, it's much cleaner.
Regarding your example with setters and getters, it's not the best because:
1) You'll generally isolate plain classes (a.k.a. POJOs, plain old Java objects) in separate packages (that's sort of like namespaces in C#) and you really won't care about the code inside (you declare class fields and let Android Studio generate all support methods). Classes you write to handle Android logic won't have that much boilerplate inside.
2) You'll be fighting Android API for most of the time so you'll need real understanding of Android app internal works (search for "Understand the Activity Lifecycle" and "Guide to background processing") and a LOT of examples in the beginning. There are plenty of them on stack overflow, and most of them are in Java and you'll need to know how to properly interpret them even if you want to code in Kotlin.
|
|
Back to top |
|
 |
LeoNatan
☢ NFOHump Despot ☢
Posts: 73194
Location: Ramat Gan, Israel 🇮🇱
|
Posted: Sun, 26th Sep 2021 16:19 Post subject: |
|
 |
Frant wrote: | LeoNatan wrote: | For Android, you should obviously use Kotlin.
But "much more efficient code and smaller file/memory size" doesn't make sense; on Android, it compiles to JVM bytecode, and is limited by the featureset that this JVM provides. The end result is bytecode that is similar between Kotlin and Java.
The only advantage Kotlin has is at development time. At runtime, it's minimal at best.
Not a particular fan of new languages such as Kotlin, Swift, etc. They suck the joy out of coding to me. Not that Java itself had any joy in coding, so it's a no brainer. But C# (which is very much not like Java at all at this point), ObjC, etc.—I'd prefer the latter, rather than Kotlin/Swift. I am a dinosaur, I guess. |
I loved learning and using C# (best/most enjoyable high level language I've ever learned). All the tedious tasks of dealing with garbage collection and the nitty gritty nonsense which took time away from writing useful constructive code was taken care of and I could focus on whatever I was trying to accomplish. When I looked at Java (also with garbage collection etc.) I didn't feel "yay, time to learn me some java".. So I didn't. I know C# can be used to develop for Android but I have no idea what it actually entails when it comes to platform support, SDK etc.. I guess I should read up on it. While writing this reply I did spend 5-10 minutes looking at some basic info and found Xamarin.Android (Mono for Android) which means I can use VS to develop Android apps. |
C# is Java done right, and more importantly, allowed to advance as a language without committee after committee. The C# of today is a lot more rich than it was 10 years ago, but without feeling alien, like modern C++ fees like to an old dog. I still love C#, I think it’s one of the best languages.
If you’d like to try C# development for Android, check out Xamarin: https://dotnet.microsoft.com/apps/xamarin
It’s now maintained by Microsoft and is very good and well maintained. You still access all the native Android views and layouts; they are just imported to .NET for use in .NET languages and CLR.
It’s free for individual developers, and you use Visual Studio, the best IDE out there.
|
|
Back to top |
|
 |
Page 1 of 1 |
All times are GMT + 1 Hour |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group
|
|
 |
|