Slide 1

Slide 1 text

let title: String = “The Future Favors Swift” // @ythecombinator // #cocoaheads

Slide 2

Slide 2 text

 @ythecombinator  #BEPiD DEV I/O, NUG, COCOAHEADS, ANDROID MEETUP, IONIC MEETUP, LAMBDA I/O…  ☕ 

Slide 3

Slide 3 text

 @ythecombinator  #BEPiD DEV I/O, NUG, COCOAHEADS, ANDROID MEETUP, IONIC MEETUP, LAMBDA I/O…  ☕  #after 

Slide 4

Slide 4 text

!!!

Slide 5

Slide 5 text

this talk is much of a very opinionated conversation.

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

“in a VERY NEAR FUTURE, Swift will be in the same "FULL-STACK LANGUAGE STATE" JavaScript is in.” - ythecombinator

Slide 12

Slide 12 text

https://nodesource.com/node-by-numbers

Slide 13

Slide 13 text

https://nodesource.com/node-by-numbers

Slide 14

Slide 14 text

https://nodesource.com/node-by-numbers

Slide 15

Slide 15 text

https://nodesource.com/node-by-numbers

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

•Optionals & Generics • Protocols & Extensions • Pattern Matching • ARC • Good Error Handling • "Safety" by design • Common Functional Programming Constructs

Slide 18

Slide 18 text

http://githut.info/

Slide 19

Slide 19 text

http://githut.info/ #1  #19 

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Swift

Slide 22

Slide 22 text

! " #  %

Slide 23

Slide 23 text

server- side !

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Slide 26

Slide 26 text

https://github.com/Awesome-Server-Side-Swift/TheList

Slide 27

Slide 27 text

import Vapor let drop = Droplet() drop.get("/hello") { _ in return "Hello Vapor" } drop.run()

Slide 28

Slide 28 text

import Kitura let router = Router() router.get("/") { request, response, next in response.send("Hello, World!") next() } Kitura.addHTTPServer(onPort: 8090, with: router) Kitura.run()

Slide 29

Slide 29 text

import HTTPServer let log = LogMiddleware() let router = BasicRouter { route in route.get("/hello") { request in return Response(body: "Hello, world!") } } let server = try Server(port: 8080, middleware: [log], responder: router) try server.start()

Slide 30

Slide 30 text

Basic Stuff !

Slide 31

Slide 31 text

user auth • log a user in; • keep a user logged in; • log out; • access an user.

Slide 32

Slide 32 text

user auth

Slide 33

Slide 33 text

raw database support database interfaces for Swift.

Slide 34

Slide 34 text

raw database support DB/FW Perfect Vapor Kitura Zewo MySQL ✔ ✔ ✔ ✔ PostgreSQL ✔ ✔ ✔ ✔ MongoDB ✔ ✔ ✔ ✔ Redis ✔ ✔ ✔ ✔ RethinkDB ✔ ✔ ✔ ✔ Cassandra ✔ CouchDB ✔

Slide 35

Slide 35 text

Object- Relational Mapping • models, relationships, and querying; • spares you from writing custom SQL.

Slide 36

Slide 36 text

Object- Relational Mapping Framework Perfect Vapor Kitura Zewo ✔ ✔

Slide 37

Slide 37 text

Routing • interpret visitor input URLs; • parse them; • retrieve parameters.

Slide 38

Slide 38 text

Routing Framework Perfect Vapor Kitura Zewo ✔ ✔ ✔ ✔

Slide 39

Slide 39 text

Sessions allow associating stageful information with individual visitors.

Slide 40

Slide 40 text

Sessions Framework Perfect Vapor Kitura Zewo ✔ ✔ ✔ ✔

Slide 41

Slide 41 text

Templating • syntax for searching & replacing placeholders in markup; • conditionals/loops etc.; • "Mustache"

Slide 42

Slide 42 text

Framework Perfect Vapor Kitura Zewo ✔ ✔ ✔ ✔ Templating

Slide 43

Slide 43 text

WebSockets • full-Duplex communication channels over TCP; • real-time data transfer (client/ server)

Slide 44

Slide 44 text

Framework Perfect Vapor Kitura Zewo ✔ ✔ ✔ WebSockets

Slide 45

Slide 45 text

Deploying putting things into action!

Slide 46

Slide 46 text

Deploying Method/FW Perfect Vapor Kitura Zewo Heroku ✔ ✔ ✔ ✔ Docker ✔ ✔ ✔ ✔ AWS ✔ ✔ ✔ ✔ BlueMix ✔ ✔ Digital Ocean ✔ ✔ ✔ ✔

Slide 47

Slide 47 text

Version Manager a tool that helps manage different versions of the language that you are using.

Slide 48

Slide 48 text

Version Manager

Slide 49

Slide 49 text

Version Manager $ brew install kylef/formulae/swiftenv $ echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.bash_profile $ echo 'export PATH="$SWIFTENV_ROOT/bin: $PATH"' >> ~/.bash_profile $ echo 'eval "$(swiftenv init -)"' >> ~/.bash_profile $ swiftenv install 3.0.0

