Introducing Swift - and the Sunset of Our Culture?

42
Introducing Swift - and the Sunset of Our Culture @dankogai 1

description

Apple recently released a language called Swift. As a language it appears to be the best of both worlds -- a script language that emits native codes. But I've got a feeling it means more than just a language. The talk roughly consists of 4 parts as follows: * Introducing Swift * Script Languages vs "Compiler" Languages * Free Software vs. Open Source * The Sunset of Our Culture

Transcript of Introducing Swift - and the Sunset of Our Culture?

Page 1: Introducing Swift - and the Sunset of Our Culture?

Introducing Swift - and the Sunset of Our

Culture@dankogai

1

Page 2: Introducing Swift - and the Sunset of Our Culture?

Introducing Swift - and the Sunset of Our

Culture?

2

Page 3: Introducing Swift - and the Sunset of Our Culture?

Introducing Swift

3

Page 4: Introducing Swift - and the Sunset of Our Culture?
Page 5: Introducing Swift - and the Sunset of Our Culture?

5

https://developer.apple.com/swift/

Page 6: Introducing Swift - and the Sunset of Our Culture?

Hello, world!use v5.16; say "Hello, world!";

6

Page 7: Introducing Swift - and the Sunset of Our Culture?

Hello, world!println("Hello,  world!")  //  no  main()  required  

7

Page 8: Introducing Swift - and the Sunset of Our Culture?

FizzBuzz#!/usr/bin/env perl -l print+(Fizz)[$_%3].(Buzz)[$_%5]||$_ for 1..100 !# http://developer.cybozu.co.jp/takesako/2007/05/fizzbuzz.html

8

Page 9: Introducing Swift - and the Sunset of Our Culture?

FizzBuzzprintln(1) println(2) println("Fizz") println(4) println("Buzz") println("Fizz") println(7) println(8) println("Fizz") println("Buzz") println(11) println("Fizz") println(13) println(14) println("FizzBuzz") println(16) println(17) println("Fizz") println(19) println("Buzz") println("Fizz") println(22) println(23) println("Fizz") println("Buzz") println(26) println("Fizz") println(28) println(29) println("FizzBuzz") println(31) println(32) println("Fizz") println(34) println("Buzz") println("Fizz") println(37) println(38) println("Fizz") println("Buzz") println(41) println("Fizz") println(43) println(44) println("FizzBuzz") println(46) println(47) println("Fizz") println(49) println("Buzz") println("Fizz") println(52) println(53) println("Fizz") println("Buzz") println(56) println("Fizz") println(58) println(59) println("FizzBuzz")

9

Page 10: Introducing Swift - and the Sunset of Our Culture?

FizzBuzz - Lowest IQprintln(1) println(2) println("Fizz") println(4) println("Buzz") println("Fizz") println(7) println(8) println("Fizz") println("Buzz") println(11) println("Fizz") println(13) println(14) println("FizzBuzz") // cf. https://twitter.com/dankogai/status/494976616796127232

10

Page 11: Introducing Swift - and the Sunset of Our Culture?

FizzBuzzfor n in 1...100 { let f = n % 3 == 0 ? "Fizz" : "" let b = n % 5 == 0 ? "Buzz" : "" let fb = f + b; println(fb.isEmpty ? "\(n)" : fb) }

11

Page 12: Introducing Swift - and the Sunset of Our Culture?

FizzBuzz - funcfunc fizzbuzz(n:Int) -> String { let f = n % 3 == 0 ? "Fizz" : "" let b = n % 5 == 0 ? "Buzz" : "" let fb = f + b; return fb.isEmpty ? String(n) : fb } for n in 1...100 { println(fizzbuzz(n)) }

12

Page 13: Introducing Swift - and the Sunset of Our Culture?

FizzBuzz - methodextension Int { func fizzbuzz() -> String { let f = self % 3 == 0 ? "Fizz" : "" let b = self % 5 == 0 ? "Buzz" : "" let fb = f + b; return fb.isEmpty ? String(self) : fb } } for n in 1...100 { println(n.fizzbuzz()) }

13

Page 14: Introducing Swift - and the Sunset of Our Culture?

FizzBuzz - getterextension Int { var fizzbuzz:String { let f = self % 3 == 0 ? "Fizz" : "" let b = self % 5 == 0 ? "Buzz" : "" let fb = f + b; return fb.isEmpty ? String(self) : fb } } for n in 1...100 { println(n.fizzbuzz) }

14

Page 15: Introducing Swift - and the Sunset of Our Culture?

FizzBuzz - subscriptclass FizzBuzz { subscript (n:Int)->String { let f = n % 3 == 0 ? "Fizz" : "" let b = n % 5 == 0 ? "Buzz" : "" let fb = f + b; return fb.isEmpty ? String(n) : fb } } let fizzbuzz = FizzBuzz() for n in 1...100 { println(fizzbuzz[n]) }

15

Page 16: Introducing Swift - and the Sunset of Our Culture?

FizzBuzz - generatorextension FizzBuzz : SequenceType { func generate() -> GeneratorOf<String> { var n = 0 return GeneratorOf<String> { if n == 100 { return nil } return self[++n] } } } let fizzbuzz = FizzBuzz() for s in fizzbuzz { println(s) }

16

Page 17: Introducing Swift - and the Sunset of Our Culture?

FizzBuzz - optionallet fizzbuzz = [ 3:"Fizz",5:"Buzz",6:"Fizz",9:"Fizz", 10:"Buzz",12:"Fizz",0:"FizzBuzz" ] for n in 1...100 { println(fizzbuzz[n % 15] ?? "\(n)") }

17

Page 18: Introducing Swift - and the Sunset of Our Culture?

