mobile library development - stuck between a pod and a jar file - zan markan - codemotion amsterdam...

42
Mobile Library Development Stuck between a Pod and a Jar file Zan Markan @zmarkan AMSTERDAM 16 - 17 MAY 2017

Upload: codemotion

Post on 21-Jan-2018

545 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

Mobile Library DevelopmentStuck between a Pod and a Jar file

Zan Markan @zmarkan

AMSTERDAM 16 - 17 MAY 2017

Page 2: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkanZan Markan @zmarkan

LIBRARY DEVELOPMENTstuck between a pod and a jar file

Page 3: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan©Copyright @zmarkan 2017

About MeDeveloper for 8+ years

Mostly Android, mobile

>>

See also: emoji overuser

Page 4: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan@zmarkan

Developer tools company

blog.pusher.com

Chat API

Hiring in Ldn

Trusted by 150k+ devs pusher.com | @pusher

Page 5: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Contents of this talk● Libs 101● API Design● Development & Testing● Releasing● Docs

...and more!

Page 6: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

We building libs because... Avoid duplicating logic - Best Practice

Sharing == Caring

It’s a great way to enrich your

We want to be paid

Page 7: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Libraries are a collection of classes and methods that encapsulate common, shared functionality.

Page 8: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Libs != AppsLibraries are NOT end products

Smaller, more lightweight than apps

Many x Many apps/lib ratio

Page 9: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

All about that Lib...What: Libraries, Frameworks, SDKs

Type: General libs, UI Widgets, Serverside, Testing

Access: Publicly vs Privately accessible

Pricing: FOSS, Free to use vs Commercial

API: DSL, Reactive, n other things...

Page 10: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Product is about the User● Developers (like you and I)● Varied backgrounds, levels of experience● User experience -> Developer experience

Page 11: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

the truth about developersLibrary users are Developers…

… developers are very lazy, so...

libraries should enable laziness.

Page 12: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

API

Page 13: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

The API is to a library what the

USER INTERFACEis to an APP

Page 14: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Things I mean by APIEntry points

Interaction points

Data model

Errors & Exceptions

Page 15: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Entry points(where people first interact with your code)

They allow you to instantiate and configure the library

In “Code”: Constructors, Builders, Factories

In UI: Widgets

Page 16: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Construction in CodeiOS: Named Parameters, Optionals

Android: (Overloaded) Constructors, Builders

Both: Sensible defaults >> Customisation

Also in Kotlin on Android!

Page 17: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Builder Poor person’s named args

… and optional args

Ensures constructor is passed correct values, and

validates its state before building the class

Page 18: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Methods & ModelsWhen in doubt - go S.O.L.I.D.

Naming, Naming, Naming!

Don’t surprise your users!(But you can delight them)

Page 19: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

(R)X-FactorAysnc as a stream of eventsAllows chaining, and functional operations

Support all the things: RxSwift, RxJava (even PHP!)

More: Paco Estevez makes AWESOME Rx libs/articles/talks

Page 20: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

RX in briefeventStream

.filter(//condition)

.flatMap(//transformation)

.subscribe(//handleSuccess, //handleError)

Not shown: one million operators, threading, ...

Page 21: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

RX… but

It’s still a power user feature

Callbacks are still often preferred

provide RX adapter as an optional extra?

Page 22: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

DSL-o-Matic... 9000Make your own little programming language…...by inventing a syntax that works for you!

Examples: Hamcrest, Rx, Kotlin Anko

Techniques: Macros, Annotations, Operator overloading, Extension methods, ...

Page 23: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

When things go ● Let it crash!● Early● Often

Ensure the error messaging is spot on

Add links in error messages to explanations

Page 24: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Anatomy of a “nice” ErrorType: Illegal Input

Message: Request unsuccessful, reason: malformed auth token

Link: https://example.com/errors/123456

Explain things here!

Page 25: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

DEV & TEST

Page 26: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Performance or Be wary of:

● Library size => App size● Memory leaks● Build times ● Needless dependencies

Page 27: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

API should be beautiful.Implementation should

f*****g work.

Page 28: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Testing it & Loving it The easy: Unit Tests

The hard: Integration Tests with an app

The smart: foodingMore in: David Schreiber-Ranner’s talk from Droidcon Vienna 2016

Page 29: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Tracking & AnalysisProblem: No Google Analytics for libraries

Track at the service level?

Listen and talk to users

fooding: Redux

unless you’re Fabric

Page 30: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Page 31: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

(Semantic) Versioning 2.0Major[.]Minor[.]Patch

● Major: Breaking changes● Minor: New features● Patch: Hotfixes Shouldn’t ever happen● semver.org

Page 32: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Releasing (how not to do it)

● Manually include the builds in your project

(Bad idea in most cases)

● Include project as a Git submodule

(Even worse idea in all cases)

Page 33: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Releasing (the right way)

: Carthage, CocoaPods

Simple, git-based tools with some workspace-gen

: Maven Central, JCenter, Jitpack

Maven-based dependency managers ^^

Page 34: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Releasing (privately)

: Carthage, CocoaPods << Work with private git repos ^^

: Sonatype Nexus, Artifactory Pro, Jitpack ^^ hosted solutions, will cost you

: Maven repo on S3, Artifactory OS ^^ free as in (just add server!)

Page 35: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

DOCS

Page 36: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

50 shades of Docs● Quick Start ● Sample apps ● Java/Swift Doc ● Wiki pages ● Yes, even tests! ● Mix & Match!

Page 37: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Quickstart a.k.a.

“Let me copypaste something”

Page 38: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Sample code● Should be small, confined apps● … often alongside libraries in the same repo● Should reflect your libraries’ features● Can go in-depth for more advanced features

Page 39: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

JavaDoc & SwiftDoc● Cheap to make● Automagically generated ● (Just add comments!)● Great in IDEs: Android Studio & XCode● Host it alongside your other docs

Page 40: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

Libraries enable app developers to be lazy. Docs enable library developers to be lazy.

Page 41: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan

The takeawaysLibs 101

API design

Development

Releasing

Support

Page 42: Mobile Library Development - stuck between a pod and a jar file - Zan Markan - Codemotion Amsterdam 2017

@zmarkan©Copyright @zmarkan 2017

fin

Blog: www.spacecowboyrocketcompany.com

Twitter: @zmarkan

Github: @zmarkan

Email: zan@[pusher.com | markan.me]