Slide 50

Slide 50 text

Version Manager $ brew install kylef/formulae/swiftenv $ echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.bash_profile $ echo 'export PATH="$SWIFTENV_ROOT/bin: $PATH"' >> ~/.bash_profile $ echo 'eval "$(swiftenv init -)"' >> ~/.bash_profile $ swiftenv install 3.0.0  Install

Slide 51

Slide 51 text

Version Manager $ brew install kylef/formulae/swiftenv $ echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.bash_profile $ echo 'export PATH="$SWIFTENV_ROOT/bin: $PATH"' >> ~/.bash_profile $ echo 'eval "$(swiftenv init -)"' >> ~/.bash_profile $ swiftenv install 3.0.0 Setup shims/ completions

Slide 52

Slide 52 text

$ brew install kylef/formulae/swiftenv $ echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.bash_profile $ echo 'export PATH="$SWIFTENV_ROOT/bin: $PATH"' >> ~/.bash_profile $ echo 'eval "$(swiftenv init -)"' >> ~/.bash_profile $ swiftenv install 3.0.0 Version Manager  Use

Slide 53

Slide 53 text

Package Manager a tool that helps manage different versions of the libraries that you are using.

Slide 54

Slide 54 text

Package Manager

Slide 55

Slide 55 text

import PackageDescription let package = Package( name: "MyPackage", dependencies: [ .Package(url: "https://github.com/me/ package.git", majorVersion: 3), ] ) Package Manager

Slide 56

Slide 56 text

Package Manager import PackageDescription let package = Package( name: "MyPackage", dependencies: [ .Package(url: "https://github.com/me/ package.git", majorVersion: 3), ] )  Project Metadata

Slide 57

Slide 57 text

Other Stuff • File System • Compression • Encryption / Cryptography • Logging • Command Line Access • Push Notifications • Networking • Parsers (XML/JSON) • …

Slide 58

Slide 58 text

https://github.com/Awesome- Server-Side-Swift/TheList Other Stuff

Slide 59

Slide 59 text

Goin’ Deeper !

Slide 60

Slide 60 text

Communicating Sequential Processes • concurrently executing entities; • communicating by sending “messages” to each other.

Slide 61

Slide 61 text

Communicating Sequential Processes • provides two concurrency primitives namely coroutines and channels • allow concurrent programming in the style of Golang.

Slide 62

Slide 62 text

Communicating Sequential Processes: Channels • a thread-safe queue; • any entity can add messages or retrieve messages from a channel without worrying about interference; • by default, a channel is synchronous.

Slide 63

Slide 63 text

Communicating Sequential Processes: Coroutines • a procedure executing concurrently with other coroutines; • a coroutine may send messages to and receive messages from channels;

Slide 64

Slide 64 text

Communicating Sequential Processes • you might get “some” parallelism with this approach–but not a lot; • if channel is not ready a coroutine waits by giving way to other coroutines

Slide 65

Slide 65 text

Communicating Sequential Processes a single thread can “multiplex” thousands of routines and ensure that “logically concurrent entities” are making progress

Slide 66

Slide 66 text

https://github.com/Zewo/ Venice Communicating Sequential Processes: Venice

Slide 67

Slide 67 text

Communicating Sequential Processes: Venice func doSomething() { print("did something") } doSomething() co(doSomething()) co { print("did something else") }

Slide 68

Slide 68 text

Communicating Sequential Processes: Venice func doSomething() { print("did something") } doSomething() co(doSomething()) co { print("did something else") }  Sample Function

Slide 69

Slide 69 text

Communicating Sequential Processes: Venice func doSomething() { print("did something") } doSomething() co(doSomething()) co { print("did something else") }  Regular Call

Slide 70

Slide 70 text

Communicating Sequential Processes: Venice func doSomething() { print("did something") } doSomething() co(doSomething()) co { print("did something else") }  Coroutine Call

Slide 71

Slide 71 text

Communicating Sequential Processes: Venice func doSomething() { print("did something") } doSomething() co(doSomething()) co { print("did something else") } Coroutine Closure

Slide 72

Slide 72 text

