Novice C++ programmer trying to get started on a MBP

Discussion in 'Mac Programming' started by mox123, May 5, 2008.

  1. mox123 macrumors 6502

    Joined:
    Jul 18, 2007
    Location:
    Chicago
    #1
    so i am going through a crash course on C++. i currently have the base model penyrn MBP. once i have C++ codes written on a text file, what should i do next to run the program?

    1. any step-by-step instruction on how i can go from lines of C++ codes to compiling it to running it?

    2. what would be some of the best ways to master C++ programming in a very quick time? i. e. get a reasonable score on brainbench exams

    for background info, i have a PhD already in a hardcore theoretical science, and i have some experience with using the terminal and reading fortran codes

    Thanks a million in advance for any suggestions!
     
  2. toddburch macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #2
    I would suggest you install Xcode. It came on the CD's with your MBP, or you can download it from Apple Web Site.

    Once you install Xcode, create a File -> New Project and select one of the styles of C++ project.

    Todd
     
  3. mox123 thread starter macrumors 6502

    Joined:
    Jul 18, 2007
    Location:
    Chicago
    #3
    oh kewl...is that X11 inside the utilities folder?
     
  4. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #4
    Well X11 is located in the Utilities folder yes, but I'm not sure what specific relevance it has to this question? Are you looking at developing an X11 app?
     
  5. mox123 thread starter macrumors 6502

    Joined:
    Jul 18, 2007
    Location:
    Chicago
    #5
    oh oops...so Xcode and X11 are different programs then for writing codes?
     
  6. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #6
    X11 has nothing to do with writing code. It is a set of APIs that allow a program you write to access GUI type features on Unix style operating systems.
     
  7. Sander macrumors 6502

    Joined:
    Apr 24, 2008
    #7
    Since you say you have experience with using the terminal, I'd say you don't need to get into Xcode yet.

    Compile your new C++ program like so:

    g++ -o myprogram myprogram.cpp

    you can then run it by typing

    ./myprogram

    to the same prompt.

    Xcode is a so-called "Integrated Development Environment" (like Visual Studio on Windows, or Eclipse). What's nice about IDE's:

    - they help you manage multi-file projects easily
    - they help you locate syntax errors in your code quickly
    - they often have a nice integrated help/documentation system.

    The first benefit is not really relevant for the vast majority of "newbe" programs (most of which are typed in a single file anyway).
     
  8. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #8
    What Sander wrote above is the right way to start out, in my opinion. I doubt seriously that any exam you are studying for is going to cater to any particular IDE, so using a command line compiler is the way to go.

    I haven't taken any brainbench exams (and shudder to think of what kinds of questions might appear on this sort of test, anyway), so you're going to have to be a bit more specific on what you hope to learn for us to be able to give you pointers on what to focus on.

    If the test is on using the STL effectively, that is far different than if it's just testing your ability to write standard C++ code, perhaps define a few objects, find errors in examples, etc.

    -Lee
     
  9. mox123 thread starter macrumors 6502

    Joined:
    Jul 18, 2007
    Location:
    Chicago
    #9
    oh kewl....so what's the difference between Carbon C++ applications and Carbon C++ standard applications? what is carbon? i know apple uses it
     
  10. mox123 thread starter macrumors 6502

    Joined:
    Jul 18, 2007
    Location:
    Chicago
    #10
    oh kewl...this is exactly what i needed to find out! sometimes i see people doing these sort of things in cheap linux boxes....so i want to be able to do this on my own mac as well as in linux/unix boxes at work as well!
     
  11. mox123 thread starter macrumors 6502

    Joined:
    Jul 18, 2007
    Location:
    Chicago
    #11
    hmm what is STL? basically i need to be proficient in writing C++ codes for quantitative modeling....instead of using proprietory softwares like Mathematica i suppose...since not everyone would have that

    I guess in general i find out that most people don't have macs nor what i thought would be standard softwares (like mathematica)...so somehow i need to do more work and learn how to do the same things without using proprietary softwares and convenient hardwares like a mac :(
     
  12. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #12
    Carbon is an API that allows you to make native Mac OS X applications. I would forget about it for the time being and just stick to doing command line programs until you are comfortable with C/C++.
     
  13. mox123 thread starter macrumors 6502

    Joined:
    Jul 18, 2007
    Location:
    Chicago
    #13
    hmm...probably a very stupid question...what is API?

    so if i use xcode for rudimentary C++ codes, what kind of new project should i choose to begin with?
     
  14. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #14
    Application Programming Interface. It supplies a group of functions which allow you to interact with either other programs, libraries or the OS.

    C++ Tool in the Command Line Utility section of the new project window.
     
  15. yeroen macrumors 6502a

    yeroen

    Joined:
    Mar 8, 2007
    Location:
    Cambridge, MA
    #15
    API == "Application Programming Interface". Essentially an API is a set of functions, datatypes, and/or classes that are bundled into a shared library (or the OS, or another application) for you to make use of. For more info, consult wikipedia.

    At this point, learning Xcode or any other IDE would just be a massive distraction. Learn how to edit, compile, and build by hand first, things that the IDE will hide from you but that you will need to know nonetheless, then graduate to the complexity of the IDE as the complexity of your projects warrants.
     
  16. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #16
    STL is the Standard Template Library. I only brought it up because it is a pretty common tool for C++ and thought it might be covered on the tests you mentioned. If you are just starting out you should learn to work without it, anyway.

    I don't know anything about quantitative modeling but a very brief overview I just read makes me think that you just need to be able to program mathematical relationships, forumlae, etc. C++ is certainly able to handle this, and I think starting out you should just learn how to do input and output with std::cin and std::cout. For cout you should look into setting precision, etc. since it sounds like you will be dealing with a fair amount of floating-point math.

    Once you've gotten that far you can start looking into the mathematical functions provided by including the header file math.h. If there are more advanced mathematical operations you need to perform than those provided you can start looking into building these. Other may have already programmed these operations and made them available online, but it may be better for you to write them yourself to get familiar with how they are programmed.

    -Lee
     
  17. Sander macrumors 6502

    Joined:
    Apr 24, 2008
    #17
    Ahem to "cheap linux boxes". I bought my wife a Mac Mini a few years ago, and when I found out about the Terminal and did a listing of /bin, I rember thinking "Wow, this is almost like a real computer!".

    We have two Macs now, and I'm getting a MacBook Pro soon.

    Also, I don't mean to sound condescending, but it looks like you still have a lot to learn. I would really focus on the programming language first. A lot of people get put off while programming because they have set their aims a bit too high, and assume they can produce cool stuff in a week or so. I had to have a long sobering chat with one of my friends who thought he'd "start with a simple game" - I assumed he meant tic-tac-toe, but he was thinking more in the lines of Doom ("Really simple, not with fancy multi-player stuff or anything").

    If your aim is to get a good brainbench score so as to get yourself invited for job interviews, be careful. I've interviewed lots of people, and "artificially inflated scores" are always popped with one or two smart questions.

    I think learning to program C++ is like learning to play the violin. Expect to be horrible at it for a few years, and expect to throw away the first few projects you attempt.

    Also, are you sure you want to start with C++, and not, say, C? If you already know FORTRAN, you should be able to pick up C relatively easily, because it doesn't introduce any new programming paradigms (generic programming, object orientation) like C++ does.

    Then, once you reach the point that you're thinking "I wish I could organize my code in such a way that related data and functions were grouped together so I can more easily exchange parts of my software, or put in different algorithms without having to change my code in dozens of places", then you read up on object orientation and reach enlightenment.

    If it weren't blatant self-advertizing, I would suggest clicking on the link in my signature. You are the exact audience for my book.
     
  18. mox123 thread starter macrumors 6502

    Joined:
    Jul 18, 2007
    Location:
    Chicago
    #18

    Actually i should have said inexpensive....all i meant was that I have been used to all the good stuff, both hardware and software, where in reality i have to work with people who haven't had access to them....so now i sorta have to get back to basics and be well-versed in all these other stuff too!!

    What do you mean by "I've interviewed lots of people, and "artificially inflated scores" are always popped with one or two smart questions"? What kind of questions would you ask?

    THe kind of work I have in mind actually requires someone to have a lot of math and physics background, which i do....so I have been told that I already have the hard part down....now i just need to pick up on the skills on running these problems that I can set up using C++ and such. I have read up on C++ and principles behind object-oriented programming....frankly i find the latter to be much more intuitive than the procedural kind.....theory aside (which i'm always better at...the more abstract things get, the better i am at them), i guess i am trying to get my hands wet in actually writing and compiling some actual codes...

    At this point, my biggest concern is actually being able to know all the syntax of C++ off the top of my head, which presumably someone who has actual programming experience would be able to do

    would you know if brainbench asks big-picture questions on object-oriented principles behind C++, or on the actual nitty-grindy syntax stuff? at this point, i'm much more concerned about the latter....
     
  19. mox123 thread starter macrumors 6502

    Joined:
    Jul 18, 2007
    Location:
    Chicago
    #19
    oops...i hit the wrong button...

    so to sum up, i guess i'm not really trying to be a hardcore programmer....i need to learn C++ so i can use it as a means to some bigger end of solving certain problems that i can't do with just pencil or paper (or when not allowed to use mathematica and such!)
     
  20. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #20
    I think that is what every programmer does :). I doubt you will find a programmer who writes code for the hell of it.
     
  21. mox123 thread starter macrumors 6502

    Joined:
    Jul 18, 2007
    Location:
    Chicago
    #21
    LoL....point taken! :)
     
  22. yeroen macrumors 6502a

    yeroen

    Joined:
    Mar 8, 2007
    Location:
    Cambridge, MA
    #22
    It sounds as if you got a quant-job at an investment bank or hedge fund where the habit is to retread Ph.D's in math/physics as quantitative developers.

    You should just pick up a copy of 'Numerical Recipes in C++', and learn what you need to know of C++ from that.

    I will say this speaking from experience, for numerics, Fotran is better, if less fashionable these days.
     
  23. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #23
    Modern Fortran is very capable, even for OOP. Modules, generics, array-slicing goodness, pointers, rich allocation primitives (is this thing allocated? how big is it? is it big enough to hold this? no, let's reallocate then). It's not how the thread started, but it is quite good for math and scientific applications. The only issue might be third party library integration, but it has strong enough interoperability with C that I think that can be mitigated.
     
  24. Sander macrumors 6502

    Joined:
    Apr 24, 2008
    #24
    Okay. I think I got misled by your brainbench comment earlier. I've never taken a brainbench test myself, but new applicants in our company usually do one as a "pre-screening". I thought this was the main use for it, so when you asked how to quickly increase your brainbench scores, I assumed that was so you could interview for a C++ position.

    I usually only glance at these scores. If someone is sent to me because he's a "C++ expert", I have other ways of finding out.

    One of my favorite questions is to ask which C++ book is currently on their bedside table, and paying attention to their response. Or ask them which book they would recommend.

    I'm actually not particularly interested if someone really is a C++ expert. In fact, I'd rather they aren't afraid of admitting they aren't. I interviewed a guy who couldn't quite tell me what template metaprogramming was, but insisted that it was useless anyway so it wasn't something he'd ever needed to learn.

    There are a lot of C programmers out there who think they became C++ programmers after renaming their code with a .cpp extension.
     
  25. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #25
    You mean that's not how you program in C++?! Damn... back to the drawing board :).
     

Share This Page