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

The future favors Swift

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")

Matheus Albuquerque

February 21, 2017
Tweet

More Decks by Matheus Albuquerque

Other Decks in Programming

Transcript

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

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

  3. “in a VERY NEAR FUTURE, Swift will be in the

    same "FULL-STACK LANGUAGE STATE" JavaScript is in.” - ythecombinator
  4. •Optionals & Generics • Protocols & Extensions • Pattern Matching

    • ARC • Good Error Handling • "Safety" by design • Common Functional Programming Constructs
  5. import Kitura let router = Router() router.get("/") { request, response,

    next in response.send("Hello, World!") next() } Kitura.addHTTPServer(onPort: 8090, with: router) Kitura.run()
  6. 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()
  7. user auth • log a user in; • keep a

    user logged in; • log out; • access an user.
  8. raw database support DB/FW Perfect Vapor Kitura Zewo MySQL ✔

    ✔ ✔ ✔ PostgreSQL ✔ ✔ ✔ ✔ MongoDB ✔ ✔ ✔ ✔ Redis ✔ ✔ ✔ ✔ RethinkDB ✔ ✔ ✔ ✔ Cassandra ✔ CouchDB ✔
  9. Deploying Method/FW Perfect Vapor Kitura Zewo Heroku ✔ ✔ ✔

    ✔ Docker ✔ ✔ ✔ ✔ AWS ✔ ✔ ✔ ✔ BlueMix ✔ ✔ Digital Ocean ✔ ✔ ✔ ✔
  10. 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
  11. 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
  12. 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
  13. $ 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
  14. import PackageDescription let package = Package( name: "MyPackage", dependencies: [

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

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

    Cryptography • Logging • Command Line Access • Push Notifications • Networking • Parsers (XML/JSON) • …
  17. Communicating Sequential Processes • provides two concurrency primitives namely coroutines

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

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

    routines and ensure that “logically concurrent entities” are making progress
  22. Communicating Sequential Processes: Venice func doSomething() { print("did something") }

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

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

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

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

    doSomething() co(doSomething()) co { print("did something else") } Coroutine Closure
  27. Communicating Sequential Processes • Apple, • Cloudflare, • Google, •

    Sendgrid, • Dropbox, • Soundcloud, • Bitly, • Digitalocean, • Twitter
  28. Functions as a Service / Serverless Architecture • functions as

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

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

    Azure Functions; • Auth0 Webtasks. Functions as a Service / Serverless Architecture
  32. • 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
  33. 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');
  34. • Basic Declarations and Assignment; • Basic Operators; • Arrays

    and Dictionaries; • Control Flow; • Functions; • String Interpolation and Concatenation Swift to JavaScript Compiler
  35. 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); 
  36. • data types (primitives, tuples, arrays, dictionaries, sets) • control

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