Starting to learn to program. (C++)

Discussion in 'Mac Programming' started by Astroblu, Jan 26, 2013.

  1. macrumors newbie

    Joined:
    Aug 3, 2012
    #1
    Hi, I'm currently trying to learn how to program. I'm 15 and I only know basic Java. I've decided to attempt C++ but I have no idea how to start, I will try look up some tutorials and maybe buy a book about it but what I'm really asking is what can I use C++ for? I have a mac and I know that Xcode has an option for C++ but what kind of things can I do with the language after learning it? I just struggle trying to grasp the whole concept of a programming language and I'd really like someone to explain it to me. I'm not sure if I explained what I'm trying to say very well but if you understand, can you please help!
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    You can do anything with C++. You can do anything with Java. The edge cases are generally interaction with the OS or hardware, and that's not something you should worry about right now. Is there something you need to do that Java can't handle? Is there something that you feel you need C++ for? There's nothing wrong with learning a new language, but it might just confuse things for you right now. I think a more important question than what C++ can do is what do you want to do? If it's learning a new language, then C++ will work. If it's something else, maybe there are better options.

    -Lee
     
  3. ytk
    macrumors regular

    Joined:
    Jul 8, 2010
    #3
    That's like saying “I'm learning to fly and I'm attempting to start on a 747”. I know a bunch of people here will disagree with me, but having started pretty much the same way as you (nearly two decades ago), I'd say you'd be much better off tackling a higher level language like Perl, Python, or Ruby first. Personally, I'm a fan of Ruby, but I can see a good argument for Perl or Python as providing a more “traditional” approach to programming (Ruby does a lot of things differently from—and in my opinion, better than—most other languages).

    Higher level languages take care of a lot of the low-level stuff like declaring variables and memory management for you, so you can focus on learning the theory of programming. There will be a time in your programming career (whether or not you pursue it professionally—I never did) when you will want or need to learn about pointers, type conversion, memory management, and other concepts that I would describe as things you just need to know because you need to know them, not because they necessarily have anything to do with the art of writing code. Understanding those things will make you a better programmer, but they are very hard to grasp for newcomers, and your time is better spent learning the basics like functions, control structures, and objects. You'll make much more progress more quickly with a higher level language, and more importantly you'll understand what you're doing, rather than simply copying code out of a book because the book says to do it.
     
  4. macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #4
    I would start by focusing on something you want to make.

    There are an almost infinite number of ways to go. So the problem is that you will get lost in the options and never get very far in any direction. If you focus on the goal (especially if it's something you want to do, because you won't have to struggle as much with motivation) -- you can pretty much figure out which way to go without wandering too much. ("Wandering" is not exactly a bad thing when you are learning, but you need to go somewhere at some point too.)

    So I suggest: pick something you want to make, post it here, and (most) people will give you good and specific advice on a path to accomplish it.
    Keep your first goal very modest, because there is plenty of software development stuff you will have to learn even for a simple goal.

    E.g., if you are generally interested in programming games, start with tic-tac-toe or whatever, not Assassin's Creed 3.

    All that said, I'll give you my perspective (as a C++ programmer for about 20 years): You can use C++ to develop almost anything. For performance-critical things it's not too hard to write code that compiles to very efficient machine code. And it supports a wide variety of high-level concepts for higher-level code. However, it has some drawbacks: (1) it is very difficult to master. It will let you do things wrong in so many ways it takes a long time to learn how not to do things wrong; (2) I don't think you can say it is the "native" language of any major application platform. E.g., it is possible to develop Mac OS X apps using C++, but realistically you will probably end up doing Objective-C++ (which is roughly C++ combined with Objective-C) because a lot of the frameworks the you will want to use to work with OS X are Objective-C. And if you're going to use Objective-C frameworks, it's usually a lot simpler to just use Objective-C.

    In my opinion, C++ is difficult to master and has become a niche language, so I wouldn't make it one of the first languages I learned. If you are interested in OS X or iOS, I'd go to Objective-C, for Windows, I'd learn C#, and for Android, I'd continue with Java.
     
  5. ArtOfWarfare, Jan 28, 2013
    Last edited: Jan 28, 2013

    macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #5
    Interesting. I agree with your assessment of Objective-C for OS X/iOS and Java for Android, but C++ is a niche language and C# is what is used for Windows? I'm a Computer Engineering student and I don't know anyone who knows C# but I know plenty of people who only know C++.

    My understanding is that you can't write native code for Windows (everything is run by a virtual machine, regardless of language) so I just use Java given all its performance problems go right out the window if everything else is going to be run in a virtual machine just the same anyways. I might be mistaken, though – I hardly have any experience with Windows at all... what I stated is what I found from Wikipedia.

    I think learning higher level languages first is the wrong approach. I think you should learn C first... nothing is handled for your automagically. You have a decent idea about what exactly is going on on your computer when your code is executing. I think assembly might be better still, but it's so platform dependent and the odds of you ever needing to work with it directly are slim to none.... so... learn C first, is my suggestion.

    I suggest learning from Learn C The Hard Way:

    http://c.learncodethehardway.org/book/
     
  6. macrumors 65816

    Joined:
    Apr 17, 2012
    Location:
    Destin, FL
    #6
    Writing Java since 1996, works on everything, can do everything my little mind can imagine. Java protects you much better from developing bad habits that can lead to huge headaches of C++ ( although those headaches, when done properly is what makes the code extremely fast ).

    Java is very much like C++. Focus on getting java perfected, then when you wish add C++. It will be a very easy transition, plus you'd have solidified good programming habits.

    If you want to code for Mac, you need to learn Objective-C. Objective C is not really much like C++ at all. Objective C is exactly C with additional libraries. Pure C will compile under XCode, but C++ will not.

    I currently do web and mobile developemnt, so I use a smattering of Java, Objective-C, and PHP ( I think that is all, that is all I used so far today, anyway ).

    Pick a project and start working on it, when you get stuck, post your code and ask your questions. We like answering, it makes us feel smart.
     
  7. macrumors 6502

    Joined:
    Sep 13, 2010
    #7
    Whatever you read, it was either incorrect, or you misunderstood it. Didn't you find it at least a little hard to believe that you "can't write native code for Windows"?

    Just learn C++. It is almost a proper superset of C, and Stroustrup was fond of noting that every program in K&R is a C++ program. The question really should be, do you want to learn procedural programming vs. OOP or generic programming? That will dicate your focus in C++. I can't think of any more pointless approach than to learn assembly language first.
     
  8. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #8
    This. The language is a bit of an afterthought, a means to an end. What is your goal?

    If you already know some Java, stick with it until something you want to do with it is easier to do in another environment/language.

    B
     
  9. macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #9
    I was/am still under the impression that all applications written in C#, VB.NET, or any other language were compiled to CIL bytecode, which the CRL then interprets at execution time... with the CLR being a virtual machine not unlike a JVM for Java bytecode.

    Here's the page that makes me think that:

    http://en.wikipedia.org/wiki/Common_Language_Runtime
     
  10. balamw, Jan 28, 2013
    Last edited: Jan 28, 2013

    Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #10
    This is generally true for those languages, but Visual C++ can generate either managed code under the CLR or not (a.k.a. "native" Win32 applications).

    http://en.wikipedia.org/wiki/Managed_code

    EDIT: I think one additional wrinkle here is that "Metro" apps are all managed. That's how they can work on both x86 and ARM/RT.

    B
     
  11. macrumors 6502

    Joined:
    Sep 13, 2010
    #11
    C++/CLI was a major improvement over the original managed extensions, but I don't know to what extent it caught on. I think most people writing managed code use C#. C++ remains the primary language for native code. Most of the programs I use day to day are native code.

    Sounds right, but I'm happily mostly ignorant about "Metro" and plan to remain that way.
     
  12. macrumors member

    Joined:
    Jun 1, 2005
    Location:
    London, UK
    #12
    I believe you can write Metro apps in C++/CX, which compiles to native code. If you deigned to do such a thing...
     
  13. macrumors newbie

    Joined:
    Mar 30, 2009
    #13
    Your problem seems to be one of understanding the concepts of computer programming. I started teaching computer programming in the mid-80's, and taught at both the college level and high school for over 25 years. I also worked in industry as a software engineer for six years. It is hard work learning how to be a good programmer, but I bet I would be correct in assuming that most of us here who have done much programming are primarily self-taught (especially us older folk, and to think we did it without the internet.) So, it can be done.

    I admire your desire to learn programming at your age, and will be honest in telling you the most teenagers give up rather quickly. The primary problem seems to be two-fold. First, programming is very abstract in some ways, but pure logic at its core. This is a concept that the still developing brain has a problem grasping. Finally, the computer does what it is told to do and nothing more. Unfortunately, far too many teenagers are driven by "instant gratification" and lack the patience to learn a language.

    Many good arguments are given above in the above posts, but it seems that your primary concern is to learn the format of computer languages, and just what it is that drives them. From an educational perspective Java would be easier to learn than C++, but in my experiences I would not consider it the best language to use to teach/learn OOP. I always found Pascal to be one of the easiest languages to teach, and loved using myself. You may wonder why I am suggesting that you learn an antiquated language? For me, learning to program is like playing cards...master one, two or three different card games and learning any others is a piece of cake. The same applies to computer programming, learn/master (I use the term "master" lightly) one or two higher languages and then it is merely an issue of learning the idiosyncrasies of a "new" language before you have mastered it also.

    There are some free Pascal compilers out there that run on OS X:

    You may find the role of Pascal and Apple Computers rather interesting when you learn about it in your studies.

    A great resource about anything having to do with computer can be found at: http://www.dmoz.org/Computers/

    MIT also offers numerous FREE courses in almost any field of study including computer programming and electrical engineering: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/

    I have taken correspondence courses from Cal Berkeley in the past. http://extension.berkeley.edu/catalog/prolang.html They were cheap at the time for college courses (you also get college credit), you get help from the instructor, and now they have forums where students can discuss their projects. They are many online course out there. Some are cheap (U of Texas Austin, or any Texas school for that matter) and some are insanely expensive (Penn State.)

    What you seem to want is a structured learning program that you can do on your own (get a compiler, find tutorials/books on the Web, etc.) or one that you can do with others (instructors, students, etc.) I would suggest that if you do it on your own that you find an existing course syllabus and adopt it,. You will also need good resources, and must have the patience/drive to find solutions on your own. A big problem with high school students is that they want to jump straight to the end while doing little in the middle.

    Finally, I always found that I learned the most when I would come up with a program that I wanted to write and start writing it. There were always the little things that I had to battle with that taught more than I ever learned in a classroom.

    Regardless of the language you choose, or the method you use...Good luck
     
  14. N-M
    macrumors newbie

    Joined:
    Jan 29, 2013
    #14
    Yeah, or just go the easy way and learn C++ to cover OS X, iOS, Android, Windows Phone, Windows, and Linux.

    At least that's what's been the experience of most who are actually in the business:
    http://blog.algolia.com/need-performance-on-mobile-use-c-cpp/
    http://blog.burhum.com/post/36166554007/cross-platform-ios-android-mobile-app-development
    http://www.infoworld.com/t/mobile-development/and-the-winner-cross-platform-mobile-app-dev-c-208770

    If you need a framework (make sure you actually do -- the beauty of C++ is that it lets you make this decision), check out Qt: http://qt.digia.com/

    One advice -- ignore the tutorials. 99.9% of what you'll find on-line is gonna be, politely speaking, outdated, useless crap (written by people stuck in the 1990s who still think that you *have* to manage resources manually when using C++ ;]).

    Instead, get a good *recent* book (so it covers modern C++11) and go through it *systematically*; I recommend: http://www.informit.com/title/032174113
     
  15. macrumors 603

    notjustjay

    Joined:
    Sep 19, 2003
    Location:
    Canada, eh?
    #15
    I learned programming as a teenager (even earlier, actually; my first programs, though stupidly simple, was when I was about 11). I remember having an Apple ][ in my room from grades 6 to 8. Back then there was no internet and hardly any video gaming so if you sat down at a computer you were either going to fire up something like Oregon Trail or WordStar or you were going to learn to program it yourself. So I did.

    I found I was quite good at thinking through logic puzzles and as a socially awkward child in the 80's, the computer was a welcome relief from the puzzling world of junior high. People were hard to understand (especially girls! :eek: ) but it was nice to know that I could always get the computer to do exactly what I wanted, it was simply a matter of figuring out how to tell it. :D
     
  16. macrumors 68000

    Joined:
    Mar 29, 2009
    Location:
    USA
    #16
    I find to be 'successful' programmer you only need two things:

    The drive/obsession to think up a project and stick with it
    Enough technical know-how to get it done

    Note that you don't need to do things the 'right' way or write the best code. So much software out there is a huge mess of a product. But it gets job X done so it sells.

    Becoming a 'good' programmer is another story. That involves another level of self-discipline and being fortunate enough to have at least one great mentor, as well as having a very deep knowledge of the domain you are working in. And it's always a bonus to have a knack for something else like design.
     
  17. macrumors 603

    notjustjay

    Joined:
    Sep 19, 2003
    Location:
    Canada, eh?
    #17
    Having the drive will force you to improve your code. You will go through the agony of working with previously-written, undocumented, buggy code and then you will come to your senses and write better code the next time. Plus a good programmer is always reading about best practices, learning new tricks from copy/pasting examples, etc.

    But that first one is key. You must want to do something. Whatever that is. "I want to learn how to program" should not be the end, but the means to get something done. That's what sets apart people like Linus Torvalds, Tim Berners-Lee, Steve Wozniak, etc -- who have visions of great ideas and want to get them done -- from the guy who picks up a magazine and says "Ooh, it says here that programming could be a good way to earn money, I should learn."
     
  18. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #18
    Doesn't seem familiar at all. ;)

    That's why I recommend learning about revision control systems early. It can really help you understand how code can be a living/evolving thing.

    B
     
  19. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #19
    That doesn't just apply to programmers. If you want to be good at anything then you will constantly need to update your skills. Learning is a life long process. It never stops. Ever.
     
  20. macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #20
    Well, the OP is new to programming, so admittedly, I was over-simplifying. I think the chances of him actually doing and learning something is increased greatly by using the best supported language for whatever platform he wants to target. It just means he'll get to concentrate more on the interesting bits of programming more than the tedious bits (no worries, there will still be plenty of those). It'll be easier to find tutorials, sample code, documentation, someone to answer questions, etc.

    On the topic of over-simplying: Windows, in particular, allows for a massive number of different languages, platforms, frameworks, engines, etc., many of which are reasonable or at least arguable for a particular situation. It's hard to say there's one best language for Windows. And, it's true, C++ remains quite well supported as a development language and gives you a lot of flexibility and allows for very good performance if you know what you are doing. But the cost of that is complexity and that there are so many more ways to go wrong. Also, there are just not that many things you actually need C++ for. IMO, choosing C++ because you think you might need the performance is an extreme case of premature optimization. Build your app, profile, simplify the design to remove layers and transformations (code that doesn't execute is much, much more efficient than the best optimized code). Then, if it's still too slow, optimize that bit in C or C++ or whatever. If you really feel that performance is ultimately going to be your ultimate bottleneck, design for it by letting the anticipated bottlenecks to be parallelized/distributed.

    Sorry, probably too much blathering there.

    Quickly, to clear up a few misconceptions, just for your information:
    You can write native code for Windows in various ways.
    Over the last decade (roughly, not looking at a calendar here) it seems like MS has put the bulk of their efforts to support general development into various .NET frameworks, which do run in the CLI (sort of like a Java VM environment), which isn't quite "native". The features and capabilities of these frameworks is massive, so a lot of apps choose to use them and usually are written in a "managed" language themselves. So its true a lot of apps aren't "native" but that's by choice (usually for good, practical reasons).
    Interestingly, MS's latest application framework, for windows store apps, has a native implementation. They reimplemented a bunch of .net interfaces in code that compiles to native machine code (I'm guessing they used C++, but I have no direct knowledge -- C is possible as well.) It's pretty clear they did this to provide a competitive platform for mobile (ARM) platforms. The windows store apps you write on top of the platform APIs can be managed (C# or, I think, VB.NET), C++, or (most interestingly) Javascript.

    Anyway: the windows world is all over the place. But when in doubt, C# has to be the default. They add native language support to C# whenever they come up with a clever new idea (it's await/async these days, I think, unless I've gotten a cycle behind.)



    Well, I've been in the business (including cross-platform development for ~7 years) more years than I care to admit. C++ *is* the Mike Tyson of cross-platform development languages (this analogy would work better if Tyson was unbeatable in the '90's rather than the '80's). But so what? Judicious use of C++ is an answer to the question, how can I develop software for multiple platforms without rewriting/porting for each platform (especially high-performance software). It's not a good answer for getting started in programming for most situations. (Also, you should read the articles you're linking to carefully. They don't suggest that C++ "covers" those platforms. One is by a newb IOS developer who may not fully understand how to optimize objective-c code -- e.g., there's nothing forcing you to send messages in your inner loops. The third one is an indirect sales pitch by a guy with a cross-platform C++ solution to sell. There's a reason it's title ends with a question mark. And the middle one -- the only experienced developer without an axe to grind -- it suggesting C++ as a cross-platform language use to implement parts of an app, mixed with native code and doesn't exactly suggest it's a panacea.) Don't get me wrong. I love C++. It's probably my "native" language. But I review C++ code routinely, written by smart, experienced programmers that nevertheless contains serious flaws. If the OP wants to start with K2, then fine. If he can climb it with little experience and preparations, then great! But that's not where I'm going to recommend someone start.

    Wow, what a long and rambling post. Sorry, just unwinding after a long day. Oh well, what else is the internet for, anyway?
     
  21. N-M, Jan 30, 2013
    Last edited: Jan 30, 2013

    N-M
    macrumors newbie

    Joined:
    Jan 29, 2013
    #21
    I see your points, I also have a few notes:

    - for me goals like "programming for most situations" are too vague to be meaningful; I'd even say that such a thing as an "average developer" is more of a statistical concept than any real person at any point in time, we all have different needs -- if we were going by what's the "majority" using (and majority isn't necessarily equal to average), we'd have to stop at suggesting OP learns PHP + JavaScript. Clearly, as OP states he/she already knows Java (so, pending clarification from the OP, my working assumption is that he/she's not "just starting"), this is not guaranteed to be the way to go (although that's also why it would really help if OP stated what the goals are);

    - yeah, "covers all" is not to be understood as "is perfect for all", nothing is a panacea, I think we agree on this one; it's just that sometimes imperfect solution with hurdles is still better than no solution at all -- e.g., Objective-C is simply not used outside of Apple ecosystem; so, even if admittedly one might have a hard time with C++'s learning curve (although it would be rather controversial to say that Obj-C is any easier for someone coming from Java, BTW), one is going to face an infinitely hard (read: mission impossible) time with adopting Obj-C for all of the other mentioned platforms;

    // Regarding Windows, there's a tremendous amount of work Microsoft is putting into C++ support, DirectX is the officially recommended way for graphics-intensive Windows Store apps: http://msdn.microsoft.com/en-us/library/windows/apps/br229580.aspx
    // one may also point out DirectXTK which some describe as "XNA for C++": http://blogs.msdn.com/b/chuckw/archive/2012/03/02/directxtk.aspx

    - I don't think the first author is that much of a "newb", 2004 doesn't sound like yesterday:
    http://www.reddit.com/r/cpp/comment...the_only_way_to_have_high_performance/c71efh8
    Further, there's an important point to be made here -- often, others like to criticize C++ for complexity, while forgetting the fact that it's all relative and there's an inherent complexity in the available alternatives. In this case, you may criticize him claiming that spending 8 years on Obj-C is not enough and spending more would theoretically make him a better programmer -- but in practice, he was simply more productive in C++. Statements like "C++ might result in lower productivity" are a myth -- you have to qualify "productivity compared to W in task X when doing Y given knowing Z", and then you might often find it's the best available choice after all;

    - going back to "it's relative" -- I still think that learning C++ and the minimal amount of copy-pasting occasionally necessary to invoke it is easier, faster, and more productive than learning three different programming languages and re-writing the code three times; this was (and is) my main point of contention: "OS X or iOS, I'd go to Objective-C, for Windows, I'd learn C#, and for Android, I'd continue with Java";

    - that being said, you're right if it turns out that, for instance, OP prefers to gamble on only one of the above-mentioned platforms being relevant (there are strong reasons to focus on mastering the platform-specific tool-chain in such a case);

    - I don't agree with your reading of the third one, given that it cites several sources with differing viewpoints (note not all agree on the conclusion, BTW);

    - serious flaws will crop up in any code base written in any language over time. For instance, anyone claiming that Java makes the memory mgmt. situation any better hasn't seen a java.lang.NullPointerException flood. Also, production Java code isn't as clean as on-line discussions / textbooks like to present, often littered with annotations, workarounds to suppress warnings, etc. Note I'm not saying all that to criticize Java. Instead, this is a so-far-unavoidable result of the fact that complexity is a simple fact of life. A good way to reduce or alleviate the flaws is to follow modern, best practices from the start, which requires learning them ASAP. That's why I feel comfortable stating that over 99% of on-line tutorials for C++ do more harm than good and are to be avoided, suggesting systematically going through a good, recent book instead (for instance, most of the resource management bugs in pre-C++11 are nearly impossible to make now, and resource management used to be the major criticism against C++).
     

Share This Page