ObjC vs C++ (was: Is ZLib available in Cocoa?)

  • I. Savant wrote:

    > There's nothing inherently different about building this with XCode
    > than any other IDE. XCode-related questions are best posed to the
    > xcode-users list while questions about how to build this particular
    > project are best posed to any forum(s) associated with that project.
    > The particulars about how to build zlib have nothing to do with Cocoa.
    >
    > Now the NSData category to which I referred you does ... :-)

    OK, now I understand that I asked offtopic question. Now a bit closer to
    Cocoa:

    I have to develop a Cocoa app, but the "visual" part is closely connected
    with a very big "invisible" part of code, containing many classes having no
    relation to UI. ZLib is just one of many modules used there. The question
    is: should I transcode ALL stuff to the ObjC or can I leave the main stuff
    "as is" in usual C++ and instantiate C++ classes from ObjC "visual" classes?
    The docs I read tell me that both ways are possible, but I'd like to know an
    opinion of experienced people, what way is better and what (if any)
    negatives are covered in usual C++ classes calls from ObjC classes. If
    possible, I'd prefer to keep the main "invisible" stuff in C++ for
    universality saving. As I understand, ObjC is used only by Cocoa...

    Hope this is not an offtopic :)

    Thanks.
  • I go further; I write extensive new code in C++ for use from Objective-C.
    The reasons are complex and almost certainly not relevant to your project,
    but there are big chunks of what you would call my "invisible" code where
    C++ is a better fit for what I think is the best design.

    So, yes it's eminently practical, with only a few gotchas. And the gotchas
    can be mostly addressed by a strict separation of functionality between
    Objective-C and C++, with tight control over how they interface. In other
    words, mostly have the Obj-C user interface call down into the C++, avoid
    have call chains going back and forth from one language to the other all
    over the place. That said:

    - When you embed C++ instances (as opposed to pointers) in Obj-C objects,
    constructors & destructors will not be called unless you enable a compiler
    option for that, which will only work for 10.3 and up.

    - C++ and Obj-C exceptions are not the same, and each language can only
    handle its own exceptions. This is the major reason for my advice to limit
    the areas where the languages touch. There are, btw some libraries out there
    that help with converting exceptions so that they can be thrown across the
    "other" language. I don't use them, because in my case it's acceptable to
    declare "an uncaught exception is a programmer error: log it, barf, and
    die."

    For more info:

    <http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articl
    es/chapter_4_section_10.html
    >

    --
    Scott Ribe
    <scott_ribe...>
    http://www.killerbytes.com/
    (303) 722-0567 voice
  • On Oct 5, 2007, at 11:33 AM, Scott Ribe wrote:

    > I go further; I write extensive new code in C++ for use from
    > Objective-C.
    > The reasons are complex and almost certainly not relevant to your
    > project,
    > but there are big chunks of what you would call my "invisible" code
    > where
    > C++ is a better fit for what I think is the best design.

    I do this as well.  In my case the "invisible" code is shared with
    Windows.  The cross platform portion of the code implements the
    "model" (and portions of the controller) of the application while the
    user interface and interaction with things like the drawing libraries
    are Objective-C.

    Scott
  • On Oct 5, 2007, at 11:13 AM, Scott Thompson wrote:

    >
    > On Oct 5, 2007, at 11:33 AM, Scott Ribe wrote:
    >
    >> I go further; I write extensive new code in C++ for use from
    >> Objective-C.
    >> The reasons are complex and almost certainly not relevant to your
    >> project,
    >> but there are big chunks of what you would call my "invisible"
    >> code where
    >> C++ is a better fit for what I think is the best design.
    >
    > I do this as well.  In my case the "invisible" code is shared with
    > Windows.  The cross platform portion of the code implements the
    > "model" (and portions of the controller) of the application while
    > the user interface and interaction with things like the drawing
    > libraries are Objective-C.

    Thirded. I write cross-platform apps, so the model is C++. It works
    fine.
  • John Stiles wrote:

    > Thirded. I write cross-platform apps, so the model is C++. It works
    > fine.

    It's just my case. Thanks to all who answered me. I'm glad to see that I
    thought in the right directon.

    Best regards,
    Alexander
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today