autoscale: true build-lists: true
- C-superset
- Dynamic type system
- Object-Oriented
- influences: C, Smalltalk
- Strongly typed
- (mostly) functional
- correctness, conciseness (S v N)
- influences: Scala, Rust, Haskell
- correctness at compile time (besides behavior)
- types as proofs (... illegal is impossible)
- vs. testing: TDD vs. TDD
- e.g.:
Optional
(Maybe
), typed collections, generics - (most) type inference
- steep ramp-up, but compiles == runs well
- blocks/closures
- initializers
- string interpolation
- (basic) operator overloading
- literals
- class declaration
- easier unit tests
NSInteger (^SumOfTwo)(NSInteger, NSInteger) = ^BOOL(NSInteger first, NSInteger second) {
return first + second
};
let sumOfTwo = { (first: NSInteger, second: NSInteger) in
return first + second
}
let sumOfTwo = { first, second in
return first + second
}
let sumOfTwo = { return $0 + $1 }
let sumOfTwo = { $0 + $1 }
@property (nonatomic, copy) BOOL (^comparator)(NSString *, NSString*);
let comparator: (String, String) -> Bool
- (void)compare:(BOOL (^)(NSString *, NSString *))comparator {
}
func compare(comparator: (NSString, NSString) -> Bool) {
}
Person.h
@interface Person: NSObject
@property (strong) NSString *name;
@property (strong) NSNumber *age;
@property (nonatomic, copy) BOOL (^onChange)(NSString *context);
@end
Person.m
@interface Person()
@property (strong) NSString *firstName;
@property (strong) NSString *lastName;
@end
@implementation Person
...
@end
class Person {
var name: String
var age: Int
var onChange: (String) -> Void
private firstName: String
private lastName: String
}
- first-class primitives
- stdlib includes
map
,flatMap
,reduce
- currying
- (somewhat) lazy
- enums, structs
- a great complement for functional programming
- avoid state (functional core, imperative shell)
- Immutable by default, single owner
- thread safety
- Current performance is on-par with C++
- But look out for:
- optimization setting
- separate frameworks (with whole module optimization)
final
- Benchmarks etc.
- namespaces
- property observers
- access modifiers
- generics
- tuples
- protocols
- pattern matching (switch-case on steroids)
- operator overloading + subscripting
- error handling (control flow + type)
- dynamic frameworks
- versioned; reduced app size; can include assets etc.
- playgrounds
- well designed from scratch (rather than a legacy system)
- open source
- developer mindshare
- Apple is betting on it
- May have rough edges (very few post-2.0)
- Some tasks are more difficult with the strong type system (parsing JSON, building a plugin system)
- Interacting with C (lots better in 2.0)
- Familiar vs. complex
- Solutions can be too Creative ✨
- "you can do it all in ObjC"
- Khan Academy
- CapitalOne
- P2P
- Ideas
- EASE
- Zazzle
- Apple
- https://www.apple.com/business/mobile-enterprise-apps/
- Dock.app
- WWDC.app
- Faster iteration for an implementation
- Safer
- Cleaner abstractions in complex contexts
- less bugs
- scalable
- modifiable...
- Safer bet for the future
- All new code
- Break out modules into Swift frameworks
- continue & refine LVUser, LVBankConnection, LVNetworking
- easier to grok/develop/reuse
- ability to add unit tests for smaller modules,
- possibly open source modules
- Convert legacy code incrementally
- clean architecture & grasp
- fewer bugs
- faster iterations
- (re)write Persistence layer
♦️ - rewrite Model layer
♦️ - move to JSON
- rewrite API layer
♦️ - rearchitect MVC pattern + information flow
♦️ - factored-out, reusable code
- clearer dependencies
- Others
- Analytics
♦️ → adds 1.5 - 2 months to development time
all → adds 2 - 2.5 months