This is a post in my series “Road to Xcode.” I will be embarking on a journey to learn Objective C and Cocoa programming for Mac OS X. This will not be an instructive series but rather a look at what I have learned as well as the resources I am using to gain ground in the wide world of software development. You can follow my progress or check out other posts in this series by heading over to the Road to Xcode tag page.
Introduction
To kick start my Xcoding journey I am reading Become An Xcoder by Bert Altenburg, Alex Clarke and Philippe Mougin. This book is aimed at people with absolutely no coding experience and is free to download in PDF form.
01: A program is a series of instructions
The introduction and first chapter to Become an Xcoder is rather simple. I was introduced to basic programming terminology like data types, integers, operators, etc. Nothing I was too unfamiliar with since I read through basic introductions to PHP which uses the same terminology (I suppose all languages do). Working through the chapter was pretty straight forward except for the introduction to the ++ operator. I don’t know what it is, but I always seem to get hung up on this thing’s function. I understand what it does (a variable will be itself incremented by 1 i.e. x = x + 1). I was having a hard time with the outcome of the variable depending on the order the operator was used, such as x++ versus ++x. The examples written in the book were not extremely helpful, but then again I am only on the first chapter and I am hoping better explanation of the ++ operator will be later on.
As with any introduction I was not compiling any code or even looking at the IDE, but I am eager to continue.
This makes me want to read the book. I have to tell myself, “no, mo-mars,” because I know it won’t go anywhere w/ me LOL
Good luck with your endeavors! That ++x oper is new to me. I am used to seeing +=1 for that sort of thing. It looks as if putting the “++” before the variable (++x) specifies that the it takes precedence in the order of operations (just as we multiply before we add). Putting the “++” after the variable (x++) simply executes the operation in the order specified. Just as the Intro says, writing lines in this way is a method of shorthand, which can be more clearly written out in multiple lines!
They actually are quite a bit different… In languages like C++, the “++” operator is more than just shorthand for “add one”, it can also do things like increment pointers by the size of a datatype… so:
int numbers[2];
int* p = numbers;
*p = 10; //Sets the first element to 10
p++;
*p = 20; //Sets the second element to 20
“+=” on the other hand is just shorthand for addition… “p+=sizeof(int);” wouldn’t have been as nice. :)