Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kotlin on the Cloud

Kotlin on the Cloud

Slides for my 'Kotlin on the Cloud' talk at the Google Developer Group Lisboa's Kotlin Night.

Eb987f4f2b2d43faa8b3b5a377713913?s=128

João Carvalho

October 12, 2017
Tweet

Transcript

  1. Kotlin on the Cloud João Carvalho - GDG Lisboa -

    Oct 12 2017
  2. About me

  3. About me • Senior Developer / Team Lead @ Talkdesk

    • Backend Developer • IST Alumni (Student & Developer) • PT.JUG Speaker • Follow me on Twitter @johnkarva
  4. Cloud Native Apps https://pivotal.io/cloud-native

  5. “Cloud-native is an approach to building and running applications that

    fully exploits the advantages of the cloud computing delivery model. Cloud-native is about how applications are created and deployed, not where.”
  6. • Devops • Continuous Delivery • Microservices • Containerization

  7. Predictability

  8. 12 Factor App 1. Single codebase, multiple deploys 2. Explicit

    Dependencies 3. Store Config in Environment 4. Backing Services as resources 5. Separate Build, Release, Execution 6. Standalone (Volatile) Process 7. Port Binding 8. Multiple Process Types 9. Disposability 10. Environment Parity 11. Logs as Event Streams 12. One-off Admin Tasks
  9. OS-Agnostic

  10. Auto-Scaling

  11. Independence

  12. Quick Recovery

  13. Agility

  14. Kotlin

  15. Why not Java 8/9?

  16. Null Safety

  17. public void printName(Person person) { System.out.println(person.getName()); }

  18. public void printName(Person person) { System.out.println(person.getName()); } null

  19. None
  20. fun printName(person: Person) { println(person.name) }

  21. printName(null) ERROR: Null cannot be a value of non-null type

    Person.
  22. fun printName(person: Person?) { if (person != null) { println(person.name)

    } }
  23. Safe Navigation

  24. private String safeGetName(Person person) { return person == null ?

    null : person.getName(); }
  25. fun safeGetName(person: Person?): String? { return person?.name }

  26. fun safeGetName(person: Person?): String { return person?.name ?: "Unknown" }

  27. Properties

  28. class Person(name: String) { private val name: String init {

    this.name = name } }
  29. class Person(private val name: String)

  30. Delegated Properties

  31. val lazyValue: String by lazy { println("computed!") "Hello" }

  32. Extension Functions

  33. fun String.helloize() = "Hello $this" "World".helloize()

  34. Data Classes

  35. public class Person { private String name; private int age;

    public Person(String name, int age) { this.name = name; this.age = age; } (...) }
  36. public String getName() { return name; } public void setName(String

    name) { this.name = name; } @Override public boolean equals(Object o) { (Stuff generated by your IDE) } @Override public int hashCode() { int result = name.hashCode(); result = 31 * result + age; return result; }
  37. None
  38. data class Person(var name: String, var age: Int)

  39. data class Person(val name: String, val age: Int)

  40. val john = Person("John", 21) val olderJohn = john.copy(age =

    78)
  41. And much more... • No Semicolons! • Lambda Expressions and

    Inline Functions • Type inference • Named Arguments • Default Values • String Interpolation • Ranges • Immutable Collections (Kind of) • Collection helpers • Infix Functions • DSL Support
  42. Performance

  43. Tooling

  44. Getting Started

  45. None
  46. None
  47. None
  48. None
  49. @RestController @SpringBootApplication public class DemoApplication { public static void main(String[]

    args) { SpringApplication.run(DemoApplication.class, args); } @GetMapping("/hello") public String hello() { return "Hello World!"; } }
  50. http://shop.oreilly.com/product/0636920038252.do

  51. Cloud-Native Kotlin?

  52. None
  53. https://docs.spring.io/spring/docs/current/spring-framework-reference/kotlin.html

  54. Demo Time!

  55. Questions?