Any sufficiently advanced technology is indistinguishable from magic.
– Arthur C. Clarke
Back when I was a programming student, my teacher Eric told me that over the years he has learned and forgotten a dozen programming languages.
At the time, it was inconceivable to me that anyone could learn and forget so much. Two years later, I am shocked to discover that he was right.
Two years ago when I really doubled down on learning iOS programming, I worked on it eighty hours a week. I was working through the Big Nerd Ranch iOS book. They had a series of about five chapters putting together a table view that would display a detail view populated by a singleton.
Every day I would wake up and code this over and over again. The first time I coded the examples, they made no sense. I typed a bunch of words that didn’t set off the compiler warnings, ran them, and magic happened. The second time was not much better. But by the third for fourth time, I began to realize, “Oh, I am creating this object because later when I load this detail view, I will be showing all the stuff I am keeping in this object. This is where it comes from.”
At the time Storyboards Interface Builder wasn’t particularly good for things. If you listen to many people online, their assessment of this situation has not changed. I used .xib files for each of my view and my custom cells and did all of my transitions programmatically. It took me weeks to wrap my head around all of these moving parts to figure out how they worked together. It wasn’t enough for me to just have something work, I really wanted to understand it.
Over the last year and a half, I haven’t really worked with user interfaces much. I had a contract job where there was no UI in Interface Builder because it was a legacy project from 2008. Then I spent a bunch of time running around like a chicken with my head cut off trying to figure out shaders, which are a tiny subset of a program. Then for the last eight months I have been working on porting another legacy project to Swift. We are just now getting to the point where I am working with interfaces again. It’s been over a year since I dealt with interfaces.
I am working on my first application. It is going to be rather limited to start off with, but I have plans to add additional functionality over time, so whenever I finally get it out, no, that is not the final product, more will come later, so don’t give me crap about it.
I am working with HealthKit. In HealthKit, there is a HKHealthStore that you are only supposed to have one instance of in your entire application.
I have been trying to figure out where to make that instance. I know that it needs to be accessible through the entire application and that you’re not supposed to make a bunch of instances of the same thing. I also know you have to pass it along to a lot of different places. I know many people don’t like singletons and I don’t want to create one of those, even though I am pretty sure HKHealthStore is a singleton. I was trying to figure out how all of the controllers can know about something while minimizing global state.
I talked to Brad about this a bit and he was talking about how it should be created in the root view controller for the application because that is responsible for the views that are controlled by it. As he was talking about all this stuff, it dawned on me that he was talking about the same things I was bashing my head against two years ago.
It wasn’t like I had spent a week mucking around with this stuff. I spent eighty hours a week for MONTHS trying to piece together how all this crap worked. I can’t believe that after spending all that time and pain on these concepts that they were buried in some far corner of my brain.
It also made me wonder about all the people who are learning programming now who use storyboards because, honestly, they are easier to get things done quickly. If you just push a couple of buttons and things happen like magic, how do you get a full understanding of what is actually going on? It makes me wonder about what else I don’t know about because I came into programming relatively recently. I know that my knowledge of memory management is bad because it was never something I had to deal with. I came in around iOS5/iOS6, so we had ARC and GCD and a lot of other things that abstract out a lot of the lower level programming stuff from you. Will understanding how root view controllers own detail views go the same way? I know talking to a guy at my first job he didn’t seem to understand this concept and it drove me crazy. I guess I have gotten to the point where I don’t understand it either.
It frightens me about how vast the knowledge is of everything that happens within the iOS ecosystem and how incredibly difficult it is to remember everything because really delving into the low level stuff means that you don’t know how to get things done quickly in the abstracted level. Sticking to the abstracted level limits your ability to do anything really customizable because you don’t see how the pieces fit together.
I am hoping that over the course of the next few years I can figure out a balance that works for me. I hope I can remember enough about how things work that I can deal with the abstracted layer without fundamentally forgetting everything.