Learning to curse

I forgot how much I hate the fickleness of writing software!

I finally gave up on Swift (for now). It’s a easy to pick up language because it resembles more a modern scripting language than a compiled one, and frees you up from historical artifacts like Smalltalk, C pointers, and reference counting. Plus you get awesome things like playgrounds:

Sure, it takes a little bit of chucking random “?”’s and “!”’s in your code before you get the hang of optionals, and I’d fear the performance of a basic structure like a b-tree written in Swift, but it interoperates with C and Objective-C so I don’t have to worry.

Or so I thought. Because of strong typing and the lack of built-in overloads, poorly documented character-based1 functions, here is how I inject a a random letter into a string:

let randomletter = "\(String(UnicodeScalar(65 + Int(arc4random_uniform(26)))))"

And then you find it doesn’t always release variables when you use optionals. create some optional simple objects, add them to an array reset everything and see what your NSLog() (e.g. println())) prints in your deinit:

e.g. BNRItem.swift:

import Cocoa
import Foundation

class BNRItem: NSObject, Printable {
    var itemName:String
    init(itemName name:String)
        self.itemName = name
    deinit {
        println("Destroyed \(self)")
    class func randomItem() -> BNRItem
        let randomAdjectiveList = ["Fluffy", "Rusty", "Shiny"]
        let randomNounList = ["Bear", "Spork", "Mac"]

        let adjectiveIndex = Int(arc4random_uniform(UInt32(randomAdjectiveList.count))) //arc4random() overflows Swift int
        let nounIndex = Int(arc4random_uniform(UInt32(randomNounList.count)))

        let randomName = "\(randomAdjectiveList[adjectiveIndex]) \(randomNounList[nounIndex])"
        return BNRItem(itemName: randomName);
   override var description:String {
        return "\(itemName)"

and main.swift:

import Foundation

var items = BNRItem[]()

var backpack:BNRItem? = BNRItem(itemName: "Backpack")
var calculator:BNRItem? = BNRItem(itemName: "Calculator")
backpack = nil
calculator = nil

for item in items {

// Destroy the mutable array object
println("Setting items to nil…")
items = []

creates 4 items, deletes three. Hello, memory leaks!

Then there are issues when you call C functions like CoreGraphics from Swift. My personal favorite is depending on if I restart Xcode before compiling, one of my apps compiles file or throws an error:

SetAppThreadPriority: setpriority failed with error 45


That’s not to say I won’t use it for the future. It’s just too frustrating for me to programming model (Cocoa Touch) in a language that I’m rusty at (Objective-C) in a new IDE (Xcode), translate to a language I don’t know (Swift), and not know if my errors are my own stupidity, or just the compiler is buggy.

Yes, someday Swift, and Swift playgrounds for learning the language, and perhaps even a mix of Swift and Objective-C in a iOS project, but I’m putting the language down for now until I learn Cocoa Touch.

  1. as opposed to string based functions 

Learning to smile

Learning to smile

I’ve been a manager for 2.5 years and I’ve been too long away from programming. There is something just so wonderful about being able to work again in a world where there is a right and a wrong.1

I decided to start to finally2 teach myself iOS development today for: first, because I’ve never done it before and second, because it’s an opportunity to learn a new language and re-learn an old one3 I haven’t done for over a decade.

We’ll see how it goes. I’m not optimistic.

  1. …and getting the feedback to know which is which! 
  2. This does not count. 
  3. If you call writing a median-based BPM counter for Mac OS X, “learning.” I think the jury is still out since Xcode, memory management, and the user-interface are so different now.