Objective-C dev here: Should I buy a C or C++ book? Which one?

Discussion in 'Mac Programming' started by moonman239, Dec 18, 2015.

  1. moonman239 macrumors 68000

    Mar 27, 2009
    I started Objective-C programming without much of a C/C++ background (as in, I hadn't gotten past "Hello World"). Now, I consider myself pretty junior as I started Obj-C 3 years ago. Lately, I've been getting into pure C programming, but I've been reading about C++ and how it is apparently better than C. Now, I should tell you that I've expressed some interest in the computer science industry. Having said that, would my time be better spent reading a C book or a C++ book? Which one should I get?

    So far, I have two candidates:
    -"The C Programming Language" by K&R
    -"The C++ programming language" by Bjarne Stroustrup
    I've also taken a look at some kind of book about algorithms w/ programs written in C.
  2. balamw Moderator


    Staff Member

    Aug 16, 2005
    New England
    Which books did you use to learn Obj-C? I find both of these a bit "dry" for my taste.

    Depends on what resonates with you.

  3. Senor Cuete macrumors 6502

    Nov 9, 2011
    In my opinion you should learn C first. I like:

    A Book on C by Kelly and Pohl

    Objective C is a superset of C. It is a simple set of extensions to the C language that allow it to be used for object-oriented programming. If you know C you will be able to pick up Objective C in a few hours. Then read:

    Cocoa Programming for Mac OSX by Hillegas, Preble and Chandler.

    This will teach you to write a proper Mac application.
  4. moonman239 thread starter macrumors 68000

    Mar 27, 2009
    Well, except that I already have experience with Objective-C. In fact, I'm building an iOS app with delegates, notification observers, and other stuff.
    On the C side, I've been working on kind of replicating NSDictionary. For this task, I've created my own hash function and two data structures. (Unfortunately, as of yet, this work is incomplete.)
  5. mfram macrumors 65816

    Jan 23, 2010
    San Diego, CA USA
    Keep in mind that some of the rules for C++ are a little different than the rules for C. And since Objective-C is a strict superset of C, the C++ stuff may not apply. There's two ways to look at your question. If you want to get better background of C part of Objective-C, then read a C book. If you want to read about a different object-oriented C-based language then read about C++. But the C++ knowledge won't directly have anything to do with Objective-C.

    You'll probably want to learn some C++ (and other languages) at some point.
  6. balamw Moderator


    Staff Member

    Aug 16, 2005
    New England
    I ask again, what books and other resources have resonatd with you?

  7. hokan macrumors member

    Mar 18, 2014
    Which you should choose to look at depends on what your goals are:
    • OSX/iOS APIs are mainly in Objective-C/Swift. Some like FSEvent are in pure C. None are in C++.
    • Reading up on C will help you when dealing with low level APIs, traditional Unix APIs and high performance code when working on a OSX/iOS/Unix style OS.
    • C++ fills a similar role as Objective-C, as they are both originated as extensions on top of C, that add object orientation, among other things. They differ in their basic philosophy Objective-C is a more dynamic (Smalltalk inspired) language which trades some performance for being more flexible at runtime while C++ lacks runtime flexibility but is designed to perform closer to plain C.
    • Objective-C is effectively a Apple (OSX/iOS) only language, while C++ is common on most platforms and can even be integrated with Objective-C as Objective-C++.
    • C is simpler/smaller/has fewer features than C++/Swift.
    • Objective-C is a fairly small extension on C, C++ adds a lot more features and complexity.
    • Swift is in many way a cleaner and simpler version of C++.
    "The C Programming Language" by K&R - this is the classical C manual, but I've seen a fair amount of people recommend to avoid it, as it is not current with modern C and recommends outdated practices.

    "The C++ programming language" by Bjarne Stroustrup - I've read parts of this (a Swedish translation) and found it unstructured and somewhat rambling - I generally prefer a more reference style manual with subjects split into clear sections.

    The following print book page counts can give a rough estimate about the complexity of each language:
    • "The C Programming Language" is about 260 pages.
    • "C - A Reference Manual" - my personal C reference (which I don't recommend as book to learn C) is 530 pages.
    • "The C++ programming language" is 1260 pages long.
    • The "The Swift Programming Language (Swift 2.1)" is 720 pages when viewed in iBooks on a 1680x1050 screen. These pages feel smaller and appear to show less text than the books above, so the actual page count may perhaps be closer to ~500 pages.
    ps: an algorithms book is also a good choice and should generally age much better than a programming language book.
  8. ArtOfWarfare macrumors G3


    Nov 26, 2007
    What do you want to do?

    Learning a language takes a few hours. There's not that many concepts in any of them. They're all share a lot of concepts with each other.

    I had zero experience with C#, but I decided I needed to write in C# for my next Unity project since Unity has deprecated Boo (which was the language I was previously using for Unity projects.) The transition took literally no time. I just started writing code. The code looks like C++, because I don't know C#, but each time I get a compiler error, I look it up, find the difference between how C++ does something and how C# does it, and move on.

    Learning new languages isn't remotely hard. Come up with an actual thing you want to make, and make it in whatever language seems appropriate.
  9. moonman239 thread starter macrumors 68000

    Mar 27, 2009
    Off-topic: I did some C# stuff, too. To me, it feels like Java.
    On-topic: Is it worth it to buy any kind of C/C++ book? I mean, we do have the Internet.
  10. ArtOfWarfare macrumors G3


    Nov 26, 2007
    Yeah, you're right. It feels more like Java than C++.

    No. The Internet exists to disseminate knowledge. Books are a relic of the past that need to be digitized and uploaded, if they haven't already, and then recycled.
  11. gnasher729 macrumors P6


    Nov 25, 2005
    You might consider downloading the Swift books instead. And google for "C Standard Draft" which should find the latest draft of the C language Standard (which is practically the same as the C Standard, except the C Standard costs > $100). Same for "C++ Standard Draft".
  12. jasnw macrumors 6502a


    Nov 15, 2013
    Seattle Area (NOT! Microsoft)
    I'd suggest giving the C Standard a miss, unless you need something to help you get to sleep. I learned C from the K&R book many years ago, but it is a bit dated. Have you taken a look at on-line resources for the purpose of learning the language? A good starting point might be https://en.wikibooks.org/wiki/C_Programming.

    As for C++, if your interest is Objective-C trying to wrap your head around C++ will just make your head hurt with little gain. I'd stick with becoming more knowledgeable about C programming and focus on Objective-C books.
  13. firewood macrumors 604

    Jul 29, 2003
    Silicon Valley
    There are people who've spent years learning C++ (the advanced C++ books can be very thick), and still don't know anywhere near all the details in the full spec and all the gotchas within typical implementations. It's not uncommon for one advanced C++ programmer to write perfectly legal C++ code that another experienced C++ programmer can barely read, if at all.

    Thus, if you already know some Objective C for the OOP requirement, I recommend learning C.
  14. oldtime macrumors 6502

    Nov 27, 2007
    Definitely give K&R a pass. I really liked David Kochan's Programming in C.
  15. thisismyusername macrumors 6502

    Nov 1, 2015
    I consider both of those to be classics for their respective languages and worth reading. I also suggest Scott Meyers' Effective C++ and related books if you want to really get into C++ (every C++ programmer should read those).

    It can take years to master a language. To say that you only need a few hours is quite frankly naive.
  16. ghellquist macrumors regular

    Aug 21, 2011
    Stockholm Sweden
    Yes and no. There is a large group of languages that are similar as they are imperative with variables and procedures. There are a lot of quite different types of languages. Here are some challenges for you to learn in a few hours:

    very not c-type procedural
    Haskell (will take more than a few hours to get your head around this) -- https://www.haskell.org
    similar, but different: ocaml -- https://ocaml.org
    sml -- http://www.smlnj.org

    This is partly old history but extremely important still, not learned in a few hours
    lisp -- https://en.wikipedia.org/wiki/Lisp_(programming_language)

    ooh, this one i love, especially the create ... does words: forth -- http://www.forth.org
    or why not good old sql -- http://www.w3schools.com/sql/

    check this one: http://listverse.com/2011/02/17/top-10-truly-bizarre-programming-languages/
    --- Post Merged, Jan 6, 2016 ---
    Sorry about the digression in my previous post, not really helping the OP.

    Personally I would suggest staying away from c++. Really learning that is going to be a quite long and tedious adventure, more on the time scale of several years. In my mind c++ simply is too complicated to really learn unless you aim at getting employment at a fully c++ shop (not too many of those around). It also seems like it is sort off the main line as it is not used much in web development.

    If you want to learn low-level basic C, which is good for some things, say embedded computers, the K&R book is the one to go for.

    But today, the computer language used really is the small part. The environment with library functions is really the large part. It is different writing for windows, os x, iOS, web browser, web back-end -- all of these rely heavily on calling library functions.

    My suggestion then is to select one environment, and learn the details of that one. Select a language much used there and learn the environment together with the environment. Most of us (it seems to me) have stopped buying books as almost everything can be had from the net.

  17. ArtOfWarfare macrumors G3


    Nov 26, 2007
    Haskell and ocaml are different. I've never really taken the time to dive into them, but, to the best of my knowledge, you will never need to know those languages. Nobody uses them professionally.

    I do know Lisp. It's a pretty simply language... Took me a few hours to learn. I would say Python was the most useful language to know prior to learning Lisp, since currying is pretty easy in Python. I wrote currying code in Python before I even knew it was a thing.

    I've heard of forth, don't know what it is.

    SQLs biggest problem is a lack of good learning materials, coupled with the fact that every single DB implements its own changes to the language, which makes it so that you never really learn SQL, but end up learning the variant of SQL for your DB instead.
  18. touchUpInside macrumors member


    May 4, 2014
    UTC -07:00
    Can anyone recommend a means to run LISP on a MAC ? I'd like to run some of the examples from the classic book Structure and Interpretation of Computer Programs. Would Clojure work ?

    Thanks for any suggestions.

    Cheers !
  19. ArtOfWarfare macrumors G3


    Nov 26, 2007
    You could use Dr Racket.
  20. touchUpInside macrumors member


    May 4, 2014
    UTC -07:00
    Just what I was looking for !
    Thank you !!
  21. stoshb macrumors newbie


    Jan 6, 2016

    Books are very old school. I have found best, and only, way to learn a new language is to come up with some task that needs to be done and pick your desired environment. This then determines what you need to know, so start programming. Just remember that Google is your extremely good, but cryptic friend.

    Picking a task is the difficult part. However, I have developed a set of tasks that I keep reprogramming into different language/environment. For instance a few years ago, I wrote a web based app using pop, then added a big JavaScript layer, and am now rebuilding it into a collection of obj-c code running on a network of macs and iPhones. Probably will rewrite into Swift some time to get a feel for that.

    Another task is download data from your bank account to report your lousy bank account in a different format.

    Using this techniques, I have learned the big names like assembler, basic, fortran, cobal, c, pearl, pho, JavaScript, plus a number of niche languages lik mumps. Found a few instances where I have given up such as with Java. But, have earned a good living with this technique.

    Best to just start and learn as you go. There are so many good free resources on the Internet. Most of the languages/environment are free so take advantage of that. Because it is UNIX based, the Mac is a great help as there are so many options available.

    Most importantly, just start doing it and when one road is blocked, go a different direction.

    Have fun.
  22. 960design macrumors 68030

    Apr 17, 2012
    Destin, FL

    What are your goals? What are you trying to accomplish by learning C or C++? Learning Japanese is great, but if you ask a forum of Koreans which language to learn, you will get a narrowed view, due to the vagueness of the question.

    Most of us lean towards OSX in this forum, so my recommendation would be to learn Swift 2.0; especially since it is open source: https://developer.apple.com/swift/blog/?id=29

Share This Page