SlideShare une entreprise Scribd logo
1  sur  42
Télécharger pour lire hors ligne
Introducing Swift 
- and the Sunset of Our 
Culture 
@dankogai 
1
Introducing Swift 
- and the Sunset of Our 
Culture? 
2
Introducing Swift 
3
https://developer.apple.com/swift/ 
5
Hello, world! 
use v5.16; 
say "Hello, world!"; 
6
Hello, world! 
println("Hello, 
world!") 
// 
no 
main() 
required 
7
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
FizzBuzz 
println(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
FizzBuzz - Lowest IQ 
println(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
FizzBuzz 
for 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
FizzBuzz - func 
func 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
FizzBuzz - method 
extension 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
FizzBuzz - getter 
extension 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
FizzBuzz - subscript 
class 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
FizzBuzz - generator 
extension 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
FizzBuzz - optional 
let 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
FizzBuzz - functionally 
let 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
FizzBuzz - operator 
infix 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
Demo
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
let Swift = 
IMHO, it looks more like Perl6 than any other!
let Swift = 
what.perl6.was.supposed 
.to.be!
Script Languages vs 
"Compiler" Languages 
24
http://www.perl6.org/archive/talks/2000/als/talk.html 
25
Write Run Type Languages 
Compiled Harder Faster Static 
C, C++, 
Java 
Scripted Easier Slower Dynamic 
Perl, Ruby, 
Python,JS 
26
Write Run Type Languages 
Compiled Harder Faster Static 
C, C++, 
Java 
Ideal? Easier Faster 
Static + ! 
Type 
Inference 
Swift? 
Scripted Easier Slower Dynamic 
Perl, Ruby, 
Python,JS 
27
The Sunset of Our 
Culture? 
28
http://danielvdende.com/gdc2014/ 
29
http://danielvdende.com/gdc2014/ 
30
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
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
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
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
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
Swift is a general 
purpose language 
36
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
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
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
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
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
that’s it (for now) 
for q in questions { 
q.answer() 
} 
42

Contenu connexe

En vedette

JSON SQL Injection and the Lessons Learned
JSON SQL Injection and the Lessons LearnedJSON SQL Injection and the Lessons Learned
JSON SQL Injection and the Lessons LearnedKazuho Oku
 
UI/UX に影響の大きい watchOS 2 の新機能 3つ
UI/UX に影響の大きい watchOS 2 の新機能 3つUI/UX に影響の大きい watchOS 2 の新機能 3つ
UI/UX に影響の大きい watchOS 2 の新機能 3つShuichi Tsutsumi
 
Audio Unit Extensions 〜オーディオエフェクトのアプリ間共有〜
Audio Unit Extensions 〜オーディオエフェクトのアプリ間共有〜Audio Unit Extensions 〜オーディオエフェクトのアプリ間共有〜
Audio Unit Extensions 〜オーディオエフェクトのアプリ間共有〜Shuichi Tsutsumi
 
Practical Core Bluetooth in IoT & Wearable projects @ UIKonf 2016
Practical Core Bluetooth in IoT & Wearable projects @ UIKonf 2016Practical Core Bluetooth in IoT & Wearable projects @ UIKonf 2016
Practical Core Bluetooth in IoT & Wearable projects @ UIKonf 2016Shuichi Tsutsumi
 
watchOS 2 新機能の細かい話
watchOS 2 新機能の細かい話watchOS 2 新機能の細かい話
watchOS 2 新機能の細かい話Shuichi Tsutsumi
 
iOS 9 の新機能 Core Image 編
iOS 9 の新機能 Core Image 編iOS 9 の新機能 Core Image 編
iOS 9 の新機能 Core Image 編Shuichi Tsutsumi
 
おもしろく働くための「わらしべ長者方式」
おもしろく働くための「わらしべ長者方式」おもしろく働くための「わらしべ長者方式」
おもしろく働くための「わらしべ長者方式」Shuichi Tsutsumi
 
「スキルなし・実績なし」 32歳窓際エンジニアがシリコンバレーで働くようになるまで
「スキルなし・実績なし」 32歳窓際エンジニアがシリコンバレーで働くようになるまで「スキルなし・実績なし」 32歳窓際エンジニアがシリコンバレーで働くようになるまで
「スキルなし・実績なし」 32歳窓際エンジニアがシリコンバレーで働くようになるまでShuichi Tsutsumi
 

En vedette (9)

JSON SQL Injection and the Lessons Learned
JSON SQL Injection and the Lessons LearnedJSON SQL Injection and the Lessons Learned
JSON SQL Injection and the Lessons Learned
 
UI/UX に影響の大きい watchOS 2 の新機能 3つ
UI/UX に影響の大きい watchOS 2 の新機能 3つUI/UX に影響の大きい watchOS 2 の新機能 3つ
UI/UX に影響の大きい watchOS 2 の新機能 3つ
 
Audio Unit Extensions 〜オーディオエフェクトのアプリ間共有〜
Audio Unit Extensions 〜オーディオエフェクトのアプリ間共有〜Audio Unit Extensions 〜オーディオエフェクトのアプリ間共有〜
Audio Unit Extensions 〜オーディオエフェクトのアプリ間共有〜
 
Practical Core Bluetooth in IoT & Wearable projects @ UIKonf 2016
Practical Core Bluetooth in IoT & Wearable projects @ UIKonf 2016Practical Core Bluetooth in IoT & Wearable projects @ UIKonf 2016
Practical Core Bluetooth in IoT & Wearable projects @ UIKonf 2016
 
watchOS 2 新機能の細かい話
watchOS 2 新機能の細かい話watchOS 2 新機能の細かい話
watchOS 2 新機能の細かい話
 
iOS 9 の新機能 Core Image 編
iOS 9 の新機能 Core Image 編iOS 9 の新機能 Core Image 編
iOS 9 の新機能 Core Image 編
 
おもしろく働くための「わらしべ長者方式」
おもしろく働くための「わらしべ長者方式」おもしろく働くための「わらしべ長者方式」
おもしろく働くための「わらしべ長者方式」
 
Client-Side Deep Learning
Client-Side Deep LearningClient-Side Deep Learning
Client-Side Deep Learning
 
「スキルなし・実績なし」 32歳窓際エンジニアがシリコンバレーで働くようになるまで
「スキルなし・実績なし」 32歳窓際エンジニアがシリコンバレーで働くようになるまで「スキルなし・実績なし」 32歳窓際エンジニアがシリコンバレーで働くようになるまで
「スキルなし・実績なし」 32歳窓際エンジニアがシリコンバレーで働くようになるまで
 

Similaire à Introduction to Swift Programming Language and FizzBuzz Examples

Test Driven Development Workshop
Test Driven Development WorkshopTest Driven Development Workshop
Test Driven Development WorkshopKaren Sijbrandij
 
ATS language overview
ATS language overviewATS language overview
ATS language overviewKiwamu Okabe
 
Introduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIOIntroduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIOKris Findlay
 
Building Interpreters with PyPy
Building Interpreters with PyPyBuilding Interpreters with PyPy
Building Interpreters with PyPyDaniel Neuhäuser
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesGanesh Samarthyam
 
Intro to the raspberry pi board
Intro to the raspberry pi boardIntro to the raspberry pi board
Intro to the raspberry pi boardThierry Gayet
 
Learn Python 3 for absolute beginners
Learn Python 3 for absolute beginnersLearn Python 3 for absolute beginners
Learn Python 3 for absolute beginnersKingsleyAmankwa
 
Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!Fariz Darari
 
Python with a SWIG of c++
Python with a  SWIG of c++Python with a  SWIG of c++
Python with a SWIG of c++bobmcn
 
20th.陈晓鸣 百度海量日志分析架构及处理经验分享
20th.陈晓鸣 百度海量日志分析架构及处理经验分享20th.陈晓鸣 百度海量日志分析架构及处理经验分享
20th.陈晓鸣 百度海量日志分析架构及处理经验分享elevenma
 
Hamamatsu.swift @浜松IT合同勉強会
Hamamatsu.swift @浜松IT合同勉強会Hamamatsu.swift @浜松IT合同勉強会
Hamamatsu.swift @浜松IT合同勉強会Takuya Ogawa
 
An intro to programming
An intro to programmingAn intro to programming
An intro to programmingWolfFlight
 
Simple ETL in python 3.5+ with Bonobo, Romain Dorgueil
Simple ETL in python 3.5+ with Bonobo, Romain DorgueilSimple ETL in python 3.5+ with Bonobo, Romain Dorgueil
Simple ETL in python 3.5+ with Bonobo, Romain DorgueilPôle Systematic Paris-Region
 
Simple ETL in python 3.5+ with Bonobo - PyParis 2017
Simple ETL in python 3.5+ with Bonobo - PyParis 2017Simple ETL in python 3.5+ with Bonobo - PyParis 2017
Simple ETL in python 3.5+ with Bonobo - PyParis 2017Romain Dorgueil
 
Performance Comparison JVM Languages
Performance Comparison JVM LanguagesPerformance Comparison JVM Languages
Performance Comparison JVM LanguagesCorneil du Plessis
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonakaptur
 
FUNctional programming in Python
FUNctional programming in PythonFUNctional programming in Python
FUNctional programming in Pythonknifeofdreams
 
Linux: Beyond ls and cd
Linux: Beyond ls and cdLinux: Beyond ls and cd
Linux: Beyond ls and cdjacko91
 
The Fuzzing Project - 32C3
The Fuzzing Project - 32C3The Fuzzing Project - 32C3
The Fuzzing Project - 32C3hannob
 
FITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an endFITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an endThibault Imbert
 

Similaire à Introduction to Swift Programming Language and FizzBuzz Examples (20)

Test Driven Development Workshop
Test Driven Development WorkshopTest Driven Development Workshop
Test Driven Development Workshop
 
ATS language overview
ATS language overviewATS language overview
ATS language overview
 
Introduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIOIntroduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIO
 
Building Interpreters with PyPy
Building Interpreters with PyPyBuilding Interpreters with PyPy
Building Interpreters with PyPy
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java Bytecodes
 
Intro to the raspberry pi board
Intro to the raspberry pi boardIntro to the raspberry pi board
Intro to the raspberry pi board
 
Learn Python 3 for absolute beginners
Learn Python 3 for absolute beginnersLearn Python 3 for absolute beginners
Learn Python 3 for absolute beginners
 
Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!
 
Python with a SWIG of c++
Python with a  SWIG of c++Python with a  SWIG of c++
Python with a SWIG of c++
 
20th.陈晓鸣 百度海量日志分析架构及处理经验分享
20th.陈晓鸣 百度海量日志分析架构及处理经验分享20th.陈晓鸣 百度海量日志分析架构及处理经验分享
20th.陈晓鸣 百度海量日志分析架构及处理经验分享
 
Hamamatsu.swift @浜松IT合同勉強会
Hamamatsu.swift @浜松IT合同勉強会Hamamatsu.swift @浜松IT合同勉強会
Hamamatsu.swift @浜松IT合同勉強会
 
An intro to programming
An intro to programmingAn intro to programming
An intro to programming
 
Simple ETL in python 3.5+ with Bonobo, Romain Dorgueil
Simple ETL in python 3.5+ with Bonobo, Romain DorgueilSimple ETL in python 3.5+ with Bonobo, Romain Dorgueil
Simple ETL in python 3.5+ with Bonobo, Romain Dorgueil
 
Simple ETL in python 3.5+ with Bonobo - PyParis 2017
Simple ETL in python 3.5+ with Bonobo - PyParis 2017Simple ETL in python 3.5+ with Bonobo - PyParis 2017
Simple ETL in python 3.5+ with Bonobo - PyParis 2017
 
Performance Comparison JVM Languages
Performance Comparison JVM LanguagesPerformance Comparison JVM Languages
Performance Comparison JVM Languages
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
 
FUNctional programming in Python
FUNctional programming in PythonFUNctional programming in Python
FUNctional programming in Python
 
Linux: Beyond ls and cd
Linux: Beyond ls and cdLinux: Beyond ls and cd
Linux: Beyond ls and cd
 
The Fuzzing Project - 32C3
The Fuzzing Project - 32C3The Fuzzing Project - 32C3
The Fuzzing Project - 32C3
 
FITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an endFITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an end
 

Dernier

Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 

Dernier (20)

Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 

Introduction to Swift Programming Language and FizzBuzz Examples

  • 1. Introducing Swift - and the Sunset of Our Culture @dankogai 1
  • 2. Introducing Swift - and the Sunset of Our Culture? 2
  • 4.
  • 6. Hello, world! use v5.16; say "Hello, world!"; 6
  • 7. Hello, world! println("Hello, world!") // no main() required 7
  • 8. 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
  • 9. FizzBuzz println(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
  • 10. FizzBuzz - Lowest IQ println(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
  • 11. FizzBuzz for 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
  • 12. FizzBuzz - func func 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
  • 13. FizzBuzz - method extension 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
  • 14. FizzBuzz - getter extension 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
  • 15. FizzBuzz - subscript class 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
  • 16. FizzBuzz - generator extension 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
  • 17. FizzBuzz - optional let 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
  • 18. FizzBuzz - functionally let 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
  • 19. FizzBuzz - operator infix 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
  • 20. Demo
  • 21. 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
  • 22. let Swift = IMHO, it looks more like Perl6 than any other!
  • 23. let Swift = what.perl6.was.supposed .to.be!
  • 24. Script Languages vs "Compiler" Languages 24
  • 26. Write Run Type Languages Compiled Harder Faster Static C, C++, Java Scripted Easier Slower Dynamic Perl, Ruby, Python,JS 26
  • 27. Write Run Type Languages Compiled Harder Faster Static C, C++, Java Ideal? Easier Faster Static + ! Type Inference Swift? Scripted Easier Slower Dynamic Perl, Ruby, Python,JS 27
  • 28. The Sunset of Our Culture? 28
  • 31. 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
  • 32. 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
  • 33. 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
  • 34. 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
  • 35. 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
  • 36. Swift is a general purpose language 36
  • 37. 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
  • 38. 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
  • 39. 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
  • 40. 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
  • 41. 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
  • 42. that’s it (for now) for q in questions { q.answer() } 42