Slide 1

Slide 1 text

1 Swift and Linux Now and the future Ian Partridge IBM Runtimes Technologies, IBM Cloud 26th July 2016

Slide 2

Slide 2 text

2 Ian Partridge • Senior developer in Swift@IBM • Background in runtime systems • Java garbage collection • Runtime performance analysis • Full-stack debugging • Swift@IBM, bringing Swift to the cloud on Linux @ianpartridge @alfa

Slide 3

Slide 3 text

Agenda • Swift • History • Why Swift? • Swift on Linux • Current status • Kitura web framework • Cloud-ready out of the box 3

Slide 4

Slide 4 text

Timeline Date Event 2010? Works begins inside Apple June 2014 (WWDC) 1.0-beta September 2014 1.0 June 2015 (WWDC) 2.0-beta September 2015 2.0 December 2015 Swift open-sourced on GitHub June 2016 (WWDC) 3.0-techpreview1 3Q 2016? 3.0 4

Slide 5

Slide 5 text

Open Source Swift 5 www.swift.org www.github.com/apple/swift • Apache v2 licence • Ubuntu packages available

Slide 6

Slide 6 text

Rapid growth in popularity 6 Q3 2014 Q1 2016

Slide 7

Slide 7 text

Safe • Type safe, but with inference • Definitive initialization of local variables • Immutability as a core language feature • No implicit type conversions • Objects cannot be null 7

Slide 8

Slide 8 text

Expressive • Syntax inspired by C family • Plus modern features from scripting languages • Generics • Closures • Tuples • map() + filter() + reduce() 8

Slide 9

Slide 9 text

Fast • Belongs to the C family of compiled native languages • Built on LLVM optimizing compiler • ARC provides memory management without GC pauses • Standard library providing collections using COW 9

Slide 10

Slide 10 text

Swift Performance 1 0

Slide 11

Slide 11 text

Swift Memory Usage 1 1

Slide 12

Slide 12 text

Swift Performance by Memory 1 2

Slide 13

Slide 13 text

IBM Swift Sandbox • Interactive sandbox for exploring Swift • Saves your work • Supports multiple versions of Swift • Deploys your Swift code in a Linux Docker container 13 https://swiftlang.ng.bluemix.net/

Slide 14

Slide 14 text

Swift on Linux – Compiler and debugger 14 • Scripts for easily building your own compiler • Or go to swift.org/download

Slide 15

Slide 15 text

Swift on Linux – Foundation (class libraries) 15 • Work in progress • Contributions welcome!

Slide 16

Slide 16 text

Swift on Linux – Concurrency with libdispatch 16 • Nearly there!

Slide 17

Slide 17 text

Kitura Web Framework What is it? New, modular, package-based web framework written in Swift Why is this cool? Empower a new generation of native mobile developers to write and deploy code into the cloud on Linux. Developer Benefits ? Delivers core technologies needed to stand up enterprise apps on the server Enables developers to create a web application in Swift and deploy these servers on Linux and the cloud. http://github.com/ibm-swift/kitura 17

Slide 18

Slide 18 text

Isomorphic Swift Code 1 8 Create Swift Module Generate Swift Client APIs Kitura Linux Server Project Swagger REST API Deploy Deploy • Same module on client and server • Local or remote API calls • Automatically created Swagger APIs

Slide 19

Slide 19 text

Developing a Kitura web application on Linux 19 myProject ├── Package.swift ├── Sources │ └── main.swift └── Tests $ mkdir myProject 2. Next, initialize this project as a new Swift package 1. First, we create a new project directory $ cd myProject $ swift package init Basic Swift package directory structure:

Slide 20

Slide 20 text

Developing a Kitura web application on Linux 20 import PackageDescription let package = Package( name: "myProject", dependencies: [ .Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 0, minor: 22) ] ) 3. Add Kitura as a dependency for your project (Package.swift):

Slide 21

Slide 21 text

Developing a Kitura web application on Linux 21 Kitura.addHTTPServer(onPort: 8090, with: router) Kitura.run() let router = Router() router.get("/hello") { request, response, next in response.status(.OK).send("

Hello, World!

").end() } 6. Create and start an HTTPServer: 4. Add a router and a path: router.get("/hello.json") { request, response, next in response.status(.OK).send(json: JSON(["Hello": "World!"])).end() } 5. Add a JSON data route

Slide 22

Slide 22 text

Developing a Kitura web application on Linux 22 import Kitura let router = Router() router.get("/hello") { request, response, next in response.status(.OK).send("

Hello, World!

").end() } router.get("/hello.json") { request, response, next in response.status(.OK).send(json: JSON(["Hello": "World!"])).end() } Kitura.addHTTPServer(onPort: 8090, with: router) Kitura.run() 7. Sources/main.swift should now look like this:

Slide 23

Slide 23 text

Developing a Kitura web application on Linux 23 $ swift build -Xcc –fblocks 8. Compile: $ .build/debug/myFirstProject & 9. Run: 10. Open your browser: http://localhost:8090/hello http://localhost:8090/ http://localhost:8090/hello.json

Slide 24

Slide 24 text

Get started quickly with Kitura • http://github.com/IBM-Swift/Kitura-Sample • `make run` • http://github.com/IBM-Swift/Kitura-Starter-Bluemix • `cf push` • http://github.com/IBM-Swift/swift-watson-sdk 24

Slide 25

Slide 25 text

The future of Swift on Linux • Completing the implementation of Foundation and libdispatch • Building a vibrant Swift on Linux community • Server-side packages in the rapidly-growing SPM ecosystem • IDE support • Cloud integration • Exploring the Swift “sweet-spot” • Linux-driven enhancements to Swift itself? 25

Slide 26

Slide 26 text

Find out more 26 https://developer.ibm.com/swift/ The Swift@IBM devCenter Join IBM Swift Engineering and learn the latest news