Re: Objective C and C++
Re: Objective C and C++
- Subject: Re: Objective C and C++
- From: Marc Vaillant <email@hidden>
- Date: Thu, 25 Dec 2008 21:12:13 -0500
- Mail-followup-to: Kevin Boyce <email@hidden>, coreaudio-API postings <email@hidden>
On Wed, Dec 24, 2008 at 03:10:12PM -0500, Kevin Boyce wrote:
>
> On Dec 22, 2008, at 2:41 AM, Brian Willoughby wrote:
>
>> But Apple can still take your advice to heart. More Standard C
>> examples would be helpful, since they could be incorporated into C++
>> or ObjC without necessitating so much in-depth knowledge of the
>> "other" language. Also, if Apple were to provide more ObjC examples
>> for the C API like CoreAudio and CoreMIDI, then new programmers who
>> are learning C and ObjC for the first time would not have the
>> additional burden of learning C++ and how to break out the Standard C
>> lines from the rest. There is a big market for new programmers
>> learning Cocoa and ObjC, so the focus on C++ examples can be a serious
>> hurdle.
>
> I heartily concur! I don't do much programming in my day job, so I made
> the choice many years ago to attempt to pole-vault from C right over C++
> to whatever came next (since C++ looked, and still does to my eyes, like
> something even easier to shoot your own feet with than C).
I disagree. For example, RAII in C++ helps you practice safer memory
management than obj-c reference counting and autorelease pools. That
is, 99% of the time you create objects on the stack, which obey
scope rules just as basic types like int, double, etc. Dynamic memory
allocations are encapsulated, typically with the help of container
objects from stdlib. Also, destructors of objects created on the stack
are guaranteed to be called so your code is automatically exception
safe w.r.t those objects.
Lastly, static typing in C++ helps catch bugs at compile time.
So, from a "shoot your own feet" point of view, I don't think that obj-c
wins.
C++ classes are often quite natural to use. Compare the following
two implementations of a 2D Array class:
objective c:
http://objc.vaillant.fastmail.fm/ArrayTest.m
http://objc.vaillant.fastmail.fm/Array2D.h
http://objc.vaillant.fastmail.fm/Array2D.m
C++:
http://objc.vaillant.fastmail.fm/ArrayTest.cpp
http://objc.vaillant.fastmail.fm/Array2D.hpp
Marc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden