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 > Simple Question: Where to start?

Simple Question: Where to start?
Thread Tools
GUI Punk
Join Date: Jan 2002
Location: S.E. Mitten
Status: Offline
Reply With Quote
Jun 28, 2003, 01:02 AM
 
I've been wanting to learn how to code OSX apps ever since X was introduced and I've finally decided Im ready to dedicate the time to learning how. I have never coded before, in any language (other than html and web stuff if that can even be considered a programming language) so I need to know what would be the best way to introduce myself to OSX Cocoa programming.

For example, the first app I want to attempt will be a minimalist mp3 player.

So, any help guiding me to the right resources for this will be hugely appreciated.

24" AlumiMac 2.4ghz C2D, 4g Ram, 300g HD, 750g USBHD • 80g iPod • 160g ATV • iPhone 3g
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jun 28, 2003, 04:49 AM
 
Starting by coding an MP3 player is really not the best way to learn to program, and it's not particularly feasible. Before you can program with Cocoa, you're going to have to learn C and the Objective-C extensions to it; otherwise you'll really have no idea what you're writing. Questions will surround you, like, "What is an int, and is it anything like an unsigned double? What in the world am I supposed to do with an int *? Why won't [[int alloc] init] work?" (These really are simple questions, but the answers aren't exactly obvious.)

The best way to learn C would have to be the book The C Programming Language, written by the guys who fathered the language. Lacking that, there's also a plethora of C tutorials on the Internet, as a simple Google will show you.

After you've got the C basics down, read Apple's The Objective-C Programming Language, which is included with the dev tools documentation. It outlines the differences between C and Objective-C that you need to know, as well as the object-oriented philosophy of Objective-C. Then you can play around with their example code to get a feeling for how Cocoa works. Finally, when you're done with that, then you can start making things with Cocoa.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Senior User
Join Date: Feb 2003
Location: USA
Status: Offline
Reply With Quote
Jun 28, 2003, 08:24 AM
 
Chuckit has some good advice there. Learn the basics of C, then you should be able to start making sense of ObjC. Of course you could also write Cocoa apps in Java or C++, but ObjC is (as far as I know) the "default" language.
There are some good books available, I would grab a book on C then perhaps the Cocoa book by Aaron Hillegass.
MacBook 2.0 160/2GB/SuperDrive
Lots of older Macs
     
swiz  (op)
GUI Punk
Join Date: Jan 2002
Location: S.E. Mitten
Status: Offline
Reply With Quote
Jun 28, 2003, 09:32 AM
 
Thanks alot folks. I'll do that.

24" AlumiMac 2.4ghz C2D, 4g Ram, 300g HD, 750g USBHD • 80g iPod • 160g ATV • iPhone 3g
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Jun 28, 2003, 02:06 PM
 
An MP3 player is perfectly feasible, when you remember that you can just play MP3s through QuickTime (NSMovie does the job).
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Jun 28, 2003, 03:38 PM
 
I'd suggest NOT learning C as your first language. C is very obtuse and requires you to do a lot of little nit-picky things to get a simple program working.

Instead, I'd learn programming concepts with a good, elegant language like Python (which is included with MacOS X). Here are a couple of decent, free programming tutorials with python as the language:

http://www.cosc.canterbury.ac.nz/ACM...rog_intro2.pdf

http://www.pasteur.fr/formation/infobio/python/

There are lots more if you google for them. Python was originally created as a teaching language, so it's well-suited to the task.

Once you understand how to write a program (variables, conditionals, application flow, programming logic and constructs), then take on a language like C.
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Jun 28, 2003, 06:03 PM
 
I disagree.

I am not as good a programmer as these guys are.

But I knew nothing, and the first thing I did when I finally decided to learn was go to oreilly's tutorial page and start from the bottom.

Do them all, step by step. Do not cut and paste; type everything. Do them all, even if you think you've got the hang of it.

Get Cocoa Browser. Start randomly reading the class documentation, browsing lightly a few a day.

By the end, you will have the hang of it.

-------

I just think it's a waste of your time to spend months learning archaic, outmoded programming skills. Just go to a C tutorial site (start at "C Basics" and go down) to learn about For and If loops, pointers, and variables and you're golden. Cocoa is incredibly simple syntactically, and the real task for OS X programming, in my humble opinion, is mastering the vocabulary that is the Cocoa framworks.
you are not your signature
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Jun 29, 2003, 07:12 AM
 
Originally posted by Gametes:
Cocoa is incredibly simple syntactically, and the real task for OS X programming, in my humble opinion, is mastering the vocabulary that is the Cocoa framworks.
If your building does not have a solid foundation, it will fall down. Learning C will make you a solid all-round programmer, it'll be a good move. If you know C, and you know OO principles (which you can get from dealing with Cocoa) you'll be able to pick up most other languages at the drop of a hat.
     
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status: Offline
Reply With Quote
Jun 29, 2003, 11:47 AM
 
How are you going to learn OO principals if you start with C?

I recommend starting with Java.
signatures are a waste of bandwidth
especially ones with political tripe in them.
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Jun 29, 2003, 01:56 PM
 
Originally posted by Kristoff:
How are you going to learn OO principals if you start with C?
The Obj-C primer has an introduction, no?
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jun 29, 2003, 05:26 PM
 
Originally posted by Kristoff:
How are you going to learn OO principals if you start with C?
The same way you'll learn pointers if you start with Java, I'd imagine.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Dedicated MacNNer
Join Date: May 2001
Location: Edinburgh, UK
Status: Offline
Reply With Quote
Jun 29, 2003, 11:07 PM
 
Here are a few things I think may be useful:

Don't ask programmers how to learn how to program. They will inevitably get into a religious war about their preferred language being better than the "other" language. I know I certainly get annoyed when people say nasty things about C and everyone has a differing opinion whether based on fact or not (aimed at my Ada and Haskel lecturers from a couple of years ago).

Anyway you probably want to learn to use the best tools for the job which in the case of Mac OS X are PB/IB and Objective-C or Java. Are these the best place to start? Probably not. I would start with simple command line based Java programs. You can use a Project Builder project for this if you want but at least you won't have to learn object oriented techniques straight away. You also do not have to start with the steep learning curve of C where shooting yourself in the foot is extremely easy. Pointers can be properly learned at a later stage. Maybe when creating things like linked lists becomes second nature you could switch to C and afterwards Obj-C.
     
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Jun 29, 2003, 11:36 PM
 
You are coming from a university background on this matter, obviously. Link lists? You show me where a Cocoa program would need link lists and I'll eat my hat.
Cocoa comes with Arrays, Dictionaries, and all that stuff, so why learn the theoretical underpinnings of computer science?

I think the only things you need to learn to get started with Cocoa are

type *name = [[class alloc] init];

[object method:argument];

and how to use IB.

It's 98% of my coding.

Until you need to actually work with pointers, it's best to use them without understading them. Until you need to use the command line, it's best to never go anywhere near the thing. My friends in college spent 4 years writing functionless applications like "input your weight in pounds", learning about link lists, and primitive drawing calls. I on the other hand made a better application after 2 weeks with O'Reilly's tutorials.
Maybe I will pay for it in the long run, I guess. But I think learning the techniques needed to program in the 70s is simply antiquated in this day and age. Work with modern tools.

you are not your signature
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jun 30, 2003, 01:47 AM
 
No offense, Gametes, but I think "Don't be prepared" is pretty bad advice. If you don't know anything about the command line before you need to use it, you're liable to jump in and rm -rf your whole hard drive. Likewise, if you don't know about the language you're using, it's going to make it a lot easier for bugs to creep in and a good deal harder to sort them out.

C is a pretty small language, smaller than C++ or Java. It may seem a little oblique at first, but once you're past that initial bump, you've practically got it.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Dedicated MacNNer
Join Date: May 2001
Location: Edinburgh, UK
Status: Offline
Reply With Quote
Jun 30, 2003, 08:34 AM
 
Originally posted by Gametes:
You are coming from a university background on this matter, obviously. Link lists? You show me where a Cocoa program would need link lists and I'll eat my hat.
Cocoa comes with Arrays, Dictionaries, and all that stuff, so why learn the theoretical underpinnings of computer science?

Try writing anything substantial in C and you will understand.


Until you need to actually work with pointers, it's best to use them without understading them.
This is something you need to learn at some point or other. Its a recipe for disaster working with pointers without understanding them.


Until you need to use the command line, it's best to never go anywhere near the thing. My friends in college spent 4 years writing functionless applications like "input your weight in pounds", learning about link lists, and primitive drawing calls. I on the other hand made a better application after 2 weeks with O'Reilly's tutorials.
Maybe I will pay for it in the long run, I guess. But I think learning the techniques needed to program in the 70s is simply antiquated in this day and age. Work with modern tools.
Many of these antiquated techniques are at least somewhat useful today. You are going to write better code if you understand the programming techniques and workings of the language and machine. Remember that Cocoa can't do absolutely everything for you. I still believe it is easier to start with simple command line apps than going straight into the OO world of Cocoa.
     
Mac Elite
Join Date: Aug 2001
Status: Offline
Reply With Quote
Jun 30, 2003, 09:08 AM
 
<edit> I've changed my mind, see later post for why </edit>

A good example of basic comp-sci in use in a modern situation is the type of attack recently publicized on slashdot. It works by exploiting the fact that hash tables (dictionaries in cocoa terms) sometimes generate the same hash for two objects, degrading performance from O(1) to O(n) in the extreme case. This allows a clever attacker who knows how the hashing algorithm works to bring down a machine by creating tons and tons of hash collisions. If you don't know how a hash table works internally, it's impossible to figure out how to fix this vulnerability. Obviously this isn't a problem in very simple apps, but it seems to me that anything recieving data from the internet and using a hash table (quite a broad category, and including some fairly elementary apps) could be vulnerable to this.


btw, I don't know (exactly) how hashing works, and I don't know how good NSDictionary's implementation is. However, since I'm 17 and have never had access to a good comp-sci class, I think that's fairly understandable. I'd be shocked if I didn't know how to write my own hash table by the time I get out of college.
(Last edited by Catfish_Man; Jul 2, 2003 at 11:12 AM. )
     
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Jun 30, 2003, 12:25 PM
 
Actually, that's exactly my point. you will be able to write your ow hash table by the time you graduate; I can almost guarantee it.
The problem is that right after that, you will *never* write a hash table again because Cocoa comes with all sorts of collection classes. Meanwhile, You will not have any experience with writing a GUI app whatsoever, because after all, all good progammers should spend 4 years learning about incrementing pointers before they drag a line from a textView to a controller and push run.
Why don't we all learn how to write our own windowing system in Assembly before moving on to Cocoa? That would surely give us a better understanding of the internal workings of our computers, and allow us to prevent the dreaded char*-exploit hack.
It's because Apple did all this for us, so we can start working from higher levels of prodctivity, and not have to deal with that junk.

I can also guarantee that dozens, perhaps hundreds, of truly potentially great programmers have been turned away from Mac development because when they first tried to start programming they were told to "start with pointers, chars, and the command line." Instead of wrting a fully functional Address Book in 2 days, and feeling their confidence and skills soar, they decided programming was lame and unproductive. After all, if it takes 2 months to write a weight converter, how long would it take to write that text editor?
I know I put off programming for 2 years because my first dive in followed this advice, which stinks. The fact is that using C is 10x harder and more buggy than Cocoa. It's so unforgiving and complicated, comparatively. Just use Cocoa.

I do think, on second thought, that these skills can be valuable, for the people who will go on to write code for Apple or Microsoft, and even then only for those working on the underlying OS code like Darwin or even *MACH*

How many people will write things like Mach?
How many will write things like Address Book?

Learn the skills that you need to write your program. My experience is that that is Cocoa first, and C second. You need C, yes, but you can learn that as you go. But learn Cocoa (Obj-C) now.

The bottom line is this:
In this day and age, Cocoa is for basic programming, and C is for advanced programming.
Ironic, I know, but true. The tables have turned. Think about it.

And please forgive my militancy. I harbor no ill will towards any of you, I just get worked up over this.
you are not your signature
     
Fresh-Faced Recruit
Join Date: Nov 1999
Location: San Jose, CA, USA
Status: Offline
Reply With Quote
Jun 30, 2003, 04:41 PM
 
I thought I'd chime in with my 2 cents. I'm currently developing in Java and planning a MacOS X front end in Cocoa Java for a more native MacOS X look and feel.

I've spent a good amount of time coding in Pascal, C, C++ and Java. I've got a masters degree in computer science. I took as many computer architecture classes as I could in college to learn how a computer works. Understanding things such as spacial locality used in caching or out-of-order execution may seem oblique, but they will help you no matter what language you choose. Why? Computers work in a very particular way. I love objects and high level languages, but with anything high level, it's a lie. Knowing how a car works will certainly be useful if your day is spent trying to make it drive fast and handle real nice and easy.

My current project is in Java. I choose it due to ease of cross platform and available SDKs. However, an object rich garbage collection system is like having a rocket launcher at times when you need a pistol. For example, I have a lexicon (a dictionary) I need to read into memory and search on. One way to do this is read in each word as a String object and store them in a HashMap. But when you have 150,000 words, I quickly watched the VM heap hit well over 15 MB. That's insane considering it's around 3 MB worth of 2 byte chars. So I read all the words into a single String object. This is a great save and will keep overall memory down, as well as keep the object relationship graph small, making garbage collection faster. Then I simply built up indexes in a single int array to the start of words in the giant String (like a list of char* in C) and do binary search to find the word I want. Bingo. I now need about 3.2 MB worth of memory instead of 15+ MB. In addition, because I know binary search over such a list will be O(lg n), it will be fast. And the VM isn't clogged with 150,000 objects.

And this doesn't mean I sacrifice being "object like". I built a nice API to the class which maintains the large String and the indexes, so a caller works with it in a friendly Java way.

So what's the point of this boring story? Well, using my knowledge of comp-sci I was able to go from 150,000 objects and 15+ MB of memory to around 3.2 MB of memory and about 4 objects. Not bad. Knowing stuff about how a computer works and cost/algorithmic tradeoffs helps no matter what language, system or OS you use.
(Last edited by jobim; Jun 30, 2003 at 04:47 PM. )
     
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status: Offline
Reply With Quote
Jun 30, 2003, 05:41 PM
 
that's good optimization. Now the question before you is, would it be better for the user to have the unoptimized version of your program or no version? Gametes' point is that there are a lot of potential programmers out there that are scared off by C (who wouldn't be?), but if they were allowed to just dip their toes into the proverbial primordial bath of CS, we might get some nice apps, and though they may not be the most optimized, they would be functional. Then as those new programmers get better and more confident, they can teach themselves the more complex aspects of C with a base of understanding already.

When this thread started, I thought to myself, I took 2 C classes and one Java class in college before trying Obj-C, and they were invaluable. But now that I think about it, I took a javascript class before any of that, which let me write some fun stuff without getting bogged down with the petty details of a more powerful language. And if I hadn't had that first taste of competence I don't know if I would have made it through boring old C.
     
Fresh-Faced Recruit
Join Date: Nov 1999
Location: San Jose, CA, USA
Status: Offline
Reply With Quote
Jun 30, 2003, 06:30 PM
 
Originally posted by Uncle Skeleton:
that's good optimization. Now the question before you is, would it be better for the user to have the unoptimized version of your program or no version?
Ah, the classic struggle. The war in heaven is never over.

I think that all depends on why you're coding and who you're coding for. If I had 1 hour to build what I talked about in my last post, I would have used a HashMap, 150,000 objects and 15 MB of memory. It's all about tradeoffs. For me, my optimization didn't take long to whip up so it was done early. And it was essential to containing memory bloat since I have some other large memory hungry pieces as well. Sometimes it takes longer. Like getting Quartz to use OpenGL.

What often happens is you code something, try it, profile it and then go back and optimize it. A good endless loop to get stuck in. People always want less resource use and faster code. Just look at MacOS X's history: performance is almost always near the top of everyone's Chirstmas list.

Gametes' point is that there are a lot of potential programmers out there that are scared off by C (who wouldn't be?), but if they were allowed to just dip their toes into the proverbial primordial bath of CS, we might get some nice apps, and though they may not be the most optimized, they would be functional. Then as those new programmers get better and more confident, they can teach themselves the more complex aspects of C with a base of understanding already.
I can fully appreciate it: no jive. I started off programming in MacPascal as a kid, trying whatever I could get my hands on. So I fully sympathize. And I think with programming now becoming more accessible, developers forget there are people out there who want to play around, or need to start somewhere. And they should experiment and get their feet wet.

However, I think if you're going to be serious about developing code you should invest in some education and learn the who, what, when, where, how and why of computers and software. Programming is an art, but also a science. And I know my education has helped me write vastly better code, seeing that I was coding for about 6 years before I got to college.

But I would like to say the comments about Apple's foundation framework having arrays, dictionaries and other structs so you'll never need to fully understand or build anything like them isn't true. I've built frameworks for things like component models, GUIs, RPCs, replication and app servers. If it's one thing you're forced to learn over and over is you can't provide a hammer for every nail. I'm sure NSDictionary is great, but I'm sure it has limits. And when you reach those limits, as I did with HashMap and String in Java, you'll find all that comp-sci stuff very useful,

When this thread started, I thought to myself, I took 2 C classes and one Java class in college before trying Obj-C, and they were invaluable. But now that I think about it, I took a javascript class before any of that, which let me write some fun stuff without getting bogged down with the petty details of a more powerful language. And if I hadn't had that first taste of competence I don't know if I would have made it through boring old C.
BASIC got me into Pascal, which got me upset with fully procedural, which got me to learn objects and so forth. I agree with you. If you can't get excited about programming, then brother, why bother? It should be fun. It was the limitations of Pascal that made me want to learn C, so I could manipulate blocks of memory and do pointers without limitations.
     
Forum Regular
Join Date: Jul 2002
Location: Berkeley, CA
Status: Offline
Reply With Quote
Jun 30, 2003, 07:08 PM
 
The fact is that using C is 10x harder and more buggy than Cocoa. It's so unforgiving and complicated, comparatively. Just use Cocoa.
Correct me if I'm wrong, but.. it's not possible to create an app with just knowledge of Cocoa. Cocoa is merely an interface between the kernel and the C code. You can't write an app with just Cocoa knowledge, since the app couldn't do anything without C instructions...
     
Dedicated MacNNer
Join Date: May 2001
Location: Edinburgh, UK
Status: Offline
Reply With Quote
Jun 30, 2003, 08:34 PM
 
Originally posted by natan:
Correct me if I'm wrong, but.. it's not possible to create an app with just knowledge of Cocoa. Cocoa is merely an interface between the kernel and the C code. You can't write an app with just Cocoa knowledge, since the app couldn't do anything without C instructions...
You are basically correct. Cocoa is an interface for using some services that Apple have written (in Objective-C) for the programmer to use. Cocoa can currently be used with both Objective-C and Java.
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Jul 1, 2003, 08:17 AM
 
Originally posted by natan:
Correct me if I'm wrong, but.. it's not possible to create an app with just knowledge of Cocoa. Cocoa is merely an interface between the kernel and the C code. You can't write an app with just Cocoa knowledge, since the app couldn't do anything without C instructions...
Yes, and no. If you write anything besides a nice GUI, you'll have to write SOME C code. But Cocoa is more than just gluing an interface to C. There are lots of nice classes so that you're using NSString instead of char* for example (String handling in C is horrible compared to any modern language, so this is a godsend). Other examples are NSDictionary, NSArray, and NSDate. These classes make allocating, reading, storing and writing data a ton easier. You save tons of time with such Cocoa framework classes.
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Fresh-Faced Recruit
Join Date: Apr 2001
Status: Offline
Reply With Quote
Jul 1, 2003, 09:41 AM
 
I tend to agree with Gametes. However, I think it depends on your learning style. I am a top-down learner, so I like to see the big picture and I fill in details as I go along. Plus, learning Cocoa examples taught me C at the same time. I did have C in college 15 years ago, but never used it (nor remembered). However, I did have a good grasp of procedural programming before starting.

If you are a bottom up learner, then this style will probably not work for you. I have worked with plenty of programmers of this style to know that my style is different. They start with the minutea, I started from the other end. Also, I am comfortable with ambiguity, which most people do not seem to handle well.

I would suggest having a C book for reference and you might want to skim the basic parts on conditionals, loops, etc., but I would not get bogged down doing a bunch of C coding. Granted you may not know all the theoretical underpinnings, but at least you will produce something neat that you like. It has been my experience that people will find out what they need to know when they run into a stumbling block. Pick up the Aaron Hillegrass book, it will have you up and running in no time at all. Plus, it is well written (ie. not like a textbook).

If you find that you really like coding, you will naturally progress into the more advanced aspects of C, and probably many CompSci topics.
     
Mac Elite
Join Date: Aug 2001
Status: Offline
Reply With Quote
Jul 2, 2003, 11:10 AM
 
That's a good point about string handling in C. No one should be forced to use Char (dang German keyboard, I don't know where the star is). I'm also starting to see Gamete's point of view. I started programming with C++ (well, Object Logo actually, but I was like 8 then so I didn't do much), and spent an entire school year writing a shitty text only RPG. For physics class this year, I wrote (in ObjC/Cocoa) a graphical newtonian gravity simulator with a nice interface, save files, zooming, dragging, and moving around. It took a weekend to write the first version, then about 3 weeks so far of debugging and adding features. I have to admit, it was about 50x more fun than my previous projects, and I learned a lot (especially about how not to do memory management in ObjC ). I never had to use a char(star) or even a C array, and the only time I had to actually think about pointers was for 5 or 10 lines in the save and open methods. Other than that and a few loops and if/elses, I think it was straight Cocoa. I'm starting to think you're right about high level vs. low level. For an amateur, trying to plug obscure security holes in hash tables is not a priority. It's only the (relatively) advanced programmers that have to think about stuff like that.
     
Dedicated MacNNer
Join Date: Sep 2002
Status: Offline
Reply With Quote
Jul 2, 2003, 06:27 PM
 
For an amateur, trying to plug obscure security holes in hash tables is not a priority. It's only the (relatively) advanced programmers that have to think about stuff like that.
What? Plugging the holes left by the programmers who assumed they didn't really need to learn about how that stuff worked?
     
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Jul 2, 2003, 07:36 PM
 
Those programmers who fix the holes are the same as those who made them. I don't think they'll be angry at themselves for not having delayed program release (or even program creation) for a year while they made sure they knew every intricacy of every C memory allocation and variable interaction, when they could write the entire program right away without knowing a peep of it.
Apple gave us Cocoa. Use it.
you are not your signature
     
Dedicated MacNNer
Join Date: May 2001
Location: Edinburgh, UK
Status: Offline
Reply With Quote
Jul 2, 2003, 08:10 PM
 
May I suggest, if you wish to start "from the top," that you do not use a C based language. It will be inevitable that you will have to use some C features at some point (yes even on Cocoa) and you will end up shooting yourself in the foot and being completely unable to figure out why your program is crashing. Begin with a language like Java where you have a great selection of APIs and safety from pointer arithmetic and such like. Then when you have the necessary skills you can move on to C/Obj-C.
     
Dedicated MacNNer
Join Date: Aug 2001
Location: Seattle, WA
Status: Offline
Reply With Quote
Jul 2, 2003, 09:24 PM
 
Originally posted by Gametes:
Actually, that's exactly my point. you will be able to write your ow hash table by the time you graduate; I can almost guarantee it.
The problem is that right after that, you will *never* write a hash table again because Cocoa comes with all sorts of collection classes.
This is simply untrue. What if the provided hash table is too slow? What if this hash table is too wide for what you really want to do, which is (for example) to look up a cached glyph width from the high and low bits of a unicode character value?

This is an example of something we actually had to do in OmniWeb 4.5 in order to get anywhere near Safari's text rendering speed. What I'm trying to say is that sometimes what has been provided to you is not good enough. If some NS[Mutable]String manipulation methods are too slow, you just might have to write your own. We have.

If you don't have a working knowledge of what's going on underneath Cocoa (such as reference counting, stack/heap allocation, pointers, etc), there is no way you're ever going to:
  • Identify where the weaknesses/bugs in your program might be
  • Know how to fix them

Meanwhile, You will not have any experience with writing a GUI app whatsoever, because after all, all good progammers should spend 4 years learning about incrementing pointers before they drag a line from a textView to a controller and push run.
Upon (finally) learning how to drag a connection from an NSTextView to a controller, those programmers tend to better understand what is going on behind the scenes and thus are more able to fix problems with their GUI code when things go wrong. And things always go wrong.

How many people will write things like Mach?
How many will write things like Address Book?


Address Book wouldn't exist without Mach.

Learn the skills that you need to write your program.


This is actually good advice. However, I really do think that C should come before Objective C. Maybe it's because that's the way I did it, or maybe it's because I've seen so many people create buggy, leaky applications in Objective C because of their shaky (or nonexistent) C foundations. If you're able to create solid Objective C applications without knowing a lick of C, then congratulations. You're way above average.
Tim Omernick
Engineer, The Omni Group
     
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Jul 2, 2003, 10:42 PM
 
Originally posted by Tim2 at Omni:
This is simply untrue. What if the provided hash table is too slow? What if this hash table is too wide for what you really want to do, which is (for example) to look up a cached glyph width from the high and low bits of a unicode character value?
What I'm trying to say is that sometimes what has been provided to you is not good enough.
Yes, this is true. But I think these are advanced examples, for which one necessarily needs C, as you point out. But I stand by my amended position, which is that Cocoa is for beginning, and C is for advanced level programming, as you so ably have described.

If you don't have a working knowledge of what's going on underneath Cocoa (such as reference counting, stack/heap allocation, pointers, etc), there is no way you're ever going to:
  • Identify where the weaknesses/bugs in your program might be
  • Know how to fix them
True. But note that you say "weaknesses in your program", presuming that the program even exists. I maintain that when people start with C, this is vastly less likely to be a true condition than if with a higher level language.

Address Book wouldn't exist without Mach.
So? I said we need more address book type programmers than mach type ones. I stand by that.

I really do think that C should come before Objective C. Maybe it's because that's the way I did it, or maybe it's because I've seen so many people create buggy, leaky applications in Objective C because of their shaky (or nonexistent) C foundations.
This is an excellent point. I don't beleive anyone would have a leg to stand on if they thought my way would produce proportionately fewer buggy programs. I think it would be vastly, vastly higher. In fact, my own program is being hampered with memory management issues.
From A users perspective, It's hard to say which would be better.
200 Solid applications or 2000 buggy applications.

But as a programmer, I don't give two shakes about that. I want to program. You are just going to have to trust me to release my app when it works.



Ok I've got the definitive test:
Who would win the race from total ignorance to home-grown CD-Burnin speech-recognizing, web-enabled address book?
Cocoa or C?

It's a no contest.
you are not your signature
     
Dedicated MacNNer
Join Date: Aug 2001
Location: Seattle, WA
Status: Offline
Reply With Quote
Jul 3, 2003, 12:45 AM
 
Originally posted by Gametes:

Ok I've got the definitive test:
Who would win the race from total ignorance to home-grown CD-Burnin speech-recognizing, web-enabled address book?
Cocoa or C?

It's a no contest.
Well, since there are Cocoa APIs and frameworks to accomplish such tasks, Cocoa would obviously win (ignoring such variables as the programmer's skill level or style).

However, what if you wanted to write an application which recorded audio input from a microphone, and then used your keychain to authenticate the saving and playback of said recordings? You're going to have to drop back into C and use the Carbon (CoreAudio and KeyChain/Sec) APIs. If you started with Cocoa and never learned C, it might be very difficult for you to do so.

But in the end, it doesn't really matter. As long as the interest in programming is there, any tool you use will eventually get you where you want to be.
Tim Omernick
Engineer, The Omni Group
     
Dedicated MacNNer
Join Date: Sep 2002
Status: Offline
Reply With Quote
Jul 3, 2003, 12:53 AM
 
Those programmers who fix the holes are the same as those who made them. I don't think they'll be angry at themselves for not having delayed program release (or even program creation) for a year while they made sure they knew every intricacy of every C memory allocation and variable interaction, when they could write the entire program right away without knowing a peep of it.
The programmers who have to fix the problems could be completely different from those who made them. In the example given, it was suggested that the original programmer wouldn't even know there might be a problem - until after the problem had arisen.

As for delaying program release.... I don't like the "release now, and fix it later" attitude that seems to prevail in software writing at the moment.
     
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Jul 3, 2003, 09:12 AM
 
The only thing I like for sure is writing a productive application. All I'm saying is that all this "Learn C first" philosophy does is turn people off from the true pleasures of programming which Cocoa delivers strongly.

In the example given, it was suggested that the original programmer wouldn't even know there might be a problem - until after the problem had arisen.
Isn't this almost always the case? When they do know about it, they only release the software if the bug is minor.

and Tim: Keychain and speech recognition are being implemented in Cocoa. Yet another bastion of the ubergeek becoming more accesible to those not in the inner circle of the programming illuminati. darn. Pretty soon the only example of why I would need c will be because "Apple's AI neural-relay system's secondary nervous connection allocates bits accross multiple address spaces" and that could be tidied up a bit.
C is hard. Cocoa, what's available, is vastly easier. When you can do so much with Cocoa, why start with the hard stuff?

I bet this exact same argument went on when C first came out.
you are not your signature
     
Dedicated MacNNer
Join Date: Sep 2002
Status: Offline
Reply With Quote
Jul 3, 2003, 09:23 AM
 
Isn't this almost always the case? When they do know about it, they only release the software if the bug is minor.
That is precisely what I'm complaining about. 'Minor' is a very relative term. It is unfortunate that people prefer to complain about how much software crashes, in preference for paying for the job to be done properly in the first place. There are examples of very good coding. They are not generally found among the programs people use everyday.

I'm a bit confused by this 'programming in Cocoa' business though. I had the impression that Cocoa was just a collection of APIs and objects. It will always need another language to provide the structure of the application.
     
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Jul 3, 2003, 09:36 AM
 
Yes, it is not accurate, per se, for me to say "C vs Cocoa", as one is a langauge and the other a set of APIs written in a superset of that language.
What I am referring to is 2 things: the dominant syntax in a program written by a Cocoa or C programmer, and the available free code to such programmers.
Cocoa has the [object method:argument otherMethod:otherArgument] thing going on, which highly, highly standardizes what must be dozens, if not a hundred, different ways of acessing variables in straight C. It has all the strengths people proclaim often on this forum in addition.
Cocoa also has an amazingly large, thorough, and robustly integrated and standardized core of well-documented APIs, including a complete Application kit for all GUI-driven activity and a foundation kit for all data-driven activity.

When I say Cocoa, it is the use of these APIs and this syntax which I am referring to, instead of, well, whatever C is. I don't really know, except to say that every time I have to learn something new about C I dread the experience because it inevitably results in learning something completely, utterly unlike what I had to learn about C before. Something hard to learn, hard to understand why it is that way, hard to remember, and hardest of all: to use it without making a catastrophic error of some sort.
you are not your signature
     
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Jul 3, 2003, 09:44 AM
 
In fact, That's it. I've had enough. I've snapped. I hate C. I can't take it anymore.
I'm going to make a SDCWrapper Framework. It will include things like:
  • varNameFromString:asType:
  • assign:to:
  • for:var:from:to:
  • if:then:else:
  • switch:case:...
  • and on and on

someone put me out of my misery.
you are not your signature
     
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Jul 3, 2003, 12:35 PM
 
Well there are a lot of different perspectives on how to learn programming. Here's my opinion, admittedly biased by my college experience. Learn from the top down. Many top universities these days actually start with LISP, then jump to a moderately difficult language like Java, and finally move into C/C++ and assembly. I think this is the right approach -- if you start with a language like LISP you can learn a lot of the "big ideas" (eg recursion, iteration, abstraction, OOP, etc) without having to worry about the details of pointers, variable declaration, confusing syntax, and memory allocation. After that, move on to Java. You'll become more familiar with a C-like syntax that way without having to worry about pointers and memory allocation. Finally do C... The advantage of this approach is that you end up being somewhat language independent because you're taught to approach programming from a conceptual standpoint rather than from paranoia about semicolons and asterisks.

Of course, it's a lot easier to start this way if you're being guided by a structured program, such as at a university... If I was going to start learning programming on my own, I probably would not start with LISP. However, I would still recommend starting either with Java or with an interpreted language like Python, which lets you play around and see the results of your work immediately. Jumping right into Cocoa with no prior programming experience would be difficult, IMO. That's not to say it isn't possible, and people have done it before.
     
Dedicated MacNNer
Join Date: Sep 2002
Status: Offline
Reply With Quote
Jul 3, 2003, 01:28 PM
 
When I say Cocoa, it is the use of these APIs and this syntax which I am referring to, instead of, well, whatever C is. I don't really know...
Might not finding out before criticising be a good idea? There are plenty of reasons to laugh at C, but the above is not a good way to get heed paid to your opinions. I would imagine that you are actually programming in either Objective-C or Java, although I know few specifics of either.
     
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Jul 3, 2003, 01:56 PM
 
Originally posted by Gametes:
When I say Cocoa, it is the use of these APIs and this syntax which I am referring to
Well, to be specific, you are really referring to Cocoa and Objective-C. You can also write Java programs that access the Cocoa frameworks, but of course those do not use the same syntax.
     
Forum Regular
Join Date: Jul 2002
Location: Berkeley, CA
Status: Offline
Reply With Quote
Jul 3, 2003, 02:09 PM
 
Well there are a lot of different perspectives on how to learn programming. Here's my opinion, admittedly biased by my college experience. Learn from the top down. Many top universities these days actually start with LISP, then jump to a moderately difficult language like Java, and finally move into C/C++ and assembly.
That's exactly (LISP > Java > C) how programming is taught at the school I go to - UC Berkeley.
     
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Jul 3, 2003, 03:13 PM
 
Originally posted by natan:
That's exactly (LISP > Java > C) how programming is taught at the school I go to - UC Berkeley.
No coincidence, since that's where I went
     
Fresh-Faced Recruit
Join Date: Nov 1999
Location: San Jose, CA, USA
Status: Offline
Reply With Quote
Jul 3, 2003, 03:30 PM
 
Originally posted by Tim2 at Omni:
This is simply untrue. What if the provided hash table is too slow? What if this hash table is too wide for what you really want to do, which is (for example) to look up a cached glyph width from the high and low bits of a unicode character value? What I'm trying to say is that sometimes what has been provided to you is not good enough.

Originally posted by Gametes:
Yes, this is true. But I think these are advanced examples, for which one necessarily needs C, as you point out. But I stand by my amended position, which is that Cocoa is for beginning, and C is for advanced level programming, as you so ably have described.
Uh, those examples have nothing at all to do with C. I can do those in ObjectiveC, Java, C, C++ or what have you. I think the argument here is "ObjectiveC is doing more for the developer so has advantages over using C". In some ways, yes. And Apple ships the Cocoa framework as well, giving the developer a class library to do things for them. However, there is the tradeoff of not being able to control memory when you need it. There will be times you will have to implement things such as hashes. Why? It's a common algorithm in comp-sci. Just like B-Trees, graphs or arrays. And with any given framework or library, any implementation will have limits. Yes, limits. Which is when you need to use knowledge of the actual field you're in. In my case doing my own hashing and String management in Java saved me over 10 MB of memory and 150,000 object allocations.

If you want a starting point for a beginner, why start with ObjectiveC? Why not use RealBasic? 4th generation languages are even easier and wouldn't they be better suited for beginners than ObjectiveC? I can do things with AppleScript or with a Perl script that would be annoying in ObjectiveC. Ideally the average end user would be able to program by example, simply showing a computer how he wants it to behave, or communicate with it through natural language. But until MacOS X ships with a dynamic recompiler that will magically optimize code for underlying resources and algorithmically, you're in trouble.

That's the key: algorithmically. Yes, compilers can do loop unrolling and register coloring for you. But they won't turn a brute force search via a for() loop into a hash or a binary search. This is where you get into trouble. Cocoa classes won't rewrite themselves to suit your application if their limitations are too great for what you're building.

I find no excuse for a workman being ignorant of his tools, just as having Coca is no excuse for being ignorant of comp-sci. If ObjectiveC is easier for the average developer than C, that's nice. If it helps them realize software they want, wonderful too. And as more people use computers and want to control how they work, to be expected. However, saying only a few, such as those building an OS such as Mach, will need and use comp-sci knowledge on a daily basis is very wrong. I use comp-sci stuff all the time. As Tim did for OmniWeb 4.5. And if you're building more than a small app, you will need to be comp-sci savvy. If you don't agree, feel free to go back to the performance of MacOS 10.1. Would you be happier knowing some developer at Apple used an off the shelf Cocoa component, or built their own solution in whatever language that was more appropriate to what they were doing, and 10 times faster? Which matters more to you as a user?

If you're building small apps then you may not have to worry. But if you're a serious developer, you need to learn the field. Sorry, dude. Big chunks of my life in the working world consist of profiling and tuning code I've implemented. People like faster code that uses less memory. Go figure. And you get there via comp-sci, not blind faith in someone's language, runtime or framework.
     
Mac Elite
Join Date: Aug 2001
Status: Offline
Reply With Quote
Jul 3, 2003, 04:16 PM
 
Originally posted by jobim:

If you're building small apps then you may not have to worry. But if you're a serious developer, you need to learn the field.
Actually, that's exactly his point (as I understand it. I can't speak for him, of course). He's talking about people new to programming. Completely new. These days that often means age 14 or younger. They generally aren't making anything more complex than a fahrenheit to celsius converter, but if they can do that and make it 'cool', it might perk their interest enough for them to learn 'real programming'. I started out making the little turtle move around in object logo. It was fun. Now, I'm more interested in learning the internal details of hash tables, or whether there's a fast algorithm to remove the duplicate objects in an array or group of arrays (if someone here knows the answer to this it would be quite useful to me). A recent project of mine was to try to write a multithreaded implementation of quicksort. It was fun (although very frustrating). If I hadn't started out dinking around having fun in logo, would I be doing this? I don't know, but that's really a single case of what the disussion is about.
     
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Jul 3, 2003, 05:07 PM
 
Richard: I exaggerate. I haven't made one claim about C that doesn't come from personal experience. I know all about variables, pointers, data structures, flow controls, and that kinda general stuff. But beyond things like command line apps, I haven't a clue (real C programming).

itai: Yes, that's even more precise. Thank you.

jobim: I wouldn't disagree with you. But where should beginners start? I say easy stuff first, and hard stuff later. If that means realbasic, then ok. But for me, Cocoa programming was just easy enough that I could start there, and learn C as I went along. This way I don't have to learn to program, then learn to program all over again when I want to make real applications for OS X.

How do people write applications in OS X? In Java or Obj-C Cocoa. My advice to all beginners is: start with the tools you will use.
If you want to write Python apps, start there. If not, don't touch the stuff. Same for RealBasic, same for Cocoa, same for plain C.
Learning from scratch myself in only Cocoa, I can say that it is my opinion that Cocoa in Obj-C is easy enough to learn that from Oreilly's tutorials you can become a self-educating Cocoa programmer in vastly shorter time (and with 10x the fun) than if you start with C.
you are not your signature
     
Dedicated MacNNer
Join Date: Sep 2002
Status: Offline
Reply With Quote
Jul 3, 2003, 05:16 PM
 
But beyond things like command line apps, I haven't a clue (real C programming)
Command line apps aren't real programming. Seems a strange definition.
     
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Jul 3, 2003, 05:22 PM
 
Can we stop nitpicking. I think you all know what I mean.
I want to address what programming environment will make new developers learn faster, or allow them to be productive sooner, or let them enjoy programming more, or etc etc.
(Last edited by Gametes; Jul 3, 2003 at 09:07 PM. )
you are not your signature
     
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
Jul 3, 2003, 08:44 PM
 
He means to say that command line apps are real programming. There's no real and fake programming, unless you're talking about writing HTML, which isn't really programming
     
Dedicated MacNNer
Join Date: Sep 2002
Status: Offline
Reply With Quote
Jul 4, 2003, 04:09 AM
 
I want to address what programming environment will make new developers learn faster, or allow them to be productive sooner, or let them enjoy programming more, or etc etc.
Well, so far as I'm concerned, Cocoa is nothing but a way of frittering away CPU cycles which could be more put to more productive use elsewhere. Different people have different needs. None of this changes the fact that loops, conditionals, procedures etc. are to do with programming languages, and not Cocoa itself.

And, even if things like hash tables are provided by ones framework/API, it's still a very good idea to have some idea about how they work. Ignorance, deliberate or otherwise, has a habit of coming back to haunt people.
     
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Jul 4, 2003, 08:47 AM
 
Originally posted by Richard Edgar:
Well, so far as I'm concerned, Cocoa is nothing but a way of frittering away CPU cycles which could be more put to more productive use elsewhere. Different people have different needs. None of this changes the fact that loops, conditionals, procedures etc. are to do with programming languages, and not Cocoa itself.

And, even if things like hash tables are provided by ones framework/API, it's still a very good idea to have some idea about how they work. Ignorance, deliberate or otherwise, has a habit of coming back to haunt people.
This thread is turning out to be a heck of gang fight!



Now, I feel compelled to jump in and defend Cocoa's honor.

Cocoa is just a bunch of Objective-C code which is has and is still being tweaked/optimized since the days of NeXSTEP. If you are going to use some kind of framework (and you should otherswise you reinvent the wheel) then one like Cocoa is a dream come true.

As overhead goes. The objective-C runtime is not a significant performance tax.

Sure you can find C code to convert from pounds to kilograms and it will likely work faster than the Cocoa version but heck just don't try to build something like iPhoto from scratch in C. There's no way you can beat the many years of effort that talented folks have put into Cocoa. Avoiding using a framework is just plain unwise -to put it very midly.


(Last edited by DaGuy; Jul 4, 2003 at 08:53 AM. )
     
Mac Elite
Join Date: Aug 2001
Status: Offline
Reply With Quote
Jul 4, 2003, 09:21 AM
 
Originally posted by DaGuy:
This thread is turning out to be a heck of gang fight!



Now, I feel compelled to jump in and defend Cocoa's honor.

Cocoa is just a bunch of Objective-C code which is has and is still being tweaked/optimized since the days of NeXSTEP. If you are going to use some kind of framework (and you should otherswise you reinvent the wheel) then one like Cocoa is a dream come true.

As overhead goes. The objective-C runtime is not a significant performance tax.

Sure you can find C code to convert from pounds to kilograms and it will likely work faster than the Cocoa version but heck just don't try to build something like iPhoto from scratch in C. There's no way you can beat the many years of effort that talented folks have put into Cocoa. Avoiding using a framework is just plain unwise -to put it very midly.


This is all true in MOST cases. As has been mentioned earlier in the thread, the Cocoa hash table implementation wasn't fast enough for Omniweb's text handling. I'd call that an excellent example of advanced programming requiring lower level programming. Frameworks have their limits, and when those limits are reached, you have to do it yourself.
     
 
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 03:45 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