Last active
February 19, 2016 22:09
-
-
Save pathawks/d639e13e59431c41da6d to your computer and use it in GitHub Desktop.
Revisions
-
pathawks revised this gist
Feb 18, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ # I :heart: Swift [:scroll: View The Slides](https://speakerdeck.com/pathawks/i-swift) ## About Swift Philosophy > Swift is friendly to new programmers. It is the first industrial-quality systems programming language that is as expressive and enjoyable as a scripting language. -
pathawks revised this gist
Feb 18, 2016 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -157,6 +157,8 @@ var (x, y) = getCoordinates() ## Expressive Syntax? * We haven't even talked about protocols and all that cool stuff! ## Swift Goals > The goal of the Swift project is to create the best available language for uses ranging from systems programming, to mobile and desktop apps, scaling up to cloud services. Most importantly, Swift is designed to make writing and maintaining _correct_ programs easier for the developer. @@ -172,8 +174,19 @@ var (x, y) = getCoordinates() ### Let's talk about "**Fast**" **None of this matters if the language is slow.** #### Chris Lattner * Designer of Swift * Compiler Guy - Creater of **LLVM** and **clang** + **LLVM** is default toolchain on FreeBSD - Completed a Ph.D. researching new techniques for optimizing pointer-intensive programs Being a "compiler guy" informs design decisions of **Swift**. ## References - [The Swift Programming Language.](https://swift.org/documentation/) Apple Inc. Used under a Creative Commons Attribution 4.0 International (CC BY 4.0) License. - [Wikipedia: Chris Lattner](https://en.wikipedia.org/wiki/Chris_Lattner) Used under a Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) License. -
pathawks revised this gist
Feb 18, 2016 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -165,6 +165,11 @@ var (x, y) = getCoordinates() - **Fast** - **Expressive** ### We've seen **Expressive**, Let's talk **Safe** * Automatic Memory Management * Undefined behavior is the enemy of safety ### Let's talk about "**Fast**" -
pathawks revised this gist
Dec 21, 2015 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,6 +14,8 @@ print("Hello, world!") ``` [:mag_right: See The Code](http://swiftlang.ng.bluemix.net/#/repl/51d2693342000ac090e8817796032592050e0f0b88d4d3a7ab1112058a169673) > If you have written code in C or Objective-C, this syntax looks familiar to you—in Swift, this line of code is a complete program. You don’t need to import a separate library for functionality like input/output or string handling. Code written at global scope is used as the entry point for the program, so you don’t need a main() function. You also don’t need to write semicolons at the end of every statement. - No `main()` @@ -91,6 +93,8 @@ for score in individualScores { print(teamScore) ``` [:mag_right: See The Code](http://swiftlang.ng.bluemix.net/#/repl/3cb6d22963cc1b3b96912d28b2c5279128a5a7ed87c190b51f33353de14368ea) ##### For Loops in Java ```java @@ -111,6 +115,8 @@ for i in 0...4 { print(accumulator) ``` [:mag_right: See The Code](http://swiftlang.ng.bluemix.net/#/repl/06cc02c49e42a011db31b3f3ce26ccec2da0779829c0b408ab0278e305a5c653) **Same As** ```swift @@ -121,6 +127,8 @@ for i in 0..<5 { print(accumulator) ``` [:mag_right: See The Code](http://swiftlang.ng.bluemix.net/#/repl/6f9da2ac8634cd18fdd5f4595d045fabf06ad246ff8c57c78bbc6b75e1de5122) ##### For Loops in Python ```python -
pathawks revised this gist
Dec 20, 2015 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -147,6 +147,20 @@ x, y = getCoordinates() var (x, y) = getCoordinates() ``` ## Expressive Syntax? ## Swift Goals > The goal of the Swift project is to create the best available language for uses ranging from systems programming, to mobile and desktop apps, scaling up to cloud services. Most importantly, Swift is designed to make writing and maintaining _correct_ programs easier for the developer. - **Safe** - **Fast** - **Expressive** ### Let's talk about "**Fast**" ## References - [The Swift Programming Language.](https://swift.org/documentation/) Apple Inc. Used under a Creative Commons Attribution 4.0 International (CC BY 4.0) License. -
pathawks revised this gist
Dec 19, 2015 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,7 +39,9 @@ let explicitDouble: Double = 70 ##### Safe Typing > Swift is a type-safe language, which means the language helps you to be clear about the types of values your code can work with. If part of your code expects a String, type safety prevents you from passing it an Int by mistake. > Because Swift is type safe, it performs type checks when compiling your code and flags any mismatched types as errors. This enables you to catch and fix errors as early as possible in the development process. - Variables cannot change types once declared, but often do not need explicit type information -
pathawks revised this gist
Dec 19, 2015 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,6 +29,7 @@ let myConstant = 42 ``` - Use `var` to declare variables and `let` to declare constants - If variable is given a value immediately, its type is implied, and does not need to be explicitly provided ```swift let implicitInteger = 70 @@ -38,6 +39,8 @@ let explicitDouble: Double = 70 ##### Safe Typing > Swift is a type-safe language, which means the language helps you to be clear about the types of values your code can work with. If part of your code expects a String, type safety prevents you from passing it an Int by mistake. Type safety helps you catch and fix errors as early as possible in the development process. - Variables cannot change types once declared, but often do not need explicit type information Python is a Dynamically Typed language -
pathawks revised this gist
Dec 19, 2015 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,6 +16,10 @@ print("Hello, world!") > If you have written code in C or Objective-C, this syntax looks familiar to you—in Swift, this line of code is a complete program. You don’t need to import a separate library for functionality like input/output or string handling. Code written at global scope is used as the entry point for the program, so you don’t need a main() function. You also don’t need to write semicolons at the end of every statement. - No `main()` - No semicolons needed - No need to import `stdio.h` for input/output ### Variables ```swift -
pathawks revised this gist
Dec 18, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # I :heart: Swift ## About Swift Philosophy -
pathawks revised this gist
Dec 17, 2015 . 1 changed file with 0 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +0,0 @@ -
pathawks revised this gist
Dec 17, 2015 . 2 changed files with 23 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -122,6 +122,22 @@ for i in range(1, 5) { print(accumulator) ``` ### Functions can return multiple values Similar to Python, a Swift function can return a tuple, which is effectively a way to return multiple values from one function. ##### Returning multiple values in Python ```python x, y = getCoordinates() ``` ##### Returning multiple values in Swift ```swift var (x, y) = getCoordinates() ``` ## References - [The Swift Programming Language.](https://swift.org/documentation/) Apple Inc. Used under a Creative Commons Attribution 4.0 International (CC BY 4.0) License. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ func getCoordinates() -> (Int, Int) { return (1,2) } var x: Int, y: Int x, y = getCoordinates() print("x = \(x), y = \(y)") -
pathawks revised this gist
Dec 17, 2015 . 1 changed file with 14 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -58,11 +58,11 @@ myVariable = "42" // Invalid, because `myVariable` is an Int final int[] individualScores = [75, 43, 103, 87, 12]; int teamScore = 0; for (int score : individualScores) { if (score > 50) { teamScore += 3; } else { teamScore += 1; } } System.out.printf("%d\n", teamScore); ``` @@ -73,11 +73,11 @@ System.out.printf("%d\n", teamScore); let individualScores = [75, 43, 103, 87, 12] var teamScore = 0 for score in individualScores { if score > 50 { teamScore += 3 } else { teamScore += 1 } } print(teamScore) ``` @@ -87,7 +87,7 @@ print(teamScore) ```java int accumulator = 0; for (int i = 0; i <= 4; ++i) { accumulator += i; } System.out.printf("%d\n", accumulator); ``` @@ -97,7 +97,7 @@ System.out.printf("%d\n", accumulator); ```swift var accumulator = 0 for i in 0...4 { accumulator += i } print(accumulator) ``` @@ -107,7 +107,7 @@ print(accumulator) ```swift var accumulator = 0 for i in 0..<5 { accumulator += i } print(accumulator) ``` @@ -117,7 +117,7 @@ print(accumulator) ```python accumulator = 0 for i in range(1, 5) { accumulator += i } print(accumulator) ``` -
pathawks revised this gist
Dec 17, 2015 . 1 changed file with 16 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,8 +32,24 @@ let implicitDouble = 70.0 let explicitDouble: Double = 70 ``` ##### Safe Typing - Variables cannot change types once declared, but often do not need explicit type information Python is a Dynamically Typed language ```python myVariable = 42 myVariable = "42" # Valid ``` Swift is a Statically Typed language ```swift var myVariable = 42 myVariable = "42" // Invalid, because `myVariable` is an Int ``` ### Loops ##### Enhanced For Loop in Java -
pathawks revised this gist
Dec 17, 2015 . 1 changed file with 20 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -86,6 +86,26 @@ for i in 0...4 { print(accumulator) ``` **Same As** ```swift var accumulator = 0 for i in 0..<5 { accumulator += i } print(accumulator) ``` ##### For Loops in Python ```python accumulator = 0 for i in range(1, 5) { accumulator += i } print(accumulator) ``` ## References - [The Swift Programming Language.](https://swift.org/documentation/) Apple Inc. Used under a Creative Commons Attribution 4.0 International (CC BY 4.0) License. -
pathawks revised this gist
Dec 17, 2015 . 1 changed file with 20 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -66,6 +66,26 @@ for score in individualScores { print(teamScore) ``` ##### For Loops in Java ```java int accumulator = 0; for (int i = 0; i <= 4; ++i) { accumulator += i; } System.out.printf("%d\n", accumulator); ``` ##### For Loops in Swift ```swift var accumulator = 0 for i in 0...4 { accumulator += i } print(accumulator) ``` ## References - [The Swift Programming Language.](https://swift.org/documentation/) Apple Inc. Used under a Creative Commons Attribution 4.0 International (CC BY 4.0) License. -
pathawks revised this gist
Dec 17, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,7 +41,7 @@ let explicitDouble: Double = 70 ```java final int[] individualScores = [75, 43, 103, 87, 12]; int teamScore = 0; for (int score : individualScores) { if (score > 50) { teamScore += 3; } else { -
pathawks revised this gist
Dec 17, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -48,7 +48,7 @@ for( int score : individualScores ) { teamScore += 1; } } System.out.printf("%d\n", teamScore); ``` ##### Enhanced For Loop in Swift -
pathawks revised this gist
Dec 17, 2015 . 1 changed file with 32 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,6 +34,38 @@ let explicitDouble: Double = 70 - Variables cannot change types once declared, but often do not need explicit type information ### Loops ##### Enhanced For Loop in Java ```java final int[] individualScores = [75, 43, 103, 87, 12]; int teamScore = 0; for( int score : individualScores ) { if (score > 50) { teamScore += 3; } else { teamScore += 1; } } System.out.printf("%d\n",teamScore) ``` ##### Enhanced For Loop in Swift ```swift let individualScores = [75, 43, 103, 87, 12] var teamScore = 0 for score in individualScores { if score > 50 { teamScore += 3 } else { teamScore += 1 } } print(teamScore) ``` ## References - [The Swift Programming Language.](https://swift.org/documentation/) Apple Inc. Used under a Creative Commons Attribution 4.0 International (CC BY 4.0) License. -
pathawks revised this gist
Dec 17, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,4 +36,4 @@ let explicitDouble: Double = 70 ## References - [The Swift Programming Language.](https://swift.org/documentation/) Apple Inc. Used under a Creative Commons Attribution 4.0 International (CC BY 4.0) License. -
pathawks revised this gist
Dec 17, 2015 . 1 changed file with 20 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,6 +14,26 @@ print("Hello, world!") ``` > If you have written code in C or Objective-C, this syntax looks familiar to you—in Swift, this line of code is a complete program. You don’t need to import a separate library for functionality like input/output or string handling. Code written at global scope is used as the entry point for the program, so you don’t need a main() function. You also don’t need to write semicolons at the end of every statement. ### Variables ```swift var myVariable = 42 myVariable = 50 let myConstant = 42 ``` - Use `var` to declare variables and `let` to declare constants ```swift let implicitInteger = 70 let implicitDouble = 70.0 let explicitDouble: Double = 70 ``` - Variables cannot change types once declared, but often do not need explicit type information ## References - [The Swift Programming Language.](https://swift.org/documentation/) Apple Inc. -
pathawks revised this gist
Dec 17, 2015 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,19 @@ # Introduction to Swift ## About Swift Philosophy > Swift is friendly to new programmers. It is the first industrial-quality systems programming language that is as expressive and enjoyable as a scripting language. > The compiler is optimized for performance, and the language is optimized for development, without compromising on either. It’s designed to scale from “hello, world” to an entire operating system. ## Swift Tour ### Hello World ```swift print("Hello, world!") ``` ## References - [The Swift Programming Language.](https://swift.org/documentation/) Apple Inc. -
pathawks revised this gist
Dec 17, 2015 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,5 @@ # Introduction to Swift ## References - [The Swift Programming Language.](https://swift.org/documentation/) Apple Inc. -
pathawks created this gist
Dec 17, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ # Introduction to Swift