Coding for X in Objective C and C++
Apple seems to use Objective C religiously for coding Cocoa apps, and all their examples are in Objective C.
But, I am learning C++ and want to be able to code in C++. I know Project Builder can compile C++ (it's what I do my assignments in).
My question is, is it possible, and if so, how, can I incorporate C++ with the Objective files that Interface Builder creates.
Any help, or links to somewhere I can learn about this would be greatly appreciated.
Code Master (in training )
But, I am learning C++ and want to be able to code in C++. I know Project Builder can compile C++ (it's what I do my assignments in).
My question is, is it possible, and if so, how, can I incorporate C++ with the Objective files that Interface Builder creates.
Any help, or links to somewhere I can learn about this would be greatly appreciated.
Code Master (in training )
Comments
<strong>you can use the terminal to compile your c++ code that way you can write it normally if you don't want to have to be confined to osx. just go to the terminal and type "man cc" and it will give you the instructions on how to use it. the cc command is actually just what project builder uses. and i actually suggest to look carefuly at the objective c code. the basics in your c++ class can be better applied in an objective format. email me at [email protected] and i can give you more info. i am a senior in highschool currently taking AP Computer Science so i know where you are coming from.</strong><hr></blockquote>
how is that course?
my school just killed it due to lack of interest right before I was about to take it
<img src="graemlins/hmmm.gif" border="0" alt="[Hmmm]" />
Despite that, the tech guy at my school gave me the C++ textbook to try and due it on my own over the summer and next year.
What else does the AP CS course entail?
If you want to become a darwin/unix guru then learn a scripting language (Ruby is my choice) as well as Java or Objective-C for application development. In my opinion 'programmers' who only know one language in depth don't deserve the title.
Finally, if you are interested in becoming a professional (or commited hobbyist)programmer then I would highly recommned the best book for learning the craft of software development: <a href="http://www.amazon.com/exec/obidos/ASIN/020161622X/qid=1014375213/sr=8-1/ref=sr_8_3_1/103-9898468-0627822" target="_blank">the pragmatic programmer</a>. It changed my life - seriously (though it is aimed at those who already program rather than newbies).
Can you give a couple examples as to why C++ sucks so much?
My C++ prof told me to not bother with Objective C if I didn't need to, but it seems that Objective is the more superior form. Just from the few examples that I'm given, I can see how Objective C works and it isn't that hard, but it looks the same as C++ with different syntax to me. How is this wrong?
terminal is well and good for compiling, but if your not familiar with unix/linux then your probably not familiar with gnu cc. the man page tells you to chk the developer docs, which then tell you to use the project builder, which you should use anyway.
as far as languages go, c and cpp are the best. learning is tough on 'em though. i haven't yet tried obj-c much yet, looked at it and the syntax seemed phuqd. Java sux bug fricken donkey [explitive deleted]. It's so slow and disgusting (cip: LimeWire). I agree with bawjaws though, in that a programmer shouldn't be limited to any language. once u learned a harder one [and really know it], new ones are easy. the biggest prob i can think of with cpp is that with classes, and inheritance and that sh!t, theres overhead that you can't get around.
some1 asked about ap cs, i'm takin it now (in college) and its basic stuff: the syntax, how to make fns, they tell u what an array is, a little bit about recursion, etc. you can chk out <a href="http://www.cs.rit.edu/~cs1" target="_blank">www.cs.rit.edu/~cs1</a> for info on cs1, from Roch Inst. of Tech. I think AP cs is cs1&cs2, but it might just be cs1. @rit they're using java, but the same basic curriculum applies to all languages, just diff syntax.
the main reason that C++ sucks is (surprisingly) culture. The people who choose to program in it over other languages are making the choice based on raw power and machismo. This is all very well if you are writing an OS kernel (but if you are then why not use C and apply OO concepts) but 99.99% percent of the time the wrong decision is made for the wrong reasons.
It's like opening a pizza delivery business and equipping your delivery boys with scooters or strapping them to booster rockets. The extra power is just going to get you into trouble.
The same people who make a decison like that also overemphasise low-level speed tuning over modularity, understandability and (v. important) high level optimization. Remember the golden rule of optimisation is: don't do it. Ask a C++ programmer about it and they will bore you for hours with pointless second guessing of compiler optimisations and old wives tales that they have never tested in real-life benchmarks - just crappy microbenchmarks. Smalltalkers or Java gurus say 'make it right, then make it fast'.
NB This line of thinking did have some validity 15-20 years ago but Moore's law is making a mockery of it now and only mental inertia lets it hang on.
real example:
You can tell Java books written by C++ refugees. They are the ones that tell you the uppercase method of String is inefficent (because it supports unicode languages with strange casing rules) and you should roll your own for speed that only does ascii. The staggering idiocy of doing something like that flabbergasts me. The 80/20 rule states that 80% of your execution time is spent in 20% of your code. Even thinking about optimising before you find out which 20% is at fault is idiotic. Discussing it in a textbook before you have written a program (or learned the language) is disgusting.
bottom line:
it's horses for courses but unless your specifically aiming at a field where C++ is hanging on then avoid it like the plague. This goes double for people learning programming and developing the skills and habits of mind that will shape your future. C++ is the past, Java (and its evil twin C#) are a stepping stone to the future.
PS the main advantage of Objective-C is that it does not enforce type safety and has a great application library (Cocoa). It is these two elements that make building GUI apps a joy in Objective-C compared with Java or C++ *shudder*.
I know that you can add files of multiple types, but how do you make the classes interact with each other? Do I use Obj notation in the .m file when referring to a class in a .cpp?
bawjaws:
I have already noticed the advantage to the dynamic binding that Obj does and I like that flexibility. I guess I'll learn both and decide for myself which is better for my purposes. The fact that Apple uses Obj is a pretty good cue
I'm vaguely familiar with the command line tools. I used cc to compile my C programs last term via the command line and that worked well, but then I figured out how to make terminal based apps using Project Builder and I use that now.
Thanks for all your inputs.
The Code Master
i dont know much about obj-c, or c#, but i dont like the idea of a proprietary language. i dont know if there are unix/linux/windoze compilers for obj-c, but i'm pretty sure that c# is ms' disgusting windows-only language.
A couple of elegant and powerful languages worth learning are PHP,and steve,my current
favorite among the "little languages".
It also seems like it is by far the most commonly used so wouldn't it be best to learn the standard?
It's not the first time I have heard to stay away from C++. Several have told me to learn C and then move to Objective C and possibly Java as C++ would teach me bad habits.
Bit confused at the reasons though
So, considering I have no programming experience but definitely want to get into it deeply what would you guys reccomend as a starting language?
I still don't know what all these 'bad habits' formed by C++ are.. it would be nice to avoid them while learning C++ for school.
C is a bad choice as it is not OO. Many people think that there is a progression C -> C++ or Java cos that's how they did it but they are fundamentally different paradigms and OO is easier to learn.
reasons Java is better than C++ as a learning language:
It is more OO (though not 100%)
No explicit memory managment == no impossible bugs
No crazy pointer arithmetic, *p++ = *q++ WTF?
Junit is a great learning/programming tool
relatively easy GUIs
Popularity, (C++ has an installed base but Java has all the cool projects/buzz/mindshare and is more likely to get you chicks)
Exceptions
Interface based multiple inheritence
Standard libraries by and large are examples of good practice and OO patterns.
and many others...
At the end of the day a well written Java program will look very similar to a well written C++ program. But a badly written C++ program will look a hell of a lot worse.
For Code Master, C++ bad habits to avoid:
writing procedural code cunningly disguised as OO
lines of code shouldn't have side effects so don't use the variable++ or ++variable operator except on a line by itself.
wanting to overload an operator is a sign that you don't completely understand OO
remember, code that takes up less space on the screen doesn't necessarily run faster.
Objects, polymorphism and dynamic dispatching slow down your programs. The guys who invented them knew this and still felt is was a worthwile trade-off over 20 years ago. They were far better programmers than any of us will ever be (no offense) and had far less processing power to play with. Meditate on that the next time you attempt to 'avoid the overhead' of a dynamic method call.
avoid multiple implementation inheritence, it'll bite you in the ass when your not looking
just because it compiles doesn't mean it does what you think it does. Static type checking isn't the end of the story.
Again, (and I don't know how well this will go over with CS types) culture is important in programming. Unit testing, refactoring, code clarity, agile methodologies (like extreme programming) and advanced use of object orientation are not enforced by Java any more than they are in C++ but it is a fact that they are more prevelant in the culture and that makes it easier to learn good programming habits from the books, people, courses and source code examples that are available.
one last thing, while i'm up on my high horse. Computer Science != Software Development. If you ever find yourself reimplementing a search algorithm then give yourself a slap and use one that is available off the shelf. As someone's sig recently said when everyone reinvents the wheel you end up with a lot of square wheels.
Peace, love and sincere sympathy to any C++ programmers out there.
I know the CS department at my university has switched to starting with Java, but I'm in engineering we still do C and C++, prolly because it's headed toward very hardware level applications, though I think they just use C for that anyways.
<strong>Thanks bawjaws!
I know the CS department at my university has switched to starting with Java, but I'm in engineering we still do C and C++, prolly because it's headed toward very hardware level applications, though I think they just use C for that anyways.</strong><hr></blockquote>
yea, that's what I have seen looking through what courses are in the various engineering majors.
while I'm at it.. wat's the basic difference between Computer Science, Computers Systems Engineering and Electrical Engineering with a Computer Hardware Focus?