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

[Mateusz Herych] Guava beyond Collections

[Mateusz Herych] Guava beyond Collections

Presentation from GDG DevFest - the biggest Google related event in Ukraine. October 24-25, Lviv. Learn more at http://devfest.gdg.org.ua/

Google Developers Group Lviv

October 25, 2014
Tweet

More Decks by Google Developers Group Lviv

Other Decks in Programming

Transcript

  1. Java is not perfect.

    View full-size slide

  2. Java sucks.
    At least compared to other languages.

    View full-size slide

  3. Scala?
    case class Person (firstName: String, lastName: String)

    View full-size slide

  4. class Person {
    private final String firstName;
    private final String lastName;
    public Person(String firstName, String lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
    }
    }

    View full-size slide

  5. class Person {
    private final String firstName;
    private final String lastName;
    public Person(String firstName, String lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
    }
    public String getFirstName() {
    return firstName;
    }
    public String getLastName() {
    return lastName;
    }
    }

    View full-size slide

  6. Scala?
    case class Person (firstName: String, lastName: String)

    View full-size slide

  7. Mateusz Herych
    GDG Kraków
    Android GDE
    Engineer, Base CRM

    View full-size slide

  8. Google’s Java

    View full-size slide

  9. Wikipedia
    In programming, nullable types are a feature of the type
    system of some programming languages which allow the
    value to be set to the special value NULL instead of the
    usual possible values of the data type. In statically-typed
    languages, a nullable type is an option type (in functional
    programming terms), while in dynamically-typed
    languages (where values have types, but variables do
    not), equivalent behavior is provided by having a single
    null value.

    View full-size slide

  10. Null’s inventor

    View full-size slide

  11. Sir Tony Hoare
    “I call it my billion-dollar
    mistake. It was the invention
    of the null reference in 1965.”

    View full-size slide

  12. Billion dollar mistake.

    View full-size slide

  13. Key -> List of Values

    View full-size slide

  14. Aygul - [2]
    Mateusz - [1,2,3]

    View full-size slide

  15. Immutable Collections

    View full-size slide

  16. Mutable state

    View full-size slide

  17. Mutable state

    View full-size slide

  18. Mutable state
    - Race conditions (multiple threads anyone?)

    View full-size slide

  19. Mutable state
    - Race conditions (multiple threads anyone?)
    - Harder debugging (what/who caused THAT
    change to my object?)

    View full-size slide

  20. Mutable state
    - Race conditions (multiple threads anyone?)
    - Harder debugging (what/who caused THAT
    change to my object?)
    - Do you trust your libraries?

    View full-size slide

  21. Do you trust them?

    View full-size slide

  22. Okay, don’t be that paranoid maybe.

    View full-size slide

  23. Usually you can trust your libraries.

    View full-size slide

  24. You don’t want to trust your co-
    workers, don’t you?

    View full-size slide

  25. Immutable = Not changed over time.

    View full-size slide

  26. Also:
    - ImmutableMap
    - ImmutableSet
    - ...

    View full-size slide

  27. Some operations are heavy

    View full-size slide

  28. And we want to avoid invoking them
    more that it’s needed

    View full-size slide

  29. Caches are hard

    View full-size slide

  30. Caches
    - Expiration

    View full-size slide

  31. Caches
    - Expiration
    - Invalidation

    View full-size slide

  32. Caches
    - Expiration
    - Invalidation
    - Weight/Sizes...

    View full-size slide

  33. Caches
    - Expiration
    - Invalidation
    - Weight/Sizes…
    - … aaand that’s only beginning!

    View full-size slide

  34. Guava is huge!

    View full-size slide

  35. Preconditions
    Concurrency
    I/O
    EventBus! (but don’t use it on Android)
    Tons of utilities

    View full-size slide

  36. https://code.google.com/p/guava-
    libraries/wiki/GuavaExplained

    View full-size slide

  37. 65K method limit, anyone?

    View full-size slide

  38. Proguard in debug - no obfuscation, just
    shrinking unused methods

    View full-size slide

  39. Proguard in debug - no obfuscation, just
    shrinking unused methods.
    Multidex

    View full-size slide

  40. Proguard in debug - no obfuscation, just
    shrinking unused methods.
    Multidex
    jar stripping?

    View full-size slide

  41. There are WAYS

    View full-size slide

  42. Just give it a try

    View full-size slide

  43. and become a Guava addict

    View full-size slide