Skip to content

Instantly share code, notes, and snippets.

@normand1
Forked from raheelahmad/swift-vs-objc.md
Last active August 29, 2015 14:25
Show Gist options
  • Save normand1/ee2b9e9d5f1a9240e68b to your computer and use it in GitHub Desktop.
Save normand1/ee2b9e9d5f1a9240e68b to your computer and use it in GitHub Desktop.
Swift vs. Objective-C

Swift vs. Objective-C

Why Swift would be a better choice for the next production app.

Strong typing

  • correctness at compile time (besides behavior)
  • types as proofs (... illegal is impossible)
    • vs. testing
  • Examples
    • Optional (Maybe), typed collections
  • steep ramp-up, but compiles == runs well

Simpler APIs

  • class declaration
  • blocks/closures
  • less code
    • initializers
    • string interpolation
    • (basic) operator overloading
    • literals
  • no .h/.m (not really private)

Functional

  • first-class primitives
  • stdlib includes map, flatMap, reduce
  • currying
  • (most) type inference
  • (somewhat) lazy

Value Types

  • enums, structs
  • a great complement for functional programming
  • avoid state (functional core, imperative shell)
  • Immutable by default, single owner
  • thread safety

Faster

Current performance is in-par with C++

Look out for:

  • optimization setting
  • separate frameworks (with whole module optimization)
  • final

Other benefits

  • namespaces
  • property observers
  • generics
  • tuples
  • operator overloading
  • dynamic frameworks
    • versioned; reduced app size; can include assets etc.

  • playgrounds
  • well designed from scratch (rather than a legacy system)
  • developer mindshare

😱 Cons

  • 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 ✨
  • New...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment