Kotlin - a JUG.RU talk, 2016
-
Upload
andrey-breslav -
Category
Technology
-
view
218 -
download
0
Transcript of Kotlin - a JUG.RU talk, 2016
Andrey Breslav
http://kotlinlang.org
JetBrains
• Pragmatic language for industry– Started in 2010– Open Source– 1.0 Released in Feb, 2016
• For JVM, Android, and JavaScript– Interoperability: 100%
• Try online: https://try.kotl.in
bytecode
Kotlin
Technicalities
• Few compiler optimizations – inlning as a language feature
• Compiler intergated into the IDE
• Incrementality
Requirements
• Statically typed
• “Toolable” (is this a word at all?)
• Interoperable (yes, C++ has been there!)
• Learnable (“democratic”)
Comparing to others
Over 500K LOC of Kotlin:
IntelliJ IDEARider (C# IDE)
YouTrackJetBrains Account
(and more)
In Open-Source Projects, Kotlin itself excluded
In Open-Source Projects, Kotlin itself excluded
IDE
Compiler
(Incremental)Build System
Java*.kt *.java
compiler
Javacompiler
“Billion dollar mistake”— Sir C. A. R. Hoare
Java String s = null;
s.length();
Errors At Runtime
Kotlin val s: Strings.length()
val s: String? = nulls.length()
Errors At Compile Time
= nullNullable
type
Check and use val s: String? = …if (s != null) { s.length()}
Check and exit if (s == null) return
s.length()
Rock’n’Roll s?.length()s!!.length()(s ?: “…”).length()
Kotlin is good with nulls
What about Java?
Java (as seen from Kotlin)public class JavaClass { public String foo(List<String> l) {…}}
String
String?
List<String>
List<String?>
List<String>?
List<String?>?
Safest!
Java Interop: All Nullable
javaValue.toString().length() + 1
javaValue?.toString()?.length()!! + 1
val l: List<String> = javaValue?.getList()!!
ArrayList<String?>
Your safest option doesn’t
work!
Annotationspublic class JavaClass { @NotNull public String foo(@NotNull List<String> l) {…}}
String
String?
List<String>
List<String?>
List<String>?
List<String?>?
Annotations are cumbersome
ANDdon’t really help!
Pick Two
• Null-safety• Convenience• Java Interop
Platform Types!
Thanks toDr. Ross Tate of
Java: Platform Typespublic class JavaClass { public String foo(Bar<String> l) {…}}
String! Bar<String!>!
Platform Type
Dereferencing Platform Values
s: String s: String? s: String!
s.length() s.length() s.length()
s?.length() s?.length() s?.length()
s!!.length() s!!.length() s!!.length()
NPE
Assignability
String String?
String!
Platform Type
Not Transitive!NPE
Some Notes
• Platform Types are Not Denotable!– String! is notation, not syntax
• Pure Kotlin is Null-Safe• Kotlin+Java is as safe as Java
• Annotations Still Applicable– @NotNull String in Java becomes String in Kotlin
• Dynamic Type for JavaScript Interop– JS is even unsafer than Java
Nullable types: Summary
Cost• More Complexity• Less Null-Safety
Benefit• Smooth Interop
http://kotlinlang.org
Images Used
• http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-32-02-metablogapi/8054.image_5F00_thumb_5F00_35C6E986.png
• http://www.complete-coherence.com/wp-content/uploads/2015/06/Is-business-rational-or-emotional.jpg
• http://www.mightyheaton.com/wp-content/uploads/2012/05/33-1024x908.jpg
• https://openclipart.org/image/2400px/svg_to_png/97543/text-file-icon.png
• http://fileinfo.com/img/icons/files/128/class-737.png
• http://1.bp.blogspot.com/-UK5uEhDELUA/T9duhHrDeII/AAAAAAAAB20/nKpYXYhqub4/s1600/application-x-jar%5B1%5D.png