Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > The merits of ObjC without Cocoa?

The merits of ObjC without Cocoa?
Thread Tools
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Feb 12, 2001, 02:04 PM
 
Is it stupid to use ObjC if I don't want to write a full GUI?
I mean, since ObjC has a runtime environment, will it be slower and more pathetic than an equivalent C++ app for command-line only environments?
How is ObjC as a language of it's own right, compared to C++, when each are separated from their respective APIs?

------------------
"This works that doesn't apple locked root out will it come back this hardware no longer kernal panics means apple going backwards this or that software now crashes..... build 4k29 ak47 On and on." -Scott_H, the one and only English mutilating, word modulating, Mac OS X moderator.
All that matters to me is the Dock perversion.
you are not your signature
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
Feb 12, 2001, 07:58 PM
 
I wouldn't use ObjC for sections of code where you're trying to conserve every possible machine cycle, but other than that there should be no problem. Part of Cocoa is the Foundation framework, which has lots of useful classes for any program, be it GUI or command line.

As for portability, the GNUSTEP equivalent of Foundation seems pretty stable and complete, which should get you to several platforms. C++ might currently be portable to more systems, though -- not sure. I've heard of some projects out there that use ObjC, like www.swarm.org (I don't think they use anything from GNUSTEP though -- they have their own stuff).

As for comparing the languages directly, well, that's more of a religious issue. I personally prefer ObjC as I feel it provides an awful lot more design flexibility (as demonstrated by the Cocoa APIs) leading to easier-to-read and more maintainable code, but others will differ. In the end, both languages should get the job done, so pick whichever one you prefer. Don't avoid ObjC simply because you're writing a command-line tool, that's all :-)
     
ali
Forum Regular
Join Date: Sep 2000
Status: Offline
Reply With Quote
Feb 12, 2001, 08:05 PM
 
Objective-C runtime is actually pretty small. The "cost" of Objective-C is actually more in all of the class information, as the classes, categories, etc are all registered in the runtime.

An Objective-C program that links only against the Foundation framework (which provides NSObject, NSString, collection classes, distributed objects,etc) would be quite small and fast, so the answer is "it's not stupid".

Ali
     
Gametes  (op)
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Feb 12, 2001, 08:52 PM
 
thanks ali, that's exactly what I'm asking.
that said, I just wrote a very basic C app to test out ObjC minus Cocoa, but i can't run it in the terminal. the dev tools compile it to a .app and then it opens and closes as if it were a real app. I just want a basic command-line ObjC app, and I read in the documentation that ObjC will definetely run all C apps.
My project was a Cocoa app (no docs) from the dev tool menu.
Can you help?

------------------
"This works that doesn't apple locked root out will it come back this hardware no longer kernal panics means apple going backwards this or that software now crashes..... build 4k29 ak47 On and on." -Scott_H, the one and only English mutilating, word modulating, Mac OS X moderator.
All that matters to me is the Dock perversion.
you are not your signature
     
Fresh-Faced Recruit
Join Date: Feb 2001
Location: San Francisco, CA, USA
Status: Offline
Reply With Quote
Feb 13, 2001, 01:26 AM
 
Here's a start. If you're using ProjectBuilder, try creating a new "Cocoa Tool" project instead of a "Cocoa Application" project.

sybarite> cat >foo.m
#import <Foundation/Foundation.h>

main ()
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSString *msg = [NSString stringWithFormat:@"Hello, %@!", @"world"];
NSLog(msg);
}
^D
sybarite> cc -g foo.m -framework Foundation
sybarite> a.out
Hello, world!
sybarite>

     
Senior User
Join Date: Feb 2001
Location: Rochester, uk
Status: Offline
Reply With Quote
Feb 25, 2001, 06:58 PM
 
ali said:
An Objective-C program that links only against the Foundation framework... would be quite small and fast, so the answer is "it's not stupid".
Forget the foundation, link against the ObjC core! not only does it avoid any of the overheads of cocoa, you can also copy it onto any linux machine and compile with no change.

Instead of:
#import <Foundation/Foundation.h>
You instead say:
#import <objc/objc.h>
Or for the really minimalist
#import <objc/Object.h>

Then you just need to find the correct framework (somewhere in System), and add it to your project. I found it still needed to Foundation framework in the project to compile, but you don't have to use it at all.
All words are lies. Including these ones.
     
Fresh-Faced Recruit
Join Date: Oct 1999
Location: Brookline, Massachusetts, USA
Status: Offline
Reply With Quote
Feb 26, 2001, 09:53 PM
 
If you stick to Foundation, your command line tool will work just fine and will also port to other flavors of UNIX, using GNUstep. I just wrote a multithreaded SNMP-based web server load monitor in Objective-C, using the UCD SNMP library. I developed and debugged it on MacOS X PB. I was pleasantly surprised to find that, once I downloaded and installed GNUstep, the code just compiled and worked on RedHat Linux without a hitch.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:22 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2