Communicating Sequential Processes: Venice let messages = Channel() co(messages.send(“Hello, CocoaHeads")) let message = messages.receive()! print(message)

Slide 73

Slide 73 text

Communicating Sequential Processes: Venice let messages = Channel() co(messages.send(“Hello, CocoaHeads")) let message = messages.receive()! print(message) Creating a Channel

Slide 74

Slide 74 text

Communicating Sequential Processes: Venice let messages = Channel() co(messages.send(“Hello, CocoaHeads")) let message = messages.receive()! print(message) Sending a Message

Slide 75

Slide 75 text

Communicating Sequential Processes: Venice let messages = Channel() co(messages.send(“Hello, CocoaHeads")) let message = messages.receive()! print(message) Receiving a Message

Slide 76

Slide 76 text

Communicating Sequential Processes • Apple, • Cloudflare, • Google, • Sendgrid, • Dropbox, • Soundcloud, • Bitly, • Digitalocean, • Twitter

Slide 77

Slide 77 text

Communicating Sequential Processes https://github.com/golang/go/ wiki/GoUsers

Slide 78

Slide 78 text

Functions as a Service / Serverless Architecture • functions as a unit of application logic; • development focus on well defined units of business logic.

Slide 79

Slide 79 text

• without decisions related to how this logic is deployed or scaled; • frees the developer from deployment concerns. Functions as a Service / Serverless Architecture

Slide 80

Slide 80 text

• running back-end code without managing your own server systems or applications; • deployment is very different to traditional systems; • horizontal scaling is completely automatic. Functions as a Service / Serverless Architecture

Slide 81

Slide 81 text

• Amazon AWS Lambda; • Google Cloud Functions; • Windows Azure Functions; • Auth0 Webtasks. Functions as a Service / Serverless Architecture

Slide 82

Slide 82 text

https://github.com/algal/ SwiftOnLambda Functions as a Service / Serverless Architecture

Slide 83

Slide 83 text

“people have been doing "BIG-BOY" EXPERIMENTS with FULL-STACK SWIFT.”

Slide 84

Slide 84 text

https://medium.com/@qutheory/server-side-swift-vs-the-other-guys-2- speed-ca65b2f79505#.4184w43vy

Slide 85

Slide 85 text

https://medium.com/@qutheory/server-side-swift-vs-the-other-guys-2- speed-ca65b2f79505#.4184w43vy

Slide 86

Slide 86 text

https://medium.com/@qutheory/server-side-swift-vs-the-other-guys-2- speed-ca65b2f79505#.4184w43vy

Slide 87

Slide 87 text

https://medium.com/@rymcol/benchmarks-for-the-top-server-side-swift- frameworks-vs-node-js-24460cfe0beb#.ze0k1uuda

Slide 88

Slide 88 text

https://medium.com/@rymcol/benchmarks-for-the-top-server-side-swift- frameworks-vs-node-js-24460cfe0beb#.ze0k1uuda

Slide 89

Slide 89 text

https://medium.com/@rymcol/benchmarks-for-the-top-server-side-swift- frameworks-vs-node-js-24460cfe0beb#.ze0k1uuda

Slide 90

Slide 90 text

https://medium.com/@rymcol/benchmarks-for-the-top-server-side-swift- frameworks-vs-node-js-24460cfe0beb#.ze0k1uuda

Slide 91

Slide 91 text

https://swiftybeaver.com/

Slide 92

Slide 92 text

• Vapor 1.18 • Swift 3.0.1 • Ubuntu 16.04 • AWS EC2 cloud instances • AWS ELB https://medium.com/swiftybeaver- blog/deployment-of-a-vapor-app- to-aws-ec2-f577eaa6c38c#.j5nflt5tv

Slide 93

Slide 93 text

https://swiftybeaver.com/ ~20K req/sec

Slide 94

Slide 94 text

front- end 

Slide 95

Slide 95 text

Swift to JavaScript Compiler https://github.com/shift-js/shift-js

Slide 96

Slide 96 text

func greet(person:String, event:String) -> String { return "Hello \(person). Welcome to \(event)!" } greet("Augusto", event: "CocoaHeads") Swift to JavaScript Compiler  function greet(person, event) { return 'Hello ' + person + '. Welcome to ' + event + '!'; } greet('Augusto', 'CocoaHeads');

Slide 97

Slide 97 text

• Basic Declarations and Assignment; • Basic Operators; • Arrays and Dictionaries; • Control Flow; • Functions; • String Interpolation and Concatenation Swift to JavaScript Compiler

Slide 98

Slide 98 text

Swift to TypeScript Compiler https://github.com/ marcelganczak/swift-js-transpiler

Slide 99

Slide 99 text

let array: [String] = ["CocoaHeads", "is", "top"] print(array.count) print(array[0].characters.count) Swift to TypeScript Compiler const array:Array = [ "CocoaHeads" , "is" , “top!" ]; console.log(array.length); console.log(array[0].length); 

Slide 100

Slide 100 text

• data types (primitives, tuples, arrays, dictionaries, sets) • control flow (if, for- in, while) • optionals & chaining • functions & closures Swift to TypeScript Compiler

Slide 101

Slide 101 text

mobile "

Slide 102

Slide 102 text

Swift to Android Target Compiler

Slide 103

Slide 103 text

No content

Slide 104

Slide 104 text

https://github.com/apple/swift-evolution

Slide 105

Slide 105 text

https://github.com/apple/swift/blob/master/docs/Android.md

Slide 106

Slide 106 text

https://swift.org/server-apis/

Slide 107

Slide 107 text

https://swift.org/server-apis/

Slide 108

Slide 108 text

https://swift.org/server-apis/

Slide 109

Slide 109 text

slides available at: BIT.LY/SERVER-SIDE-SWIFT- COCOAHEADS

Slide 110

Slide 110 text

thanks! ythecombinator gitbub.com/ twitter.com/ instagram.com gotinder.com/@