Dimdim was the first time when I encountered OSX. The first time I saw this machine.
Everything there was new including using it, the file system layout, conventions, file extensions etc etc. Then I came to know that it is actually a Unix based system. I actually had a terminal at my disposal where I could do all my stuff starting from cp/mv to ps/top. That was an awesome news for me. I was really spellbound the styling and effects and the systematic organization of files/apps etc on mac. I liked it.
But then the keyboard, the shortcuts everything was new to me.
Then there was XCode, the dev environment on OSX. It took some time to familiarize XCode but then I soon found that this piece of software was really good and usable.
The more I saw MAC the more I was impressed by it.
Enter Objective-C. Aaaaaaaaaaaaaa!!!!! I couldn't help but shout. Coming from a background of C/C++ starting my IIIT days, this was one language which was hell different. The most significant difference to me was the function declaration and invocation.
Declaration
C/C++ style:
char * func(int i, char * c);
Objective-C style:
-(char *) func : (int) i charlabel (char *) c;
In C, we have a type and name for each argument, but in obj-c we have a label, type and name for each argument, except for first which has no label.
function name above is "func:charlabel" :D
Invocation:
C/C++ style:
char * r = func(i,c);
Objective-C style:
char * r = [func : i charlabel : c];
It actually took me a while to digest the fact that I was reading functions in the code and I was actually invoking a funtion when I wrote the above lines :D
But then I realize that this was one language which had been developed well before C++ had evolved and it had the object-orientedness embedded in it.
You feel like OSX development is a world in itself, totally untouched and uneffected by external world!
Then started the actual coding. I realized after some time that you can invoke methods on "nil" (equivalent of our NULL) objects and not crash ur code. It just doesn't get executed! functions calls are also like messages which are delivered on a best effort basis!
below is an example:
static MyClass * c = nil;
void doOpOnMyClassVar()
{
//some code
int i = [c getVar1Val];
//some more code
}
This code was failing functionally because the "i" was not getting assigned correctly! It took me a while to trace that I forgot allocation of "c". Once I allocated, things were working awesome! But note, no crash! just ignored function call!
I had to refer to apple documentation for class references and etc. I find that though the documentation is extensive, it is not really so appealing as one finds...say java documentation or MSDN for that matter. To find the help for a funtion you may have to refer multiple places and you find many links which refer each other (page 1 says refer page 2 and page 2 says refer page 1).
After all the struggle and fight, I could finally complete the task in hand and was instantly named as the future expert of OSX code and the guy responsible for the OSX codebase :)
After this first stint, I have worked a lot on OSX and at one stage I found it strange to come back to the all familiar visual studio. I would actually instinctively use the shortcuts of OSX on windows!
I cannot help but smile when I come across these situations.
Before joining Dimdim, karthik was known as the Linux guy everywhere. But after coming here, I have worked only on Windows and OSX. Windows is OK, I worked a bit there too...but never did I dream even in my wildest dreams that I shall actually work on Objective-C and actually even respect it and get mildly addicted to it ;)
Subscribe to:
Post Comments (Atom)
2 comments:
Quite interesting. I have never used objective-c. The function format looks really wierd though.
ya.... i guess thats' the reason the mac system doesn't good games etc as windows does.. but im assuming gnu compilers (gcc, g++) work on mac os too.. aren't they good on osx?
Post a Comment