The following are my on the fly notes taken at the 2017 Playgrounds Conference in Melbourne.
Disclaimer: There may be some errors
Chris Bailey, IBM
- BFF - back end for front end
- a layer that allows the frontend device to access backend hosted services
- web cares alot about first paint time compared to mobile which already has the UI in place
- https://swapi.co/api/people/1/
- to get a piece of information, may need 3 requests
- GraphQL allows you to request particular sub objects, but means more work in the client
- BFF - allows a custom layer infront of the API that has tailored request/responses
- Suggests that the frontend team writes their own BFF layer
- This means less assumptions and more understanding
- They can write the BFF layer in their native language (js/java/Swift)
- Aim is not to duplicate code, but to have the platform specific APIs only in the BFF
- https://github.com/IBM-Swift/Kitura.git
$ swiftservergenerator
- kitura.io
Matt Gallagher, Cocoa with Love
- How fast is Swift compared to ... c?
- Why is C considered the baseline for performance? Abstractions (or the lack therof)
- C is close to a 1:1 mapping to assembly
MT19937_64
Mersenne Twister Random Number Generator- Result: C 0.62s vs Swift 1.04s (of a naive implementation)
- Performance profiling analysis
- Speed up usage of arrays with
withUnsafeMutableBufferPointer
for looping var &+ 1
for an unchecked addition (we don't care about overflow)- Final result Swift run in 0.52s - with alot of cheating
- But the performance is actually identical if these steps are taken
Rachel Bobbins, Stitch Fix
- Refactoring is a lot like renovating
- Tools: Deprecation warnings, Other compiler warnings
- Know the problem. Have a vision
- Temporarily deprecate a method to see the scope of the required change
- Temporary protcols - to help bridge the old and the new
- Tests - use them to make sure critical paths don't break
Soroush Khanlou, Fatal Error Podcast
Sequence > Collection > BidirectionalCollection > RandomAccessCollection > RangeReplaceableCollection
- Sequence: a list of elements, can be infinite, iteration not always repeatable
Iteator.Element
- Implement a linked list as an
enum
because its swifty indirect
please let me reference myself within myself and don't freak out- Conform to
Sequence
and you get all the good stuff for free:forEach
,map
,filter
etc - Next, lets extend
Sequence
with acount
function - Easy, something a bit harder is to extend it with the
eachPair
function Collection
inherits fromSequence
, always finite and iteration is repeatable
Matt Comi, Big Bucket Games
- Heuristic - the approximate cost of moving from a tile to a destination
- Manhattan distance hueristic - tells you how many moves to the destination
- A* Algorithm - uses the Heuristic, the exploration is guided by the hueristic
- Start at the origin, calculate the cost of getting to the destination
- Loop outwards adding tiles to the closed set when they have the lowest cost
- When the destination is found, reverse the array and you have a path
Wendy Lu, Pinterest
- Pinterest rewrite from 2015-2016, took about a year
- Optimise data sent over the API
- App startup time
- Concurrency
AsyncDisplayKit
to configure views and lay them out off the main thread- Immutable model layer
- Shared state can be an issue if multiple writers can modify the same model
- Autogenerated model classes - JSON Scheme > Model class files
- Builder object pattern: a mutable representation of an immutable object
PINCache
- Merge the new data with the cached version and update the cache on object init
- http://moreindirection.blogspot.com/2014/08/nsnotificationcenter-swift-and-blocks.html
- https://engineering.pinterest.com/blog
- https://github.com/linkedin/RocketData
Harlan Haskins, Bryx & Student
- A compiler is a translator
- Input > Lexer ~> Token Stream > Parser ~> AST > Code Generator
- AST = Abstract Syntax Tree
- LLVM is a set of libraries for Compilers
- Centered around LLVM intermidate representation
Marin Usalj, Lyft
- Quote from apple
- As a user, you're sure you're getting authorized software
- Protects developers from unauthorized copying
- No competition for the App Store (iOS)
- Things break
- Important to understand the underlying technology
- Relies on public-key cryptography based on X.509 standard
- Introduced on OS X 10.8 - Gatekeeper
- CSR consists of info, algorithm and the signature (a public/private key pair is created)
$ openssl asn1parse
- RSA 2048 bit
- Public key used for the request
- Private key used to sign the binary
- Certificate - a public key combined with some additional information
- The additional info is signer data (issued by Apple, valid til, etc)
- Once again, can use
openssl
to read the contents of the CER file - PKCS#12 - archive file format for saving multiple crypto objects in a single file (.p12)
- Team, Bundle, App ID
- App ID is a team id + a bundle id (eg
4R5GH57P.com.yolo.ios.beta
) - Entitlements - iCloud, get-task-allow (only allow in debug), plist
$ codesign -d --entitlements :- Yolo.app
- Provisioning profiles - contains the app id, cert, entitlements, an ID and an expiry date
$ security cms -D 0i Yolo.app/embedded.mobileprovision
- tip: use
.xcconfigs
if you can for code signing settings
Dennis Pilarinos, buddybuild
- Review software development lifecycle
- Web app continuous build systems are better established than native apps
- Limitations of TestFlight (multiple versions, staging, confusing for users)
- Lots of slides of project usage stats
data
Samuel Giddins, CocoaPods
- Strings
- Unformatted data, often have meaning beyond the bytes
- The universal data type? Think UDID, JSON
- C strings are just arrays of
char
s - In Objective-C they are backed by a class cluster
NSString
- In Swift,
String
is a value-type struct, which is pretty complex - Encoding. ASCII, Unicode, et al
- Unicode - puts all characters in a single encoding. Every character. Every language. Unique code/number for each one.
- Swift strings are Unicode-aware (can correctly compare two versions of the same strings)
- ๐ performance, correctness, shipping - choose 2
Jason Brennan, Meetup
- What is education about? What can we as programmers to do to help?
- Alan Kay - an inspiration
- Book: Mark Johnson - The Meaning of the Body
- Book: Daniel Kahneman - Thinking, Fast and Slow
- Reality is a hallucination ๐ค
- We must ensure that human wisdom exceeds human power - Vi Hart
- What to do about it?
- Learn! (read books)
- Learning is hard, you have to train yourself over years to do it!
Ash Furrow, Artsy
- Synchronous programming is 'normal' programming
- CPU time is valuable and we don't want to waste it
- Asynchronous programming is executing code out of order from the way its written
- You can resume async code later on due to an external event
- Abstractions and tradeoffs, some languages are quite opiniated
- Node JS only has 1 thread, so alot of it is non-blocking
- Imagine if every function returned via a completion handler!
- Swift has built in async capabilities
- GCD - Grand Central Dispatch
NSOperationQueue
is built on top of GCD- Check out
DRBOperationTree
, open sourced by Artsy - Target/Action - used mainly by UI controls
- Callbacks / Completion handlers - short anonymous functions that execute at a later point in time
- Can lead to Callback hell - the traingle of doom
enum Result<T> { case success(T); case error(Error) }
(result types are monads)- Ok to use callbacks, they are good, but sometimes you need a better abstraction
- Promises/Futures
- Great to reduce the nesting, single point to handle errors
- Functional Reactive programming
- Streams of observables
- FRP is at its best when you are sent a stream of values over time
- FRP has a learning curve, but is a great option
- Actor Model
- Adds constraints and conditions on how you write your code that makes it complicated but very robust
- All the comms between actors is handled by message passing
- What about things we can't do in Swift?
- Async / Await - allows you to write async code that looks sync
- Coroutines and Generator Functions ๐ค
Greg Heo, Instagram
- ๐ค๐
-
- You already know it!
- Data flows, propagation of change, how data travels as inputs into your program and then as output
-
- Sequences everywhere
- Everything is a sequence
- An iterator is a sequence
- Sequences aren't indexable, have a single direction and are unbounded?
-
- Small pieces of logic
-
- Declarative style
- Think of
UIStackView
as declarative opposed tolayoutSubviews()
which is imperative -
- Testable code
- Can mock data with a sequence of test data, eg an array
Alan Zeino, Uber
- Uber scaled from a team of 10's to 200 iOS engineers
- We had a 5,000 line view controller
- Presidio - cool internal code name for the project of Rewriting
- Built in monitoring and analytics, with an opt-out policy
- De-risk experimentation - application framework with Plugin API
- "Riblets" design pattern - RIB - Router Interaction Builder
- And optionally, a Presenter and a View
- http://t.uber.com/rider-app
- 8000
.swift
files, about 10% are code generated - 700,000 lines of Swift
- Compile times increased alot due to Swift
swiftc -Onone -whole-module-optimization
-Xfrontend -warn-long-function-bodies=100
- Optimise the number of dylibs as this affects the startup time of the app as the OS loads the
- Takes 250ms to load the Swift standard lib on iPhone 6s
- Swift 3 migration - 160867 insertions, 105132 deletions - ouch
- Keep an eye on compile times
- No compiler setting is untouchable!
- Too many dynamic libs can hurt your startup performance
- Consider using Buck
- File radars because Apple needs them
Erica Sadun, Author
- Style rules are personal choices
- Why style?
- Code should be invisible
- Focus on meaning
- Reduce cognitive load
- Uniformity
- Consistent rules produce consistent code
- Underscores in numbers?
1732500
vs1_732_500
- Same for hex strings
0xffffff
vs0xff_ff_ff
Felix Krause, fastlane
- 4 stages of open source projects
-
- Publish source code
-
- Developers start using your project
-
- Go-to solution in its field
-
- Hyper scale projects
- Keeping the momentum
- Handling support
- Reviewing PR's can take as long as just writing the feature itself
- Maintainers are so busy maintaining, they stop using the product, which is a problem
- How to scale open source projects
- Improve your error messages
- Make it easy to find existing issues
- Use bots to filter issues and PRs to filter out the noise
- Responding to pull requests
danger
- Be welcoming and friendly ๐
- Local extensions / plugins ro allow developers to extend/customise the functionality for their project
Hecthor Matos, Capital One
- The Game Loop
- Lag is introduced when your update code takes longer than its alloted in the run loop, causing the next frame to be dropped
- Contact detection/collisions
SKPhysicsContactDelegate
- For collision behaviour at least one physics body must have a collision bitmask
- Bitmasks are the most efficient way of comparing sprites
- Architecture
- Single responsibility principle
- https://github.com/KrakenDev/SuperMarioWorld
Tamar Nachmany, Tumblr
- Do the designers I work with know this concept?
- Have I taken the time to explain to designers how the code/UI layout works?
- Anyone can become a teacher
- Software developlment is the reuse of logics and types across a system
- Unit tests validate individual units of code by executing logic and asserting expected results
- Unit testing is a vehicle for change
- Unit testing automates identifying new issues
- Tests reflect the construction of a codebase or a type
- Modularity is how units become units
- Safety is the reduction of chaos
- Designing a test is a type of abstraction
- Innovation - Don't learn by example, be the example
Chris Eidhof, objc.io
- Functional programming dogma - immutability is the best
- Mutability can make code harder to read as you need to keep track of the current value
- Immutable objects are good for multi threading or async code
- Structs will solve everything - if you
let struct
then its values are constant (as opposed to an object) - The mutablily of a struct is controlled by
let
vsvar
mutating
keyword on a struct's func tells you thatself
is mutableCtrl+Opt+Cmd+F
- fix all in scope - handy keyboard shortcut- A new
var
for a struct is a new copy, as opposed to a new reference for an object - Array's are structs so can be treated the same
Adam Bell, Facebook
- What made iOS so good? Interaction and Animation
- How can we remove some of the waiting from animations? (So we can interact with the screen all the time)
- Interruptible animations - should be interrupted, cancelled or ignored, begin again with or without interaction
UIScrollView
is interruptable- Without interruptibility, apps feel laggy, unresponsive or broken
- iOS has been making improvements to this, in the OS and in the animation APIs
- Pro-tip:
UIView
animations are kind of limiting when it comes to prematurely cancelling animations POP
is an animation open source animation framework- Selective interruptibility - should avoid blocking user interaction when possible
- It requires a bit more work, but is worth it to improve usability
Side note: (All/most?) speakers from the northen hemisphere had 1 slide in their deck upside down ๐๐ฆ๐บ