FizzBuzz - functionallylet fizzbuzz = [ 3:"Fizz",5:"Buzz",6:"Fizz",9:"Fizz", 10:"Buzz",12:"Fizz",0:"FizzBuzz" ] Array(1...100) .map { fizzbuzz[$0 % 15] ?? "\($0)" } .map { println($0) }

18

Page 19: Introducing Swift - and the Sunset of Our Culture?

FizzBuzz - operatorinfix operator => { associativity left precedence 95 } func => <A,R> (lhs:A, rhs:A->R)->R { return rhs(lhs) } let fizzbuzz = [ 3:"Fizz",5:"Buzz",6:"Fizz",9:"Fizz", 10:"Buzz",12:"Fizz",0:"FizzBuzz" ] Array(1...100).map { fizzbuzz[n % 15] ?? "\(n)" => println }

19

Page 20: Introducing Swift - and the Sunset of Our Culture?

Demo

Page 21: Introducing Swift - and the Sunset of Our Culture?

let Swift =Of course, it also greatly benefited from the experiences hard-won by many other languages in the field, drawing ideas from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list. - Chris Lattner

Page 22: Introducing Swift - and the Sunset of Our Culture?

IMHO, it looks more like Perl6 than any other!

let Swift =

Page 23: Introducing Swift - and the Sunset of Our Culture?

let Swift = what.perl6.was.supposed

.to.be!

Page 24: Introducing Swift - and the Sunset of Our Culture?

Script Languages vs "Compiler" Languages

24

Page 25: Introducing Swift - and the Sunset of Our Culture?

http://www.perl6.org/archive/talks/2000/als/talk.html25

Page 26: Introducing Swift - and the Sunset of Our Culture?

Write Run Type Languages

Compiled Harder Faster Static C, C++, Java

Scripted Easier Slower Dynamic Perl, Ruby, Python,JS

26

Page 27: Introducing Swift - and the Sunset of Our Culture?

Write Run Type Languages

Compiled Harder Faster Static C, C++, Java

Ideal? Easier FasterStatic + !

Type Inference

Swift?

Scripted Easier Slower Dynamic Perl, Ruby, Python,JS

27

Page 28: Introducing Swift - and the Sunset of Our Culture?

The Sunset of Our Culture?

28

Page 29: Introducing Swift - and the Sunset of Our Culture?

29http://danielvdende.com/gdc2014/

Page 30: Introducing Swift - and the Sunset of Our Culture?

30http://danielvdende.com/gdc2014/

Page 31: Introducing Swift - and the Sunset of Our Culture?

Bottom-up languages are "discovered"

• Perl for those C is too hard • Perl for those awk is too limited • PHP for those who considers perl too hard • Python for those who considers perl too easy • Ruby for those who cosiders -> too much

31

Page 32: Introducing Swift - and the Sunset of Our Culture?

Top-down languages are "delivered"

• Java by Sun -> Oracle • JS by Netscape -> MS -> Google and Apple • Dart and Go by Google • Swift by Apple

32

Page 33: Introducing Swift - and the Sunset of Our Culture?

How Apple Delivers Their Products

• Release a few good products • Microsoft: C#, F#, Silverlight, TypeScript… • Google: Dart and go • Facebook: Hack? What the Heck? • Apple: Swift

• Among a few good products, languages are the fewest • Only two since 1984 - HyperTalk, AppleScript (I

know Dylan but only its name)

33

Page 34: Introducing Swift - and the Sunset of Our Culture?

How Apple Delivers Their Products

• "Innovation is not about creating something extraordinary today: it is about making something ordinary tomorrow" — @chibicode

• "We’d be lucky if we sold 10 million iPhones" — steve Jobs • More iPhones are sold in a month these days

34

Page 35: Introducing Swift - and the Sunset of Our Culture?

How Apple Delivers Their Products

• "Swift is an innovative new programming language for Cocoa and Cocoa Touch." • Then why "lldb -repl" invokes Swift? • I coundn’t find anything special to Cocoa and

Cocoa Touch in Swift.

35

Page 36: Introducing Swift - and the Sunset of Our Culture?

Swift is a general purpose language

36

Page 37: Introducing Swift - and the Sunset of Our Culture?

Swift is a general purpose language

• Emits native code. • UnsafePointer<()> • @asmname • Inherits libc and Foundation • rejects legacy syntax of (Objective-)?C • Will it achieve C++ and Java did not — replace

C? Time will tell…37

Page 38: Introducing Swift - and the Sunset of Our Culture?

Will Swift go OSS?• No promise. Just guesses. • clang is OSS

• lldb -repl • Swift itself is not platform-specific • Once OSS, you can never close it

• Android 3.X has set a very bad example

38

Page 39: Introducing Swift - and the Sunset of Our Culture?

Top-down >

Bottom-up?• Perl6 = Still Crazy After All These Years • Perl5: two years just to add subroutine signature • Swift: two weeks to change T[] to [T]

39

Page 40: Introducing Swift - and the Sunset of Our Culture?

A language for getting the jobs done

• But who gives you the job? • And if your job giver offer you a lanugage, who

can resist?

40

Page 41: Introducing Swift - and the Sunset of Our Culture?

There’s more than one language to do it

• OS X bundles more languages than any other OS • Perl is there to stay

• /usr/bin/perl -v # 5.18.2 as of Yosemite DP6 • Available even without Xcode!

• Among others • ruby 2.0.0, python 2.7.6, php 5.5.14…

• But mind the mindshare and mindshift

41

Page 42: Introducing Swift - and the Sunset of Our Culture?

that’s it (for now)for q in questions { q.answer() }

42