15Jun/092
Thoughts on Objective C
This is my first day trying to learn Objective C. Here's my thoughts so far - some of these may be wrong since I am still a newb.
Learning a new language is always a bit frustrating at first, so bear with me.
What is it
- Objective C seems like it started with C, took a few OO concepts from C++ and added manual reference counting memory allocation out of the box. Somewhere along the way, syntax got beaten to death with a hammer, resulting in a strange, unique syntax. This gets a big frowny face from me - almost every modern language shares a similar syntax (Java, C++, C#, Actionscript, Javascript, heck even PHP once you get past the dollar signs) - being different here only makes it hard to learn and there's no reason it couldn't have a more C++ or Java like syntax.
What's weird
- Why come up with an entirely new syntax and language? Objective C is rumored to be less efficient than C++ and doesn't seem to offer any benefits. Programmers still have to deal with pointers (in the sense that bad reference counting can still crash your applications). Poor use of reference counting can easily lead to memory leaks. There doesn't seem to be anything particularly slick or time saving about the language itself.
- When declaring an interface, why are methods and variables outside of the brackets? Also, it's not necessary to declare methods as part of the interface? Seems like this kind of defeats the purpose of having an interface.
- Way of declaring and calling methods (esp methods with parameters) is strange and not very readable..
What's nice
- Interface builder is kind of nice.. Ability to click and drag to connect outlets is slick. However, I find myself wondering if I couldn't do things faster just by creating the interface "by hand" with code. Even simple stuff requires a lot of setup..
- @property, @synthesize
So far every application I try to write from scratch crashes and burns. Oh well, there's always tomorrow.
June 18th, 2009 - 09:44
Objective-c Language is definitely tough to get used to coming from a JAVA/C#/C++ background. In theory, the reason for the strange syntax (basically passing method names as string parameters) is because of Objective C’s Dynamic Typing which enables Message passing and forwarding. The syntax is therefore based in the languages roots in Small-talk. Hence, the parsing of method calls happens during run-time , leading to further frustration for developers. It should be noted though, that message passing and dynamic typing can be extremely powerful, especially in mobile apps which, I believe, was the reason for incorporating it into the iphone platform.
June 18th, 2009 - 13:44
Dynamic typing is cool (flash is capable of some pretty extensive dynamic typing). It is most helpful for keeping loosely defined connections between your classes (and enabling easier interprocess communication). However, there’s still no reason why [someobj somefunc] couldn’t be written as someobj.somefunc. Flash has dynamic typing and works this way. That said, flash is a scripting language and maybe there was some technical reason why objective C chose not to work do this. The thing that seems to really suck about this scheme is that if you mess up a method call (ie, pass the wrong parameter to a method or call a method that doesn’t exist) then you get a crash with no ability to find out what line the crash occurred on. Also, no error at compile time. This can be a real pain for debugging. Also, with the retain / release scheme, if you release something you shouldn’t have, the crash doesn’t always occur until the memory pool is released (which also is a nightmare to debug).. in C/C++, if you release the same memory twice or access a bad pointer you get a crash right away and it’s pretty easy to debug. The bugs that are hard to catch are buffer overruns since they don’t always cause a crash where you expect. Anyway, I guess I was just kinda hoping that since apple is regarded as being so visionary when it comes to designing devices, that their choice for programming language would offer something over .NET, Java, etc.. My experience is that it has a higher learning curve and is just as crashy, if not more so than other languages I’ve used. Just look at how many iphone apps crash or leak memory. if the iphone was made by microsoft, apple would be all over that. Instead people pretty much ignore it. Strange how that works.
But, enough venting – I’m sure in a week or two I’ll be totally comfortable with the language and won’t care about it’s shortcomings.