Start with C or C++ to get to ObjC/Cocoa?

Posted:
in macOS edited January 2014
If I am starting from scratch and my ultimate goal is to know Cocoa should I start with C or should I just get into C++ ? I am willing to spend the money to start with C then move to C++ then Object Oriented Programming then onto Obcective-C/Cocoa. I would be doing this through a combination of Computer Based Training CD"s and Videos as well as the highest rated books.



I would like someone's advice though if all that is necessary. I would rather just spend the money and time starting from C++ but I've seen in other forums where it is stated that one should start with C first if they are fresh to programming.



Any advice would be greatly appreciated.



thanks
«13

Comments

  • Reply 1 of 47
    Skip C++ entirely, skip videos.



    Don't go all out, but make sure you do get into "pointers," that's what Objective-C is largely based off of.



    You'll probably only need a week or two in C, so only get one book and make sure it's easy to follow rather than "complete" or "the one book you'll ever need," because you really only need the basics.



    You can also get away with a variety of online tutorials/etc.



    If you spend too long in C, you might have to "unlearn" some things in Cocoa that will trip you up. You're really only getting the basics down so that Objective-C doesn't seem to come out of nowhere, because I don't think there's any ObjC guides that really skew towards new programmers.
  • Reply 2 of 47
    lundylundy Posts: 4,466member
    Right - forget C++.



    Learn C, learn the * notation for pointers.



    Objective-C is nothing more than C with calls to Cocoa in it.



    Once you know C, the only thing you have to learn to know Objective-C is the concept of objects and messaging.



    C++ is completely different, isn't necessary, isn't intended to be used to call Cocoa routines, and has a different approach to object-oriented programming. It will only make learning Objective-C more confusing.



    Do you already know the basics of programming, or are you really starting from scratch?
  • Reply 3 of 47
    carniphagecarniphage Posts: 1,984member
    Quote:
    Originally Posted by brent1a


    If I am starting from scratch and my ultimate goal is to know Cocoa should I start with C or should I just get into C++ ? I am willing to spend the money to start with C then move to C++ then Object Oriented Programming then onto Obcective-C/Cocoa. I would be doing this through a combination of Computer Based Training CD"s and Videos as well as the highest rated books.



    I would like someone's advice though if all that is necessary. I would rather just spend the money and time starting from C++ but I've seen in other forums where it is stated that one should start with C first if they are fresh to programming.



    Any advice would be greatly appreciated.



    thanks



    The discipline of computer programming is always re-inventing itself as programmers look for better tools to create computer software.



    C was an interesting step - creating a high-level language which gave programmers very direct control over low-level data. It was great for constructing operating systems and the history of C is tied to the creation of the Unix operating system.



    C is a language from a time when programs and data were quite seperate.



    The little-used language Smalltalk introduced a new model called Object Oriented programming. Where objects represented stuff and each object contains both data and the code designed to manipulate that data. The idea was that as programs become more complex, you can add objects to a program without having to know how the code or the data inside is organized. That's the theory.



    Both C++ and Objective C were attempts to add object-oriented features to the C language while retaining all of the benefits of C. If you asked which is better, there would be a big fight. The C++ crowd would win because they are a lot more of them.



    C++ is the more commercially significant language. There are more jobs in C++. There is some debate as to whether C++ has made programmers more productive or less.



    Objective C is closely tied to the development of the Next Step environment which evolved into OS X's Cocoa.



    I personally found Objective C easier to learn than C++. To me it reads better. And with Cocoa it is pretty easy to create applications.



    There are a couple of caveats.

    1) There is little or no use for Objective C outside the OS X sphere - although it is a good way to learn about well designed object-oriented code.

    2) Quite a bit of OS-X does not have a Cocoa interface. This means understanding "old-fashioned" C code, structures and so on. This also has been a subject of some debate.



    Learn some C and then read...

    Cocoa Programming for Mac OS X - by Aaron Hillegass - it's a great place to start.



    C.
  • Reply 4 of 47
    hirohiro Posts: 2,663member
    Man, all the C++ bashing in here. C++ isn't evil, there are just too many idiots programming in it that shouldn't be programming at all. If you do it right it's not that different from Obj-C.
  • Reply 5 of 47
    chuckerchucker Posts: 5,089member
    Quote:
    Originally Posted by Hiro


    Man, all the C++ bashing in here. C++ isn't evil, there are just too many idiots programming in it that shouldn't be programming at all. If you do it right it's not that different from Obj-C.



    It's not that different, it's just inferior.



  • Reply 6 of 47
    To everyone who replied, up until Hiro and Chucker, thanks for the advice. I'm pretty sure what road I'm going to take now.

    Thanks



    Hiro and Chucker, I appreciate your posts, even though they are not directly advisory in nature.
  • Reply 7 of 47
    kickahakickaha Posts: 8,760member
    Quote:
    Originally Posted by Chucker


    It's not that different, it's just inferior.







    QFT.
  • Reply 8 of 47
    The two books you should get are:



    1 - Cocoa Programming for Mac OS X by Aaron Hillegass

    2 - Programming in Objective-C by Stephen Kochan



    With the first book you will learn how to build GUI based applications using Xcode and Interface Builder. The second book concentrates on building command line applications (ie no GUI) so while you can use Xcode to write your code you do not need it. I use the vi editor when working with this book. Kochan takes a unique approach with this book in that he assumes no programming experience at all so he teaches Objective-C and C as a single integrated language, and from an object-oriented programming perspective.
  • Reply 9 of 47
    It wasn't until I started using VHDL that I realized how much I actually hate C. I'm not sure if Obj-C is any better, but as far as I can tell the syntax is somewhat less terse, which is a good thing.



    Anyway, it took me two semesters during freshman year at college to really grasp "C" and the way it deals with data flow in a computer. I started with essentially no knowledge of programming or computers. The primary text was "Algorithms in C" by Sedgewick, which may have been a little aggressive, but looking back I think it correctly instills the sense that good programming is responsible for massive improvements in runtime efficiency. In other words, programmers who think they can write shit code and just wait for better procesors should be shot. If you plunge into coding just knowing the language fundamentals, you will undoubtedly lump yourself in this group.
  • Reply 10 of 47
    Quote:
    Originally Posted by Carniphage


    C is a language from a time when programs and data were quite seperate.



    I think what you mean is that C is a language from a time when compilers were crude, there weren't any OSes, and fancy program stacks weren't the norm. In order for object oriented languages to exist, those must exist first, but the Von Neumann architecture had been around long before C. It wasn't since klutzy ENIAC that the Harvard architecture was the big deal.



    For the record, Linux is written in C. Most low level code is written is C because it's the better way to understand a sequential machine, which most CPUs still are. For what it's worth, C++ and objC aren't much better at realizing parallel models.
  • Reply 11 of 47
    MarvinMarvin Posts: 15,309moderator
    I personally like C over all the languages. I never got into the object-oriented mindset and C++ was a nightmare for me to learn. So much so that I didn't and started with Objective-C and found that I tried to make Obj-C programs as close to C as I could.



    One thing I don't like about C is that it's hard to do threading.



    Since Obj-C is a simple extension to C, it seemed like it would be ideal but I don't like the syntax. C# uses the standard C syntax and I think it would make it much easier to understand. I also think it's time to get rid of braces and semicolons. Python and Pascal indentation forces good code structure.



    What we really need is a language that uses common syntax, can be compiled or interpreted so used for programs or web apps, is backwards compatible with C, C++, Obj-C and is available on all platforms and doesn't have C/C++'s dependency problems. Pascal/Delphi programs compile 10 times faster than C-based ones do.



    Anyway, I would start with C and as mentioned learn about pointers because they are the biggest pains in the ass you will have to deal with when you begin. Once you understand it, it's not so bad but you still have to remember to allocate memory when it's needed and free it when it's no longer needed.



    Just for the sake of popularity, I'd actually go with C++. Objective-C is hardly used anywhere. If you are making high performance cross-platform code, it is essential. As I say, I wish there was another language that combined the best bits of all the languages.
  • Reply 12 of 47
    hirohiro Posts: 2,663member
    Quote:
    Originally Posted by Splinemodel


    It wasn't until I started using VHDL that I realized how much I actually hate C. I'm not sure if Obj-C is any better, but as far as I can tell the syntax is somewhat less terse, which is a good thing.



    Obj-C is C, in all it's messiness. Only difference is the added object type "id" and the means/syntax to handle it.



    Quote:
    Originally Posted by Marvin


    One thing I don't like about C is that it's hard to do threading.



    VERY few languages have threads at all, those are almost entirely the provence of the OS APIs (Java and ADA being two of the best known exceptions). That pretty much means it's the OS API writers that suck instead of the languages.



    Quote:
    Originally Posted by Splinemodel


    I think what you mean is that C is a language from a time when compilers were crude, there weren't any OSes, and fancy program stacks weren't the norm. In order for object oriented languages to exist, those must exist first, but the Von Neumann architecture had been around long before C. It wasn't since klutzy ENIAC that the Harvard architecture was the big deal.



    For the record, Linux is written in C. Most low level code is written is C because it's the better way to understand a sequential machine, which most CPUs still are. For what it's worth, C++ and objC aren't much better at realizing parallel models.



    C was written so UNIX could be written, although they didn't know it was going to be UNIX when they started. Thompson & Ritchie invented C language, the first high level language and the first high level language compiler all at the same time. Why, well one reason was because writing software for ATT telephone switches was abhorrently painful. Unix was the end result of a number of projects started to replace the MULTICS efforts with MIT after they saw MULTICS wasn't going to scale over the long haul.



    Now just about ALL OS kernels are written in C. It's low level enough to avoid unnecessary extra stack frame function calls and high level enough to not feel like assembler. It's also the first in a significant family of languages: C, C++, Obj-C, Java. Yes, even Java, it's roughly just Obj-C without direct access to pointers. Kinda hard to beat.
  • Reply 13 of 47
    Quote:
    Originally Posted by Hiro


    Obj-C is C, in all it's messiness. Only difference is the added object type "id" and the means/syntax to handle it.



    VERY few languages have threads at all, those are almost entirely the provence of the OS APIs (Java and ADA being two of the best known exceptions). That pretty much means it's the OS API writers that suck instead of the languages.



    C was written so UNIX could be written, although they didn't know it was going to be UNIX when they started. Thompson & Ritchie invented C language, the first high level language and the first high level language compiler all at the same time. Why, well one reason was because writing software for ATT telephone switches was abhorrently painful. Unix was the end result of a number of projects started to replace the MULTICS efforts with MIT after they saw MULTICS wasn't going to scale over the long haul.



    Now just about ALL OS kernels are written in C. It's low level enough to avoid unnecessary extra stack frame function calls and high level enough to not feel like assembler. It's also the first in a significant family of languages: C, C++, Obj-C, Java. Yes, even Java, it's roughly just Obj-C without direct access to pointers. Kinda hard to beat.



    First off, both C and C++ have their place in the community. Anyone who says one is inferior over the other does not understand the significance of both languages. As Carniphage had put, C was the idea of having a higher level language be able to interface with the lower level calls of the OS (a.k.a. Assembly). If it were not for C, languages like BASIC, Pascal, Python, etc. would have never existed.



    C++ also has its place. It brought to the table Objects, and all of the other fun stuff that Object Oriented Programming is. If you think objects are inferior, or not as good as Procedural Oriented Programming, you have not spent enough time behind the wheel of Objects. If used correctly, Objects can immensely speed up your development time, and lower the amount of time debugging. (Please notice, the bold text there.)



    Objective C is at first, an act of pure lunacy. Please note: At first. it took a while before I finally got my head wrapped around the idea of its syntax. Once you get over that hurdle, you actually start to see its strengths, including those that looked like weaknesses.



    My advice to anyone who is starting out programming: Do Not Learn Procedural Oriented Programming. That is not how Cocoa, nor OS X was framed, and it will make your life so much more difficult, unlearning the things you just learned. Learn just a small bit of C (very small), BASIC, Pascal, Java, or even PHP to get your feet wet. This will help you understand calls, variables, memory allocation/deallocation, and pointers. From there, pick up a book on Object Oriented Programming. This book should be about Theory, and not Application. Understanding what OOP is, and how everything relates with each other will save you a bunch of time. Once you have that, I would get Learning Cocoa, it is an O'Reilly book. That is a very well laid out book, and is rather easy to get into.



    I hope this helps.
  • Reply 14 of 47
    Is it really that hard to "unlearn" procedural programming? In order to do anything of value, some amount of ADTs are required, and these ease right in to object oriented methodology.



    Anyway, I'm tempted to start using Ada instead of any type of C, although I'm hesitant because there are a lot of things I don't like about Ada. Most of these have to do with the amount of services that get forced on the programmer, much as is the case with Java. Anyway, at least one recent study has been done, which shows that by virtue of using Ada instead of C/C++/C-whatever, time spent debugging goes down by two orders of magnitude. It's mostly because of the syntax. The reduction of bugs in Ada is so significant that it ends up being used in many mission critical systems such as flight control software (i.e. Boeing 777).
  • Reply 15 of 47
    kickahakickaha Posts: 8,760member
    er, Mike... anytime you write a method, you're writing a procedural program in the small. "Don't learn procedural programming"? Um, no. That's not just bad advice, it's silly. Learn every technique you can, and use them where they are appropriate.



    Hell, I've written a system that had custom hooks into gcc in C (procedural), used a 30kLOC Python (OO) app to do a bunch of data munching to produce XML which was run through XSLTs (declarative) to produce Prolog (logic) and Otter (logic) inputs, the outputs of which were converted back to XML by another Python app, and then the final results produced by more XSLT. Toss a shell script around the entire thing, and voila. One app from the user's point of view, many techniques under the hood, used where appropriate.



    That's the beauty of Objective-C: it separates the two models used internally, procedural and OO, into two distinct syntaxes. This lets each be easily identified, easily used in the proper way, and easily optimized by the compiler. Languages such as C++ that try and unify the systems end up creating a hybrid that doesn't offer the cleanliness for either style, trying instead to pretend that they are singular.



    And Hiro... Mike... I suggest you take a look at this before giving C more credit than it is due. "First high level language"? Not even close. Quick list of quite high-level languages that *predate* C showing up in 1972:



    FORTRAN (1957)

    COBOL (1959)

    LISP (1959)

    APL (1962)

    BASIC (1964)

    LOGO (1968 )

    Pascal (1971)



    Those that came out the same year:



    Smalltalk

    Prolog



    C was a latecomer, sorry. You are right that it was rather unique in that it merged high and low level access, but it was the *LOW-LEVEL* access that was its distinguishing feature. Many much higher languages had already existed for years by the time C was invented.



    And yes, OO, in perhaps its purest form in Smalltalk, came out at the same time as C. C++ wasn't to pop up for another decade.
  • Reply 16 of 47
    lundylundy Posts: 4,466member
    Don't forget PL/I - automatic syntax correction. SNOBOL for string manipulation, APL for vector work, and the uber-CISC IBM/360 assembly language.
  • Reply 17 of 47
    kickahakickaha Posts: 8,760member
    Yup yup. I actually did include APL because it just so fricking NEAT to work with. Yeah, okay, it requires a custom keyboard, but holy crap - IMO it really should be considered a granddaddy of OO because of how it made you think about data as discrete entities, and allowed really incredible use of operators in a wide variety of situations with typing. ie, overloading.



    Of course, because it was so neat to work in, and you could do so many things with it, no two programmers solved even simple things the same way, and adopted their own sets of idioms to work with. We joked that it was the Write Only Language, because nobody else could read what you'd done.



    Hmm, maybe it should be the progenitor of Perl, because of that...



    To get this back on track - brent1a, I'd go with C, not C++. Learn it's exquisite grottiness, and embrace the complete lack of a safety net. Have fun playing as close to silicon as you can get without learning hex.



    Then, if you really want to grok OO, go work with Squeak. It's a Smalltalk implementation that runs on MacOS X (and most other places you'll encounter), and it's about as pure an OO form as you can get. Of course, if your goal is just to learn Cocoa, then you can skip this part, but if instead you want to be an OO guru in general, I'd suggest it. Besides, it's fun.



    Now, take C and Smalltalk, merge them, and you have... Objective-C.



    The two books mentioned above by troberts are excellent.
  • Reply 18 of 47
    hirohiro Posts: 2,663member
    I think this is the best place to start if you want to understand Obj-C and object-orieented progrramming: Brad Cox's book.



    Kick, I'll agree to disagree with your list. It all depends on point of view as to general usefulness and the state of the languages at the times you cite them. You have a nice cross section of specialized and grandfather languages, but few of them are really "general" languages or particularly "powerful". BASIC at that time was a woefully limited "teaching steppingstone" meant to introduce new CS students to "real languages", that has since changed but it took a nearly 25 year holiday for that to happen. PASCAL and C were both basically invented in parallel with PASCAL having a few months head start but it never had the power and flexibility C brought to the table (K&R wasn't published until years after the language was in use rewriting UNIX).



    Oh well. History is always in the eye of the beholder.
  • Reply 19 of 47
    Quote:
    Originally Posted by Kickaha


    er, Mike... anytime you write a method, you're writing a procedural program in the small. "Don't learn procedural programming"? Um, no. That's not just bad advice, it's silly. Learn every technique you can, and use them where they are appropriate.



    The problem with learning both is that, as a beginner, you will tend to start getting the two confused. I started with Procedural Oriented Programming, and it made life really difficult to understand and use Objects. From a procedural standpoint, the idea that a data element could have a function is just bizarre, until you make the distinction that an Object is just like a structure, and the structure can have a or multiple functions.



    If the OP is going to be doing some serious Cocoa programming, then the best advice is to skip Procedural Oriented Programming almost altogether. Cocoa and Obj-C are both Object Oriented.



    Quote:
    Originally Posted by Kickaha


    C was a latecomer, sorry. You are right that it was rather unique in that it merged high and low level access, but it was the *LOW-LEVEL* access that was its distinguishing feature. Many much higher languages had already existed for years by the time C was invented.



    And yes, OO, in perhaps its purest form in Smalltalk, came out at the same time as C. C++ wasn't to pop up for another decade.



    I know that C was the latecomer. I knew that Pascal and BASIC came out before then. However they did not get the ability to do lower level calls until C came abut. And that is why I give C all the credit it deserves.



    Listen, the main point about this is that you will find developers (myself included) who think that [insert language here] is the best language ever, and all the others are crap. Personally, I think Java doesn't get enough recognition it deserves, but that isn't the point of this thread. brent1a, you will need a little bit of C knowledge. I would also spend a little bit of time with C++ or Java to get a handle on how Objects interact with each other. Then, I would get into Cocoa. Cocoa and Obj-C are really powerful tools, as long as you can get your mind wrapped around the idea of Objects, and how they deal with each other.
  • Reply 20 of 47
    kickahakickaha Posts: 8,760member
    Quote:
    Originally Posted by Hiro


    Oh well. History is always in the eye of the beholder.



    While true, a statement such as "first high-level language" is quite empirical. The above list show very clearly that is was not first, and it's strength was (and is) not that it was high-level, but provided access to low-level features inside a mid-level environment. It exposed the guts of the machine much more than, say, FORTRAN or even Pascal. Compared to even its predecessors, it wasn't high-level, for crissakes. It's a good language for learning how the hardware works, and because of that closeness in abstraction it has a definite speed advantage at run time. It's obviously a successful language, for those and other reasons, but "first high-level language" that "If not for C ... languages such as Pascal, BASIC, Python, etc would not even have existed"?? Not even close, sorry. Those are just factually false statements. No sense in perpetuating those to folks just learning.
Sign In or Register to comment.