Slowly crawling up the learning curve

Man, XCode development is hard. And fun.

XCode is the suite of development tools that Apple gives away for its OSX and iOS operating systems. It lets you write programs for OSX or iPhones/iPads/iPod Touch, in other words. It’s free, but it’s a serious bunch of software. Writing code with it is not like writing a Visual Basic application (well, except for when it is). The language behind it is Objective-C, which is a variant of the old C programming language. I’ve got some familiarity with C, but most of my software writing experience is using languages like PHP and Python and Perl (love them P languages) that handle a lot of things for you automatically, like pointers.

A pointer is a concept in programming languages that helps make programs more memory efficient. In C, you can say the following:

int x = 10;

That means you’re declaring a new integer value named ‘x’ which starts with the value of 10. Integer values can hold whole numbers.

All well and good. But most of the time in iOS, you’re not dealing with simple little things like integers. You spend a lot more time dealing with very complex objects that consist of lots of simple numbers as well as other objects – like UIView. UIView is an object that’s responsible for displaying stuff on your iPhone or iPad. It takes up a lot more memory than an int, so when you declare one in Objective-C, you create a pointer to it, like so:

UIView *myView;
myView = [[UIView alloc] init];

The “*” on the first line means that you’re not creating a variable that is a UIView; it means you’re creating a variable that points to a different memory location where the UIView is actually being created – a pointer. A pointer doesn’t contain a value that you can use; it contains a memory address where the value that you want to use actually lives.

PHP, Python, and Perl don’t (typically) make you use pointers. Any variable that you create in them is just a variable that you can play with directly. The problem with pointers is that they can potentially allow you to accidentally reference a chunk of memory somewhere else that may or may not still be the variable that you want to be working with. The old adage is that C gives you enough rope to shoot yourself in the foot – pointers are a great way to do that.

Anyway, all this is really saying is that I’m still coding and still learning. Hopefully something useful comes of all this. I need coffee and chocolate.

Comments are closed.