Making up for Cocoa shortcomings

bauhsoj

Registered
I have spent most of my programming career working with PHP and after branching out to Java I found that I have been fairly spoiled with some of PHP's ease of use. I have only recently been delving into objective-C as I believe it would be the language of choice for a new area of interest I am focusing on, which is genetic algorithms and evolutionary programming. I believe objective-C would be a good candidate because it is somewhat faster than C or C++ (from what I have read), it is self-documenting, high code reuse potential, dynamic typing, and because of Cocoa's rich objects.

I was recently reading over a post at Wikipedia that detailed a lot concerning Cocoa programming. As I read I came across what appears to be some shortcomings of Cocoa that I would like to try to address before I start programming with the language. If anyone can comment and/or offer solutions to these issues, I would greatly appreciate it.

Please excuse me for noting these shortcomings, whether perceived or real, from a PHP based perspective....that just happens to be the programming language I have the most expertise with so it is a convenient reference point.

1. Memory Management: Memory management appears to be completely manual, unless I am misunderstanding what I read. Is there any way to enable automatic garbage collection in a Cocoa app as is standard with PHP and Java?

2. NSString: This object appears to be missing a built-in regular expression package. I frequently use Perl and POSIX style regex in my PHP to handle a lot of parsing and searching. Can this be easily fixed and what would be involved in adding regex support to NSString?

3. High-End Database Integration: I very frequently utilitize MySQL during development in PHP. With PHP it is very simple to access data in MySQL (or any other DB server) through built-in functions and it is also possible to do similar in C++ through the use of the MySQL++ class. Can this be easily achieved in Cocoa or is there any workaround?

Know of any Cocoa quirks I should be aware of coming from a PHP background?

If you know of any other shortcomings that I should be aware of, I would appreciate knowing those, too. The easier it is for me to slide into Cocoa development the better as I am currently working a very heavy schedule that will leave me with very little time each week to become familar with the language and get around any problems.

Thanks in advance for any input!
 
1. No, there's no automatic garbage collection in Cocoa.

2. That's true, there's no built-in regex, but there are a few third party frameworks you can add to your application if you need it.

3. Obj-C is a subset of C. There's also Obj-C++. You can use regular C or C++ calls in Cocoa. (If you want to use (Obj-)C++, the file extension needs to end in .mm)

Also, there's a Java <-> Obj-C bridge, and some third party bridges as well (Python and Perl, perhaps some other ones I'm not aware of). With those, you can call Obj-C methods within Java or others with third party bridges.
 
I'm sorry, but I have to question something you stated...

>I believe objective-C would be a good candidate because it is somewhat faster

Where did you get this info? I have heard the opposite.
 
cfleck said:
I'm sorry, but I have to question something you stated...

>I believe objective-C would be a good candidate because it is somewhat faster

Where did you get this info? I have heard the opposite.

I read somewhere objective-c is three times faster than C or C++, however, my memory may have simply been wrong on that as I read it quite a while back. I did some searching to figure out where I read that and it seems that Objective-C is 3 times faster than SmallTalk, as I found in the comp.lang.objective-c FAQ

Can you point me to a reference on just how fast Objective-C is compared to C and C++?

I found the following page on Objective-C speed but I don't know how accurate it is as it seems to be from one person's experiences.
http://lists.gnu.org/archive/html/discuss-gnustep/2001-08/msg00221.html
 
Darkshadow said:
3. Obj-C is a subset of C. There's also Obj-C++. You can use regular C or C++ calls in Cocoa. (If you want to use (Obj-)C++, the file extension needs to end in .mm)

Also, there's a Java <-> Obj-C bridge, and some third party bridges as well (Python and Perl, perhaps some other ones I'm not aware of). With those, you can call Obj-C methods within Java or others with third party bridges.

Are their any performance issues with using a combination of languages?
 
If you mean mixing C/Obj-C C++/Obj-C++, then no, none that I have ever noticed.

If you mean with the bridges, then most likely there's some performance issues. I can't say for sure, as I haven't even attempted to use them.
 
On the speed issue an objective C method call is about 2 time more expencive than a regular C function call. So that aspect is slower. But the important issue really is how well it allows you to write code. If you can write your code 5 times faster but have it run twice as slow then that is a big win. Even writing 10% faster will be a super boost in productivity.

If you look at it from a project management perspective if you give the same task to 100 programmers there can easily be a 10x difference in speed between any two implementations in the same language. So worrying about the small overhead of method dispatch is a silly exercise in premature optimization.
 
lurk said:
On the speed issue an objective C method call is about 2 time more expencive than a regular C function call.

I know there have been some improvements to the language by Apple since it was originally adopted. Any idea if Apple can or will improve the language to address such speed issues?
 
Back
Top