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

The future favors Swift

97d21da8e0ffa8f81218a293482c253a?s=47 Matheus
February 21, 2017

The future favors Swift

let description: String = "Há alguns anos atrás, muito se ouvia coisas como 'Quem é esse tal de JavaScript que tem atraído todos os devs para seu universo pluralista e multiplataforma?' ou ainda 'Se você sabe JavaScript, você pode ir onde quiser!'. Então, vimos uma linguagem, originalmente proposta para uma única plataforma, tomar conta dos navegadores, servidores, mobile, sistemas embarcados e muito mais!"

let theFuture: String = description.replacingOccurrences(of: "JavaScript", with: "Swift")

97d21da8e0ffa8f81218a293482c253a?s=128

Matheus

February 21, 2017
Tweet

Transcript

  1. let title: String = “The Future Favors Swift” // @ythecombinator

    // #cocoaheads
  2.  @ythecombinator  #BEPiD DEV I/O, NUG, COCOAHEADS, ANDROID MEETUP,

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

    IONIC MEETUP, LAMBDA I/O…  ☕  #after 
  4. !!!

  5. this talk is much of a very opinionated conversation.

  6. None
  7. None
  8. None
  9. None
  10. None
  11. “in a VERY NEAR FUTURE, Swift will be in the

    same "FULL-STACK LANGUAGE STATE" JavaScript is in.” - ythecombinator
  12. https://nodesource.com/node-by-numbers

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

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

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

  16. None
  17. •Optionals & Generics • Protocols & Extensions • Pattern Matching

    • ARC • Good Error Handling • "Safety" by design • Common Functional Programming Constructs
  18. http://githut.info/

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

  20. None
  21. Swift

  22. ! " #  %

  23. server- side !

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

  26. import Vapor let drop = Droplet() drop.get("/hello") { _ in

    return "Hello Vapor" } drop.run()
  27. import Kitura let router = Router() router.get("/") { request, response,

    next in response.send("Hello, World!") next() } Kitura.addHTTPServer(onPort: 8090, with: router) Kitura.run()
  28. 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()
  29. Basic Stuff !

  30. user auth • log a user in; • keep a

    user logged in; • log out; • access an user.
  31. user auth

  32. raw database support database interfaces for Swift.

  33. raw database support DB/FW Perfect Vapor Kitura Zewo MySQL ✔

    ✔ ✔ ✔ PostgreSQL ✔ ✔ ✔ ✔ MongoDB ✔ ✔ ✔ ✔ Redis ✔ ✔ ✔ ✔ RethinkDB ✔ ✔ ✔ ✔ Cassandra ✔ CouchDB ✔
  34. Object- Relational Mapping • models, relationships, and querying; • spares

    you from writing custom SQL.
  35. Object- Relational Mapping Framework Perfect Vapor Kitura Zewo ✔ ✔

  36. Routing • interpret visitor input URLs; • parse them; •

    retrieve parameters.
  37. Routing Framework Perfect Vapor Kitura Zewo ✔ ✔ ✔ ✔

  38. Sessions allow associating stageful information with individual visitors.

  39. Sessions Framework Perfect Vapor Kitura Zewo ✔ ✔ ✔ ✔

  40. Templating • syntax for searching & replacing placeholders in markup;

    • conditionals/loops etc.; • "Mustache"
  41. Framework Perfect Vapor Kitura Zewo ✔ ✔ ✔ ✔ Templating

  42. WebSockets • full-Duplex communication channels over TCP; • real-time data

    transfer (client/ server)
  43. Framework Perfect Vapor Kitura Zewo ✔ ✔ ✔ WebSockets

  44. Deploying putting things into action!

  45. Deploying Method/FW Perfect Vapor Kitura Zewo Heroku ✔ ✔ ✔

    ✔ Docker ✔ ✔ ✔ ✔ AWS ✔ ✔ ✔ ✔ BlueMix ✔ ✔ Digital Ocean ✔ ✔ ✔ ✔
  46. Version Manager a tool that helps manage different versions of

    the language that you are using.
  47. Version Manager

  48. 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
  49. 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
  50. 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
  51. $ 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
  52. Package Manager a tool that helps manage different versions of

    the libraries that you are using.
  53. Package Manager

  54. import PackageDescription let package = Package( name: "MyPackage", dependencies: [

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

    dependencies: [ .Package(url: "https://github.com/me/ package.git", majorVersion: 3), ] )  Project Metadata
  56. Other Stuff • File System • Compression • Encryption /

    Cryptography • Logging • Command Line Access • Push Notifications • Networking • Parsers (XML/JSON) • …
  57. https://github.com/Awesome- Server-Side-Swift/TheList Other Stuff

  58. Goin’ Deeper !

  59. Communicating Sequential Processes • concurrently executing entities; • communicating by

    sending “messages” to each other.
  60. Communicating Sequential Processes • provides two concurrency primitives namely coroutines

    and channels • allow concurrent programming in the style of Golang.
  61. 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.
  62. Communicating Sequential Processes: Coroutines • a procedure executing concurrently with

    other coroutines; • a coroutine may send messages to and receive messages from channels;
  63. 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
  64. Communicating Sequential Processes a single thread can “multiplex” thousands of

    routines and ensure that “logically concurrent entities” are making progress
  65. https://github.com/Zewo/ Venice Communicating Sequential Processes: Venice

  66. Communicating Sequential Processes: Venice func doSomething() { print("did something") }

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

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

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

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

    doSomething() co(doSomething()) co { print("did something else") } Coroutine Closure
  71. Communicating Sequential Processes: Venice let messages = Channel<String>() co(messages.send(“Hello, CocoaHeads"))

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

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

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

    let message = messages.receive()! print(message) Receiving a Message
  75. Communicating Sequential Processes • Apple, • Cloudflare, • Google, •

    Sendgrid, • Dropbox, • Soundcloud, • Bitly, • Digitalocean, • Twitter
  76. Communicating Sequential Processes https://github.com/golang/go/ wiki/GoUsers

  77. Functions as a Service / Serverless Architecture • functions as

    a unit of application logic; • development focus on well defined units of business logic.
  78. • without decisions related to how this logic is deployed

    or scaled; • frees the developer from deployment concerns. Functions as a Service / Serverless Architecture
  79. • 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
  80. • Amazon AWS Lambda; • Google Cloud Functions; • Windows

    Azure Functions; • Auth0 Webtasks. Functions as a Service / Serverless Architecture
  81. https://github.com/algal/ SwiftOnLambda Functions as a Service / Serverless Architecture

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

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

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

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

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

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

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

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

  90. https://swiftybeaver.com/

  91. • 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
  92. https://swiftybeaver.com/ ~20K req/sec

  93. front- end 

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

  95. 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');
  96. • Basic Declarations and Assignment; • Basic Operators; • Arrays

    and Dictionaries; • Control Flow; • Functions; • String Interpolation and Concatenation Swift to JavaScript Compiler
  97. Swift to TypeScript Compiler https://github.com/ marcelganczak/swift-js-transpiler

  98. let array: [String] = ["CocoaHeads", "is", "top"] print(array.count) print(array[0].characters.count) Swift

    to TypeScript Compiler const array:Array<string> = [ "CocoaHeads" , "is" , “top!" ]; console.log(array.length); console.log(array[0].length); 
  99. • data types (primitives, tuples, arrays, dictionaries, sets) • control

    flow (if, for- in, while) • optionals & chaining • functions & closures Swift to TypeScript Compiler
  100. mobile "

  101. Swift to Android Target Compiler

  102. None
  103. https://github.com/apple/swift-evolution

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

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

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

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

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

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