learning C++

Discussion in 'Mac Programming' started by thekev, Mar 19, 2012.

  1. macrumors 603

    thekev

    Joined:
    Aug 5, 2010
    #1
    Okay sort of similar to my last thread, but can anyone suggest a good method for learning such a language? All I ever read is that it's annoying to learn. Would books be the way to go? Night/online courses? I really have no idea as my background isn't in programming.
     
  2. macrumors 68000

    Joined:
    Mar 29, 2009
    Location:
    USA
    #2
  3. macrumors 603

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #3
    Different people learn differently. Figure out what's the best learning setup for you. Personally. Not what worked for some other random person.
     
  4. macrumors 6502a

    Angelo95210

    Joined:
    Jan 7, 2009
    Location:
    Paris, France
    #4
    To learn a new language, I love the O'Reilly books which are available on Amazon. (Learning C++)
     
  5. thread starter macrumors 603

    thekev

    Joined:
    Aug 5, 2010
    #5
    With software I haven't taken a course since college (quite some time ago) so that's generally been a matter of reading books. I asked with this one because it's supposedly an annoying topic to learn. I don't expect to be writing programs or anything major. It's used in writing shaders quite a lot, and many stock ones are written in C or C++, so I wanted to be able to read this stuff properly. The post was just looking for leads or suggestions. It's not intended as a replacement for doing my own research. Anyway I just wanted to respond to that so that you don't think I'm simply lazy.

    Checking that one. Amazon seems to have more reviews. I may order that.

    That name sounds familiar. I'll look them up.
     
  6. macrumors member

    Joined:
    Sep 19, 2004
    Location:
    Bay Area, CA
    #6
    C++ Books

    If you are new to programming - start with this solid book:
    http://www.amazon.com/Primer-Plus-E...6402/ref=sr_1_1?ie=UTF8&qid=1332223370&sr=8-1
    or this one:
    http://www.amazon.com/gp/product/0201721481/ref=cm_cr_asin_lnk

    Each book is around 1000 pages. C++ is heavy duty language for professional programming with 25+ year of history. Learning C++ would require substantial commitment and time investment.

    If you are fluent in other programming language I would start with shorter book:

    http://www.amazon.com/Accelerated-C-Practical-Programming-Example/dp/020170353X/ref=pd_sim_b_1

    Good luck.
     
  7. macrumors 68000

    Joined:
    Mar 29, 2009
    Location:
    USA
    #7
    You might also want to play around with a language such as Python or Ruby to get the basics of programming before you have to deal with the very strict requirements of C++
     
  8. macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #8
    Books are the best way to go in my opinion. C++ can be boring to learn, and it does take much more effort than C or something like Objective-C so be prepared for that. In my opinion though its not near as hard as people make it out to be, its just harder to get very good at.

    Since you've never programmed before, maybe start with an easier language just to pick the basic ideas up (C is a great start). You don't have to be an expert at the easier language by any means but as long as you grasp these concepts:

    -variables
    -loops
    -functions
    -structs
    -conditional statements
    -maybe classes (depending on the language, although this can wait)

    You should be good to go for C++.
     
  9. thread starter macrumors 603

    thekev

    Joined:
    Aug 5, 2010
    #9
    Python is the other thing I'm studying at the moment, so that is covered. I have never actually come across Ruby.

    I might try C if it helps understand the other. Also I started on Python. If I recall correctly, you use many of the same programs in your work. I could always see how far I get with books before getting stuck, but I hate developing bad habits early on. That's usually a concern with any new software or workflow. Initially the purpose of this is just writing custom shaders, but I do want to take the time to learn the language effectively.
     
  10. macrumors member

    Joined:
    Sep 15, 2008
    #10
    I am twenty years in with software development and I am still finding better ways to use the language effectively. It's a never ending process. Jump on in and along your journey you will come across code/books/forums/people that will help in that goal. Just be relentless in that pursuit every single day and you will be way ahead of the curve.

    May the force be with you...
     
  11. macrumors member

    Joined:
    Aug 28, 2008
    #11
    This is pretty decent (and free):
    Code:
    http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-096-introduction-to-c-january-iap-2011/
     
  12. thread starter macrumors 603

    thekev

    Joined:
    Aug 5, 2010
    #12
    I read through the intro and a little of the second part. I'm going to look at the first couple lectures and exercises this evening.

    +1 for the Star Wars reference:D. I'm not trying to become a programmer or anything of that sort. I keep bumping into stuff that's written via C++ or Python and I wanted to better understand how the languages work rather than just memorizing details relative to a given application without that level of comprehension. I feel like that kind of learning path leads to bad working habits that become more difficult to correct later. As I noted my research isn't limited to starting a thread here (as that would be silly). It's just helpful getting a range of suggestions and sometimes warnings on common pitfalls.
     
  13. macrumors newbie

    Joined:
    Aug 8, 2010
    #13
    Howdy,

    Here is a good dvd video tutorial series called "C++ Complete" on C++ and OpenGL:
    http://www.3dbuzz.com/xcart/product.php?productid=30&cat=12&page=1

    Even though it's mainly using MS Visual Studio on Windows, they use cross platform frameworks, GLUT, wxWidgets and SDL, so following along the lessons on Mac is fairly easy. It's well worth the price.

    Adios,
    Cactus Dan
     
  14. macrumors regular

    Joined:
    Nov 18, 2010
    #14
    C++ is one of the most powerful and difficult programming languages; I know this because I'm a professional software engineer, and I write C++ code. I learned this language in undergrad, used it in grad school, and then spent many years as a professional learning best practices and idioms from my own mistakes and by reviewing other professionals' coding. This is a programming language that not too many engineers can truly master.

    From what you wrote, you want a "casual" programming language to start learning programming in general. Try JavaScript or Python to learn about functions, loops, and other programming language constructs that are applicable to almost all other languages.

    If you are serious about C++, then the best bet is to start off with a class at a local junior college where the instructor can help you learn from your mistakes and teach you best programming practices.
     
  15. thekev, Mar 20, 2012
    Last edited: Mar 20, 2012

    thread starter macrumors 603

    thekev

    Joined:
    Aug 5, 2010
    #15
    I mainly wanted the ability to write my own shaders. I am not going into what would be considered software development. I'm working on learning python simultaneously, which is something I should have done long ago, but at least I'm doing it now. It's quite popular as a scripting language.

    It would end up being a night course if I did that. Given that the summer term for such a thing would still be at least a couple months away, I do have time to review some books before then. A course does sound appealing. I'm kind of paranoid about developing bad working habits.


    Thanks but that seems like they're covering a lot of topics in a limited amount of time. For $100, I feel like I'd be better off with $100 worth of books (assuming quality books).
     
  16. chrono1081, Mar 20, 2012
    Last edited: Mar 21, 2012

    macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #16
    Hm....I may get that just for the OpenGL tutorials. OpenGL tutorials that are good are hard to come buy.

    The Blue Book doesn't really teach OpenGL anymore, it only teaches their wrapper and the Red Book is full of deprecated API's. NeHe is severely outdated so maybe I'll give these a shot.

    If anyone used these, please let me know what you thought about them, especially the OpenGL sections. I'm familiar with OpenGL but I just don't feel like I know enough of it and its hard to find good resources on.
     
  17. macrumors newbie

    Joined:
    Aug 8, 2010
    #17
    Howdy,
    The videos go from the basics (drawing a 3D cube) to creating a scene graph and working with shaders. I've gone through all of the lessons, following along using Xcode.

    Adios,
    Cactus Dan
     
  18. macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #18
    So definitely worth the money? If so I'll be buying these very soon.
     
  19. macrumors newbie

    Joined:
    Aug 8, 2010
    #19
    Howdy,

    Yes, I think it was well worth the money. You'll get C++ Volumes 1 through 5 plus the OpenGL In-Depth. The OpenGL In-Depth is 73 lessons. Of course I had to figure out how to set up the projects in Xcode, compared to them using MSVC++, but there was plenty of information on the internet to get it figured out, even for an old guy like me. :D

    Adios,
    Cactus Dan
     
  20. macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #20
    Thanks! I ordered them :)
     
  21. macrumors regular

    Joined:
    Jun 5, 2010
    #21
    Read every page of Bjarne's book, then read every page of scott meyer's books. If you are a beginner it may take several years of experience to be able to put everything together. Where's that 10,000 hours statistic I keep hearing about?

    When you are done with that, thoroughly understand boost. then you too will be a C++ guru. The reward at the end is well worth the hardships.

    Do not take shortcuts, you will write very bad code and your potential will be stunted, e.g. you will never get hired at the most prestigious firms out there.
     
  22. macrumors 6502

    Joined:
    Mar 8, 2004
    #22
    I didn't find C++ to be particularly difficult to learn. I actually had a harder time with Objective C than C++. There are a few things that will really make life easier for you:

    Don't be lazy and skip creating copy constructors, destructors & assignment/equality operators for classes that need them (those that contain pointers you need to deep copy). Being lazy is a good way to introduce subtle bugs.

    Learn RAII. Link 1, Link 2.

    Don't use heap semantics (pointers) just because its cool or fun (well except for learning projects and breakable toys) when you're better served by stack semantics; i.e. variables that will never be passed between functional units or passed as arguments to other functions. Any time you use a pointer, you're opening yourself up to the possibility of a memory leak, and when you're not dealing with some massive object larger than your stack or a large object that has to be passed to a function you're not receiving any benefit by using a pointer. Stroustrup has been trying to get this message out for years but its very hard to convince people to not throw pointers at everything (partially because pointers are what make C/C++/Obj C better than those other inferior languages :rolleyes:).

    Also related, try to pass objects by reference where possible. There are many fringe benefits besides being able to, in many cases, use simpler syntax. At the very least, remember to pass your objects as pointers so you're not creating copies left and right for no reason. Primitive types (int, bool, float, char, etc) can be passed by value.

    Learn how to use Smart Pointers.

    Learn Const correctness.

    Try to rely on composition rather than inheritance. This will be hard initially since deciding which is better is very much a decision influenced by past experience and most of your teaching material will have you creating all sorts of inheritance chains. Just keep an open mind to how you implement things and you'll be fine.
     
  23. macrumors newbie

    Joined:
    Jun 27, 2011
  24. mully1121, Apr 18, 2012
    Last edited: Apr 18, 2012

    macrumors member

    Joined:
    Dec 9, 2009
    #24
    I second this recommendation, the guy really breaks it down well and does it in short easy-to-digest blocks.
     
  25. macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #25

    You say your background is NOT is programming. All those suggestions to buy a book are only good if you DO already have a background in programing.

    Learning to program is NOT the same as learning a programming language. It is like writing a novel. You could write a novel in Spanish or English but in order to do so you h=first have to learn how to develop characters and story lines and so on.

    Class es at a community collage are the best way. Then you have access to an instructor and may get to work on projects with other students.

    If you did have a software background then I'd say to just get a reference book and use C++ on the next project and look up everything as you need it.
     

Share This Page