 |
 |
Some Questions from a Newbie
|
 |
|
 |
|
Professional Poster
Join Date: Jul 2001
Location: Dis
Status:
Offline
|
|
I'm trying to get in to programming, but I'm finding that I have a few obstacles on Mac OS X. For starters, printf in C and cout in C++ seem to be broken. The problem is that they only display text when the program terminates. For instance:
printf("Enter a value: ");
scanf("%d", &x);
or
cout << "Enter a value: ";
cin >> x;
don't work. The screen will simply be blank and the user will just have to know what to do. I have figured out that I can fix printf with fflush(stdout) after my printf statements, but that's a hassle. I haven't figured out a way to fix cout.
Is there some technical reason why Cocoa doesn't support C++? My dilemma is this: I already have a good amount of experience with C (in the command line, that is), so Objective C was attractive at first, but the messaging syntax does not follow the mathematics-like syntax that made C, and make C++, so attractive to me. Java seems like a reasonable alternative, but I don't have any experience with in it, and it would require me to learn all new terminolog, functions, and I don't have a good book for it yet. I also don't like Carbon because I'm new to GUI programming (and setting up Cocoa in IB nearly builds the app for you  ). Will Cocoa support it in the future? What is this Objective C++ I've heard about? Why would you want to add any more extensions to C++?
Thanx 
BlackGriffen
|
|
I do not feel obliged to believe that the same God who has endowed us with sense, reason, and intellect has intended us to forgo their use. -Galileo Galilei, physicist and astronomer (1564-1642)
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Originally posted by BlackGriffen:
<STRONG>don't work. The screen will simply be blank and the user will just have to know what to do. I have figured out that I can fix printf with fflush(stdout) after my printf statements, but that's a hassle. I haven't figured out a way to fix cout.</STRONG>
The cout bug is well known (i.e. it doesn't flush unless you output a newline), and has been discussed several times before (search the archives). I have had no such problems with printf(), in fact I just checked and the following code works fine:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>#include <font color = red>"stdio.h"</font>
<font color = green>int</font> main (<font color = green>int</font> argc, <font color = green>char</font> *argv[])
{
<font color = green>int</font> blah;
printf(<font color = red>"FOO: "</font>);
scanf(<font color = red>"%d"</font>,&blah);
printf(<font color = red>"\nYou entered: %d"</font>,blah);
<font color = green>return</font> <font color = blue>0</font>;
}</font>[/code]
<STRONG>Is there some technical reason why Cocoa doesn't support C++?</STRONG>
Yes. Cocoa has at its heart lots of runtime typing and archiving of objects and so on, and uses various other aspects of the ObjC runtime that just plain don't exist in C++. C++ is too static for Cocoa.
<STRONG>My dilemma is this: I already have a good amount of experience with C (in the command line, that is), so Objective C was attractive at first, but the messaging syntax does not follow the mathematics-like syntax that made C, and make C++, so attractive to me.</STRONG>
I'm not with you here. Obj-C's messaging syntax is perfectly good, I don't really see how you can have problems with it, it's just different. Use it for a while and see if you get used to it.
<STRONG>Java seems like a reasonable alternative, but I don't have any experience with in it, and it would require me to learn all new terminolog, functions, and I don't have a good book for it yet. </STRONG>
Also, there are various issues with Java as a language for developing Cocoa in (slow, bloat of a massive vm, seems like there's a longer development time too).
<STRONG>Will Cocoa support it in the future? What is this Objective C++ I've heard about? Why would you want to add any more extensions to C++?</STRONG>
Objective-C++ lets you mix Obj-C with C++. It will not let you treat Obj-C objects as C++ objects and vice versa, but it will, for example, let you use your C++ model objects in a Cocoa app (so you can have a Controller class that will call both C++ code for processing data and Obj-C code for displaying the GUI). Currently, you have to create horrible glue code in C everywhere, and this basically puts of people with large codebases from porting to Cocoa.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status:
Offline
|
|
If you really want to use C++ directly, you could take a look at the Carbon API.
As for actual languages, Obj-C and Java will come very easily if you know C. I knew C and Java and picked up Obj-C in a week or two on the side. Obj-C is really nice and I really came to like it. I don't know what the overall consensus has been, however.
Actually, knowing Obj-C gave me the edge in a recent Scheme assignment I had to do for my CS class. It is useful to have experience with these different syntactic paradigms.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Jul 2001
Location: Dis
Status:
Offline
|
|
Originally posted by Angus_D:
The cout bug is well known (i.e. it doesn't flush unless you output a newline), and has been discussed several times before (search the archives). I have had no such problems with printf(), in fact I just checked and the following code works fine:
Thanks, I just checked and the printf bug seems to be restricted to running the code within Project Builder.
I'm not with you here. Obj-C's messaging syntax is perfectly good, I don't really see how you can have problems with it, it's just different. Use it for a while and see if you get used to it.
I never said there was anything wrong with it. There's nothing wrong with AppleScript, but I have trouble with its syntax too because it doesn't follow a mathematics like paradigm.
Apocolypse wrote:
If you really want to use C++ directly, you could take a look at the Carbon API.
I know, I guess it comes down to laziness and the fact that I've already spent $30 for a C++ book. Objective C would probably be eaiser to pick up if I had a better background in OOP... I actually started out learning in C++, not C, but I never got beyond using it as a non OOP language, you could have literally substituted printfs and scanfs for my couts and cins.
Thanks for the help, I'll probably dig in to carbon since doing things the harder way the first time will give me a better learning experience  .
BlackGriffen
|
|
I do not feel obliged to believe that the same God who has endowed us with sense, reason, and intellect has intended us to forgo their use. -Galileo Galilei, physicist and astronomer (1564-1642)
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Originally posted by BlackGriffen:
<STRONG>Thanks for the help, I'll probably dig in to carbon since doing things the harder way the first time will give me a better learning experience  .</STRONG>
I would really advise you against doing this. Cocoa is such a joy to program in, and the development time for an app is much smaller than a Carbon app (in general).
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|