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

Escape from Java

Escape from Java

Slides of the talk I gave at Kotlin Night Torino 2018

6923bdeb363961b064d2cdb6329982d6?s=128

Roberto Orgiu

June 08, 2018
Tweet

More Decks by Roberto Orgiu

Other Decks in Programming

Transcript

  1. Escape from Java The Java Programming Language™

  2. Rob

  3. Why Kotlin?

  4. Why Kotlin? Less Libraries

  5. Why Kotlin? Less Libraries More readability

  6. Why Kotlin? Less Libraries More readability Many functions out of

    the box
  7. Why Kotlin? Less Libraries More readability Many functions out of

    the box
  8. False myths

  9. False myths Budget

  10. False myths Budget Tooling

  11. False myths Budget Tooling Learning curve

  12. False myths Budget Tooling Learning curve

  13. public class Model { private String property; private int anotherProperty;

    private float wowAnotherProperty; private double pleaseStahpDude; public String getProperty() { return property; } public void setProperty(String property) { this.property = property; } public int getAnotherProperty() { return anotherProperty; } public void setAnotherProperty(int anotherProperty) {
  14. } public void setAnotherProperty(int anotherProperty) { this.anotherProperty = anotherProperty; }

    public float getWowAnotherProperty() { return wowAnotherProperty; } public void setWowAnotherProperty(float wowAnotherProperty) this.wowAnotherProperty = wowAnotherProperty; } public double getPleaseStahpDude() { return pleaseStahpDude; } public void setPleaseStahpDude(double pleaseStahpDude) { this.pleaseStahpDude = pleaseStahpDude; } }
  15. public class Model { private String property; private int anotherProperty;

    private float wowAnotherProperty; private double pleaseStahpDude; public String getProperty() { return property; } public void setProperty(String property) { this.property = property; } public int getAnotherProperty() { return anotherProperty; } public void setAnotherProperty(int anotherProperty) { this.anotherProperty = anotherProperty; } public float getWowAnotherProperty() { return wowAnotherProperty; } public void setWowAnotherProperty(float wowAnotherProperty) { this.wowAnotherProperty = wowAnotherProperty; } public double getPleaseStahpDude() { return pleaseStahpDude; } public void setPleaseStahpDude(double pleaseStahpDude) { this.pleaseStahpDude = pleaseStahpDude; } }
  16. public class Model { private String property; public String getProperty()

    { return property; } public void setProperty(String property) { this.property = property; } }
  17. public class Model { private final String property; public Model(String

    property) { this.property = property; } public String getProperty() { return property; } }
  18. import android.support.annotation.Nullable; public class Model { private final @Nullable String

    property; public Model(@Nullable String property) { this.property = property; } @Nullable public String getProperty() { return property; } }
  19. public class Model implements Parcelable{ private final @Nullable String property;

    public Model(@Nullable String property) { this.property = property; } protected Model(Parcel in) { property = in.readString(); } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(property); } @Override public int describeContents() { return 0; } public static final Creator<Model> CREATOR = new Creator<Model>() { @Override public Model createFromParcel(Parcel in) { return new Model(in); } @Override public Model[] newArray(int size) { return new Model[size]; } }; @Nullable public String getProperty() { return property; } }
  20. import android.os.Parcelable import kotlinx.android.parcel.Parcelize @Parcelize data class Model(val property: String?)

    : Parcelable
  21. AutoValue Guava Immutables Parceler Annotations

  22. GSON uses Reflection

  23. GSON uses Reflection Custom TypeAdapters

  24. GSON uses Reflection Custom TypeAdapters Vimeo Stag to generate code

  25. GSON uses Reflection Custom TypeAdapters Vimeo Stag to generate code

    Moshi
  26. RxJava+ Retrofit

  27. Coroutines+ Retrofit

  28. Retrofit.Builder() .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .baseUrl(BuildConfig.API_ENDPOINT) .build()

  29. Retrofit.Builder() .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .baseUrl(BuildConfig.API_ENDPOINT) .build() interface ApiService { @GET("home") fun home():

    Single<HomeResponse> }
  30. Retrofit.Builder() .addCallAdapterFactory(CoroutineCallAdapterFactory()) .baseUrl(BuildConfig.API_ENDPOINT) .build()

  31. Retrofit.Builder() .addCallAdapterFactory(CoroutineCallAdapterFactory()) .baseUrl(BuildConfig.API_ENDPOINT) .build() interface ApiService { @GET("home") fun home():

    Deferred<HomeResponse> }
  32. Coroutines do not replace RxJava

  33. Guava

  34. Guava Collections getFirst() getLast() concat() addAll() contains() isEmpty() toImmutableList()

  35. Guava Collections getFirst() getLast() concat() addAll() contains() isEmpty() toImmutableList() Strings

    join() split() trim() any() whitespace()
  36. Guava Collections getFirst() getLast() concat() addAll() contains() isEmpty() toImmutableList() Strings

    join() split() trim() any() whitespace() Optionals
  37. Guava Collections getFirst() getLast() concat() addAll() contains() isEmpty() toImmutableList() Strings

    join() split() trim() any() whitespace() Optionals Ranges
  38. Guava Collections getFirst() getLast() concat() addAll() contains() isEmpty() toImmutableList() Strings

    join() split() trim() any() whitespace() Optionals Ranges
  39. AutoValue Guava Immutables Parceler Annotations Guava Collections RetroLambda Project Lombok

  40. None
  41. open.nytimes.com @nytdev github.com/NYTimes developers.nytimes.com

  42. QA &