Why otlin?
Sprint Part 1
Kirill Rozov
Senior Android Developer
@kiryl.rozau
kiryl.rozau@apalon.com
Main facts
• Was born at JetBrains in 2010
• Modern replacement of Java
• Releases
• 1.0 was at February 2016
• 1.1 was at March 2017
• Kotlin is official supported by Google for Android
Simplify the development
Data Class in Java
public class Device {
private String id;
private String name;
private String cpu;
private long ramSize;
public Device(@NotNull String id, @NotNull String name, @NotNull String cpu, long ramSize) {
this.id = id;
this.name = name;
this.cpu = cpu;
this.ramSize = ramSize;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCpu() {
return cpu;
}
public void setCpu(String cpu) {
this.cpu = cpu;
}
public long getRamSize() {
return ramSize;
}
public void setRamSize(long ramSize) {
this.ramSize = ramSize;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Device device = (Device) o;
return ramSize == device.ramSize && id.equals(device.id) && name.equals(device.name) && cpu.equals(device.cpu);
}
@Override
public int hashCode() {
int result = id.hashCode();
result = 31 * result + name.hashCode();
result = 31 * result + cpu.hashCode();
result = 31 * result + (int) (ramSize ^ (ramSize >>> 32));
return result;
}
@Override
public String toString() {
return "Device{" + "id='" + id + ''' + ", name='" + name + ''' + ", cpu='" + cpu + ''' + ", ramSize=" + ramSize + ‘}';
}
}
Data Class in Kotlin
data class Device(var id: String, var name: String, var cpu: String, var ramSize: Long)
Operations with data array
List<Device> qualcommCpuDevices = new ArrayList<>();
for (Device device : devices)
if (device.getCpu().equals("Qualcomm"))
qualcommCpuDevices.add(device);
List<Device> largeRamQualcommDevices = new ArrayList<>();
for (Device device : qualcommCpuDevices)
if (isLargeRamDevice(device))
largeRamQualcommDevices.add(device);
List<String> deviceNames = new ArrayList<>();
for (Device device : largeRamQualcommDevices)
deviceNames.add(device.getName());
Operations with data array
devices.stream()
.filter(device -> device.getCpu().equals("Qualcomm"))
.filter(Device::isLargeRamDevice)
.map(Device::getName)
.collect(Collectors.toList());
List<Device> qualcommCpuDevices = new ArrayList<>();
for (Device device : devices)
if (device.getCpu().equals("Qualcomm"))
qualcommCpuDevices.add(device);
List<Device> largeRamQualcommDevices = new ArrayList<>();
for (Device device : qualcommCpuDevices)
if (isLargeRamDevice(device))
largeRamQualcommDevices.add(device);
List<String> deviceNames = new ArrayList<>();
for (Device device : largeRamQualcommDevices)
deviceNames.add(device.getName());
Operations with data array
devices.stream()
.filter(device -> device.getCpu().equals("Qualcomm"))
.filter(Device::isLargeRamDevice)
.map(Device::getName)
.collect(Collectors.toList());
devices.filter { it.cpu == "Qualcomm" }
.filter(Device::isLargeRamDevice)
.map { it.name }
.toList()
Operations with data array
Characters
0
100
200
300
400
500
Java Java 8 Kotlin
97
153
447
Simplify the development
• Reducing the amount of code
• Integration with modern development software
• Built-in tools for improving code stability
Interoperability
Interoperability
• 100% compatibility with Java code in both directions
• No need to bundle additional runtime to the app
• Backward compatibility with previous versions
• Easy convert Java code to Kotlin
Support
Support
• Developing by JetBrains
• Google official support for Android
• Open Source
• Working with community
• Frequent updates
GitHub repos count
Repositories
0
2500
5000
7500
10000
2013 2014 2015 2016 2017 Now
Release 1.0
Release 1.1
Official Android support
Who uses Kotlin
Platforms
Platforms
Learning
Learning
• Easy “Getting Started”
• Studying Kotlin: online or offline
• Many code samples and videos
• Good documentation
• Books from language makers
Reduce time
Reduce time
1. Less time for implementation
2. More stability -> less test time
3. Interoperability with old projects
4. Low entry barrier for Java developers
5. Common codebase for different platforms
Next step?
Q&A
Thanks!
goo.gl/ApXkhW

Why Kotlin - Apalon Kotlin Sprint Part 1

  • 1.
  • 2.
    Kirill Rozov Senior AndroidDeveloper @kiryl.rozau kiryl.rozau@apalon.com
  • 3.
    Main facts • Wasborn at JetBrains in 2010 • Modern replacement of Java • Releases • 1.0 was at February 2016 • 1.1 was at March 2017 • Kotlin is official supported by Google for Android
  • 5.
  • 6.
    Data Class inJava public class Device { private String id; private String name; private String cpu; private long ramSize; public Device(@NotNull String id, @NotNull String name, @NotNull String cpu, long ramSize) { this.id = id; this.name = name; this.cpu = cpu; this.ramSize = ramSize; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCpu() { return cpu; } public void setCpu(String cpu) { this.cpu = cpu; } public long getRamSize() { return ramSize; } public void setRamSize(long ramSize) { this.ramSize = ramSize; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Device device = (Device) o; return ramSize == device.ramSize && id.equals(device.id) && name.equals(device.name) && cpu.equals(device.cpu); } @Override public int hashCode() { int result = id.hashCode(); result = 31 * result + name.hashCode(); result = 31 * result + cpu.hashCode(); result = 31 * result + (int) (ramSize ^ (ramSize >>> 32)); return result; } @Override public String toString() { return "Device{" + "id='" + id + ''' + ", name='" + name + ''' + ", cpu='" + cpu + ''' + ", ramSize=" + ramSize + ‘}'; } }
  • 7.
    Data Class inKotlin data class Device(var id: String, var name: String, var cpu: String, var ramSize: Long)
  • 8.
    Operations with dataarray List<Device> qualcommCpuDevices = new ArrayList<>(); for (Device device : devices) if (device.getCpu().equals("Qualcomm")) qualcommCpuDevices.add(device); List<Device> largeRamQualcommDevices = new ArrayList<>(); for (Device device : qualcommCpuDevices) if (isLargeRamDevice(device)) largeRamQualcommDevices.add(device); List<String> deviceNames = new ArrayList<>(); for (Device device : largeRamQualcommDevices) deviceNames.add(device.getName());
  • 9.
    Operations with dataarray devices.stream() .filter(device -> device.getCpu().equals("Qualcomm")) .filter(Device::isLargeRamDevice) .map(Device::getName) .collect(Collectors.toList()); List<Device> qualcommCpuDevices = new ArrayList<>(); for (Device device : devices) if (device.getCpu().equals("Qualcomm")) qualcommCpuDevices.add(device); List<Device> largeRamQualcommDevices = new ArrayList<>(); for (Device device : qualcommCpuDevices) if (isLargeRamDevice(device)) largeRamQualcommDevices.add(device); List<String> deviceNames = new ArrayList<>(); for (Device device : largeRamQualcommDevices) deviceNames.add(device.getName());
  • 10.
    Operations with dataarray devices.stream() .filter(device -> device.getCpu().equals("Qualcomm")) .filter(Device::isLargeRamDevice) .map(Device::getName) .collect(Collectors.toList()); devices.filter { it.cpu == "Qualcomm" } .filter(Device::isLargeRamDevice) .map { it.name } .toList()
  • 11.
    Operations with dataarray Characters 0 100 200 300 400 500 Java Java 8 Kotlin 97 153 447
  • 12.
    Simplify the development •Reducing the amount of code • Integration with modern development software • Built-in tools for improving code stability
  • 14.
  • 15.
    Interoperability • 100% compatibilitywith Java code in both directions • No need to bundle additional runtime to the app • Backward compatibility with previous versions • Easy convert Java code to Kotlin
  • 16.
  • 17.
    Support • Developing byJetBrains • Google official support for Android • Open Source • Working with community • Frequent updates
  • 18.
    GitHub repos count Repositories 0 2500 5000 7500 10000 20132014 2015 2016 2017 Now Release 1.0 Release 1.1 Official Android support
  • 19.
  • 21.
  • 22.
  • 23.
  • 24.
    Learning • Easy “GettingStarted” • Studying Kotlin: online or offline • Many code samples and videos • Good documentation • Books from language makers
  • 25.
  • 26.
    Reduce time 1. Lesstime for implementation 2. More stability -> less test time 3. Interoperability with old projects 4. Low entry barrier for Java developers 5. Common codebase for different platforms
  • 28.
  • 29.
  • 30.