How to Kotlin - from the lead Kotlin language designer (Google I/O '18)
Вставка
- Опубліковано 16 сер 2024
- Kotlin is similar to the Java programming language, so it's natural that your Kotlin code looks very much like Java code when you are first start to use the language. While this is fine to begin with, you're probably not taking full advantage of all the language benefits. In this session, the lead Kotlin language designer will show you how you can write more idiomatic Kotlin, what the benefits are, and help you discover some of the most powerful yet lesser known features of Kotlin.
Rate this session by signing-in on the I/O website here → goo.gl/rcxeHQ
Watch more Android sessions from I/O '18 here → goo.gl/R9L42F
See all the sessions from Google I/O '18 here → goo.gl/q1Tr8x
Subscribe to the Android Developers channel → goo.gl/GEh1ds
#io18 event: Google I/O 2018; re_ty: Publish; product: Android - Languages; fullname: James Lau, Andrey Breslav; event: Google I/O 2018; - Наука та технологія
A class can be created with a single line of code, without getter/setter garbage. I love it!
@@trollberserker1515 Yes but that class would be pretty much useless. Adding functionality would require several lines. This one-line class is completely functional in Kotlin:
data class Person(val firstName: String, val lastName: String, val age: Int)
@@593jorge check out the records blogs.oracle.com/javamagazine/records-come-to-java
@@trollberserker1515 I Y Luis ilustración kk millón Illinois de pesos dólares lipkkikiiii6i6ii66nimmkmnmkmii6miyil6yiiki6i98klki6k67ikkkukkikkkkkkkki666i6i6ikyminkinnmu7mmmmiim66miikmyi7u6k8kikkikkikk8kkikkk6kikkkki7k666iikiyiu8kikmlkkkyjknkiikkl7mik6ikkkkkkkkkkkk7kkkukkkkikikkkkkkmmmmmml766m6ik668k666k66k6666766(pesos huy k6kikilu66ikni6hj6i66ikik66ikiikh6k6kpkk7iikk6kkukkilkipk6866kii9ii6yiiim7miil7mimjumi6umk66iyiikuy6iy6uilu6ui666u66iyki6ikik677kikkkikik6k6666kk6kkkk6kk86ikki6iuiiiu6kmlnknmnn66k6iki66ki6klukkkkkklkkkkkkuk7ll9kkikkkkkkkmkkmuk9mmik66iki66k7iukpkk96kkkkp6l6kkkki6kkki6kkk8mu8mkk8klimmm666y6i7k6k6kkki6ki6yi68kkk8ikilkkkkkkkkkk6kkkkkkklijpi66k7iyiik6k6bkn888km8m868k8u6m8nmi6kmii6i67iiiliillkkk6kllkiiiipipii6iikiyikiibikimk6mm6iuik6imibim8myiynip9bniiikkkkiiiikiiiiiiiiii887k7ik7iikoii6jijiyjkiiijkiikik88kkkkikj6ijiyiikikkk8k7k8kk78kkk86k7k8k8kkk7k67ipjplp9kkl876k7y6k7mlkl76kl7l6ikkii767ijkikll6kklk6kklkk66kkk6lkkklkkkkkkk6i7li6ik68ii67yklk6klk6l6iii6iiili76kyk7llll7i8pl7ibi6i6iijukk7ll67lkpkkkyk6lll7kklk7kpk66k8lk66lkk6kkklkk7l6k8678k7k9i7ijl7i7iki7iku8mi7n8777866788likkikikyik7i6ik7kl6i6k7kkp76kk6kk676kkykk6kkk6klkkkk6kkkl7ii6iiklikk6i86k8i6m8k6kk8kl86lyi7i7ii6i7li7k7k6k8kkkl66k7k68k8k6kk88kll8kk8k8l79k6k86k7kk8kkk866p68jkiij9ikiiiiil8hj8p78lyl6lk68k8knk8jkiij97yi8lk8pjkllkj9l8k78kjk8klj8j8l7jipp8j8piipij8pi7ki77k7i78k96lkipi68666yk7i7ip98k776iki778klkkk6k8kky8lk8kk8i6kk88i86k66kkkkkkk6kk8kkkkk8lkk68k7k8k8i6kkk6j9ik68k86k6787k8ikk77k8iiii6k8i7i8kk7kkkkkkk8kkk88kkkkkkkk6kkkkkk8kkkkkkkk8kkk8iii86ki6ik8kkk7iikyyi8ikkkk8kiik87kkiki7iiiiiiii6k866k8k7kkki67ki86kkk88lk78ik8i78kk88k778iliikyii6iiiikikkiik7iiikk8k7k8iy776886k78i7l77ki8pkkk78k8kk8il8kkkkkkk8kbp
@@593jorge all I hear excuses
Kotlin seems to take the best syntax suger from C# & JavaScript to Java world, which Java failed to provide for years. I am impressed.
You're so right. Java is so late.
@@chuganator ...Java the language is late, Java the JVM is still the wonder drug that it always has been. Java is dead, long live Java.
modern C# isn't far behind at all, especially when you mix in some F#
@Ahmed El Ashry , java is not dead. I said "Java is dead, long live Java", the only thing replacing Java is more Java
@Ahmed El Ashry , I've tried to escape youtube many times, but continue to fail.
More than the language, I like this person. He is so humble and down to earth. Great mind.. humble human being!
yeah, I agree. He is not cocky. :D
honestly, in my experience, everyone from jetbrains seem really humble, practical, down to earth people. the corporate fakeness is completely nonexistent here. they sell their products by showing their merits, not by excessive claims or false marketing or appealing to emotions. i guess this has a lot to do with who their customers are: jetbrains sell development tools for technical people, there's a lot less room for bs here and I guess this has attracted non-bs people to their company as well
Poor Andrey, he seems so nervous! Mind you I would be too lol.
Great language he created. Many thanks from me, it has made my Android development fun where I have used it.
Keep the good stuff coming with Kotlin!
It's a presentation in front of thousands and not just a small team. And maybe he didnt have rehearsal like Google's speakers.
Yes, and maybe he's just being authentic without putting on a facade (because he doesn't need to since he is the inventor).
*modafinil intensifies*
He is doing great!!
he is not :)
Ive been studying Kotlin for 8 weeks: Its good to see Andrey give an overview of it.
Thanks for helping to stick in my head.
Finally someone fixed Java and made it more C again with other great additions from languages like Python and C# and all that. There a are a *few* quirks I'm not particularly happy about, a lot of them come with the JVM baggage (like not being able to manage my own memory) and I don't understand why we had to switch to name:Type schema instead of "Type name" which I thought was always more natural to read like real text, but I can live with those
Yeah I hate the name type order. Reminds be of visual basic
it's from pascal
loops and arrays declaration and not expressive though
Well most of the time you can skip those and maintain code clarity simultaneously. For eg:
val obj: MyClass = MyClass()
can be turned to
val obj = MyClass()
without losing any context of the code.
@@VivekYadav-ds8oz you can do that in java too, var obj = new MyClass(); nothing new :(
That trick when he showed Kotlin byte code then decompiled to Java was pretty cool. A few months back I was a little confused about what the 'noinline' keyword was doing... this trick would have probably made it clear.
Timestamp?
@@freshfast6197 On 28:25. Yes I know I'm 2 years late.
I started 9 years ago programming java... this is like a DREAM! !!!!
This presentation just keeps on blowing my mind through the whole thing
The Audience looked so happy. I am Learning a lot thanks for the vid.
"Noise is harmful for your brain" - my biggest takeaway
Yeah I was going to say it has Andre's personal philosophies directing the language
At 22:14, "this is something pretty unfamiliar for the C-language family" ... that is true pre-C++11. But with C++11, there are lambdas and immediately invoked lamba expressions (IILE), so you could write very similar code as follows:
auto s = []() {
if (condition) {
cout
46ģmm9bem bem j9.j
Wow that looks ugly. Is it still like that?
To anyone thinking they are used to Java and don't need to learn Kotlin or struggling, I say go for it learn it trust me all worth it don't think just do it
Even for competitive programming?
I just learned Kotlin during quarantine. It's much easier to learn.
What did u do with it
seems like this kind of new awesome things but, we already doing this with c# for a couple of years
I would love to start using Kotlin where I work.
then use it
Why? Weren't you using Java annotations, boilerplate generators, and so on? Butterknife?
You should definitely start (perhaps start with unit tests in Kotlin). You will be thankful several years from now for learning Kotlin, trust me.
Igor Ganapolsky it's perfectly foreseeable Kotlin will die a slow death if Android apps are going the way of the dodo bird. 🐦
Kotlin is a general purpose language, not just Android. At work, we use it for backend web development
Me everyday learning Java: There has to be a better way
Kotlin: There is!
*slams fist on table*
There has to be a better way. Sounds like Raymond Hettinger
I learned a little bit of javascript and html then thought "you know what I should do with all of my 6 hours of javascript? Try to make an app in a different language for fun!" So now I'm trying to find a tutorial
There is! Clojure!
Andrey, thanks for creating Kotlin.
Hello from Saint-Peterburg!) In this city Kotlin has been started!
A very advanced project has the one Util class to rule them all.
i think i would say good bye to java after 10 years. i am very impressed.
I'm impressed. Kotlin is Java, but not awful.
Great language, reduced NullPointerException which was one of the headache in java
Java had annotations for that, and you can and will still get a lot of null crashes now. Even more, actually, since every method where you specify an non optional parameter will crash instantly (Kotlin check) if the said parameter is null. So you need to design clearly each function param....is it optional or not, etc.
The difference is that these crashes occur at compile time and not at runtime, making you think about null safety more that when you just use annotations in java. Its about making you think in a different way about null safety.
Not if you use explicit pointers, or whatever they're called in Swift/Kotlin. If you unsafe-unwrap them, they will still crash at runtime
then why use kotlin at all if you are gonna unsafely unwrap the optionals
Another programming language and from this presentation it does look better than existing JAVA. It takes a lot of time, effort and working experience to master a programming language, why can't these programming language inventors work together to perfect the existing programming languages instead of keep creating new .
Downside of having too much freedom
Beautiful! It seems easy to switch from Ruby to it.
Kotlin is really power skills for everyone developer!
33:16 I think the code should be like:
s1.request(s2.name) { r1 ->
println(r1.message)
s2.request(r1.from.name) { r2 ->
println(r2.message)
}
}
right, Andrey makes you think
Base knoledge: js and ts.
Typescript (ts) = ts for Javascript (js)
Kotlin = ts for Java
C++ = ts for C.
scss/sass = ts for css.
Rust = ts for C++.
xml = ts for html
delphi = ts for pascal.
continue below...
Great job, master piece. Is the code in the demo available for download anywhere?
Can you just please keep the code on the screen all the time, next time? Maybe just have a speaker view contained in the nested screen...This way I had to stop video too many times.
kotlin lang and lib revived the java ecosystem , multiplatform jetpack compose will make it full stack in the full sense of the word
great...I hope there are another videos explaining kotlin like this
Kotlin: You still need to add an extra line to return more than one variable.
Python: Learn from me....
You can return pair and it would work just like in python if i remember correctly
10:28 seems like not as great of an idea.. kinda reminds me of "don't use global in JavaScript", even tho I haven't touched js for like a decade.
Like, for me it seems natural to encapsulate functions into groups based on what they are doing. Can't imagine trying to remember what exactly is the name of one of thousands functions in your project.
While if they were in a class e.g. StringUtils, you can just write the class name, put a dot and scroll through the functions inside it, "oh that's the one I was looking for".
Here is response from jetbrains team on that question: discuss.kotlinlang.org/t/best-practices-for-top-level-declarations/2198
Kotlin is just a blessing ✌😁
Im Learning Kotlin to develop android apps to replace legacy code written to run in Telnet within our multivalued DB.
The android apps will be used on RF Guns to control Stocks in a warehouse.
The coroutine stuff went over my head lol. What exactly do all those keywords (high level functions, I guess) do? How do I make sure I'm not leaking a reference to my activity? Can I cancel the blocking thing?
It's really frustrating that this keeps cutting around. I would really like to just see the demo the whole time
I came here looking for a 101 to make my game and my head is spinning from those tutorials what in the f.
Kotlin is the best language ever created.
Whenever he said, do you have questions? I always had one, and I remember he is in my phone not live :P
do I have to learn or have some idea about java beforehand.
Kotlin's semantics are not tied to the jvm, but some oop experience is helpful
Some comments:
13:13 The property won't allow you to use a different separator though, right?
23:32 The number "3" isn't even...
24:07 This "println" print "null" in case you give it null value. Any way to avoid this in a short way, and print only if it's not null?
26:34 Any way to convert to normal code instead of lambda? Sometimes it's clearer and seem more flexible...
Continue using Java everyone else will move on and benefit from Kotlin. You are the same person from last year who thinks constant null checks are a benefit.
I'll just make an interface between transcendental super consciousness in real life and people will see what it thinks like a movie and it could even do miracles.
this man is walking documentation
Kotlin saves my time, I love it.
Kotlin many features which were missing in Java and are already in C#.
Feedback: When the camera shows Andre, sometimes it happens while he edits the code. This should not happen, as it can be confusing.
I am new to code. I don't get this actually. What should I know before Kotlin!?
@Hamad AlMarri Exact opposite, you will not want to go back to Java
21:02How did he duplicate the cursor?
Hold alt & drag
www.jetbrains.com/help/rider/Multicursor.html
Ctrl + up/down arrow key (win/linux)
Alt + up/down arrow key (osx)
There's multiple ways: www.vojtechruzicka.com/intellij-idea-tips-tricks-multiple-cursors/
alt + vertical selection
I sorta know kotlin still learning tho si cant articulate likes and dislike too well yet. But idk if I want short dev time as a python and c c++ guy I'll just go with python I feel you need an ide with java and kotlin because there is so much overhead, extension functions are really nice tho
Great session, thanks a lot!!
Wow, this is so similar to Scala.
Great Content keep it up bro!
Love the language.
Many reasons to switch to Kotlin :) !
very useful sir
Smells a bit like mix of Java, C#, PHP and some functional languages. I see many good things, but I see few chaotic parts of language, at least from my C-like language background.
He's just using Kotlin idioms and decreasing line of code
I hear birds in the background
The return type of a function is located at the end of a line, which is one of the first things I would like to see when I read an API.
I just don't understand why there are so many software engineers writing kotlin code on Mac computers, am I the only one who notices this ?
If you write mobile applications, there's a good chance you need to code for iOS too, which means a mac.
I wish he would commented out the code, rather than delete it. It would be much easier to compare the different
How is this an improvement over Scala?
abstractable properties + the null "?" thing don't exist in scala
Extension functions are easier to understand than type wrappers. I also like that Kotlin does NOT have implicits IMO. Kotlin has even better interop w/ Java because it uses more of the same underlying classes.
I don't understand this fight of 'which language lets you write shorter code'. I still find Java more readable.
Agreed. Did we really need 'fun'?
agree
Readability doesn't mean writing lots of "public static void" or for-loop, it means that you write exactly what you mean. For example, you want to create a new list with each element is two times the element in another list. In Java, you need to do something like `List a = new List(b.size()); for (int i = 0; i < b.size(); ++i) b[i] = a[i] * 2;`. But in Kotlin you only need `val a = b.map { it * 2}.toList;`. And Kotlin version is more readable because it exactly describes what I want to do: creates a new list with each element times 2, but in Java, you need to understand the whole `new` and `for-loop` thing. For more complex logic, it's more difficult to understand what you really mean, i.e. less readability.
You may say Java 8 supports lambda function and streams. Yes, Java 8 makes things better, but not good enough.
I think the real motivation of pushing kotlin so much, is because of the legal issues Android is facing against Oracle because of Java usage.
@@protaties Exactly, Java gets bloated and clunky with all the boilerplate, I'm getting into kotlin primarily because they are addressing some of the frequent annoyances that come with writing code. I mean just look at the lazy initialization example he gave, its a prime example why kotlin is great.
Rip getters and setters and huge line of java code 🙂😂
have you heard of annotations ?
Kotlin великолепен, конечно.
how can i get these codes
meow
Kotlin looks like Swift sometimes for me.
They are very similar and for a good reason
It is actually almost 100% Scala, which also influenced Swift
Sobanya nope
I have no EXP in scala, but according to your comment you do. So lemme ask a question. I belive Java is a bit outdated langauge, my original tought was that C# will eventually take over Java's throne, but now seeing Kotlin I kinda changed my mind. However when you said that is almost 100% Scala I ahve my doubts, since up until recently I have not even heard of Scala. So someone liek you who have seen all of these languages do you think Kotlin has a shot taking over java ? I belive Java will decline in the near future eventually.
Swift is garbage.
I'm having fun programming in Kotlin, and that couldn't be said about Java.
It's time to make a film: forward to the past :)
How do I pass obj by ref to fun in Kotlin?
They are all passed by ref by design, you'd have to make a copy if you wanted to pass "by value".
I don't like Kotlin, it always suspends fun
Did we really need 'fun'?
😡 no fun 😡
No
Yes, because it would conflict with the syntax of a funcion with a single lambda argument
'fun' and ?: make Kotlin awesome
very goob, this is an on big langague, I`m liked this
What IDE is he using?
IDEA from JetBrains
pythonic! great
Almost good as C#
You've let him talk about basic stuff that one can read by himself in the documentation? I had hoped it would have more depth and would _reveal_ some interesting internal Kotlin things or how they made particular design decisions etc. Disappointing.
Hey, can you send me a Kotlin t-shirt :D
I was expecting Hadi hariri
Me too
If I already know Java, why would I learn yet another programming language to do the same stuff in a different way?
What is this ide???
Of course it's IntelliJ IDEA by JetBrains: www.jetbrains.com/idea/
Umm... Can I have my C#/Java language back now?
Thats copied from namedtuple in python
Kotlin rocks
Closely to Swift style
Wait take a break n tell...
Over-analyzing with developer paranoia :
Google Big Boss - "How do we get developers to start writing apps for Fuscia with Flutter and Dart?
Google Smaller Big Boss - "Introduce a new programming language to Android that's "better", but also "annoying"!
Google Big Boss - "Do it."
Ok
very nice!
Sorry, i didn't liked Kotlin. i will keep with Java, there's no real reason to change.
TRANSLATE TO SPANISH PLS!
Me @ 11:51 (look to the bottom right)
Now, I create a 100.000 threads. Looks at the audience as a bad boy.
Kotlin was inspired by Scala. Or in other words, it stole most of Scala's ideas.
👍
😊😀👍
Interestingly Kotlin didn't seem to learn javascript mistakes, like extension functions is similar to overriding prototype in javascript (do you remember prototype lib). But today considered as antipattern, because overriding prototype is dangerous.
Kotlin is compiled and statically typed, which eliminations many of the problems of JS prototypes.
Extension functions don't "override" anything. It's just a syntactic sugar. First, you need to import extension functions to be able to use them. Second, when you are declaring extension function on, let's say, String class, you are not changing the class itself, you just get a nice way to invoke your method. So you are not affecting any other code which uses String (unlike in javascript) and different libraries can have their own extension functions (even with the same name) and things are still going to work.
In essence, declaring extension function on String just creates a class StringKt with that method inside and the compiler replaces invocation "John Doe".getFirstWord() with StringKt.getFirstWord("John Doe") behind the scenes.
What do Kotlin Extension Functions have to do with Javascript??