Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

feanorkinslayer

macrumors newbie
Original poster
Jul 19, 2012
4
0
London
Hi there, this is my first post here although I have lurked here for a while. I also apologise for asking something that probably has dome before.

My background is a physics masters and I am familiar with Fortran 95 and extensively used Matlab (well gnu Octave) on my 10 month placement. I am looking to learn c++ for when I start my PhD as I'll need to do a lot of data analysis and it seems it's the language others in the group use.

My question is, what do I need to get going with c++ on a mac. I have Xcode as I got it by mistake over a year ago, but do I need anything else to begin my "hello world" program? Are there any useful websites or books?

Thanks in advance.
 

foijord

macrumors newbie
Jul 18, 2012
6
0
Norway
I am looking to learn c++ for when I start my PhD as I'll need to do a lot of data analysis and it seems it's the language others in the group use.

C++ is probably the wrong language to use, no matter what you're doing. I'm assuming you're not doing any GUI, in which case you would use Objective-C.

If you're creating small programs to churn through some data, you should probably just use Python. Many (most?) scientist type of guys do. I know, Python is very slow for stuff like this, but that doesn't matter because it's so much faster to get the job done in. If you create a Python script and you find it's running too slow, you can port the offending part of the code to C and easily call it from your script.

In C++, it may take you 10 hours to write some code that executes in 10 minutes, while in Python, it might take you 10 minutes to write equivalent code that executes in 10 hours. Which do you prefer?
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
My question is, what do I need to get going with c++ on a mac. I have Xcode as I got it by mistake over a year ago, but do I need anything else to begin my "hello world" program? Are there any useful websites or books?

No, if you have Xcode you're ready to go. C++ primer is a good introduction to C++ in my opinion.
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,557
6,057
I would actually say learn C, not C++. 90% of the people I've met at school who say they know C++ in fact mean they know C; they don't know a single thing about objects, which unless I'm mistaken, is the only thing the ++ in C++ refers to.

I recommend the free ebook Learn C The Hard Way. Google it.
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
In C++, it may take you 10 hours to write some code that executes in 10 minutes, while in Python, it might take you 10 minutes to write equivalent code that executes in 10 hours. Which do you prefer?

This would only be true if you are starting from scratch. With STL much of the drudge work is already done for you, just use the library, plus the OP is not working in a vacuum.

I'll need to do a lot of data analysis and it seems it's the language others in the group use.

The above quote also suggests that there are plenty of examples to work from. Why introduce Python when perfectly good solutions already exist in C++?

Personally, I find MATLAB to be the right tool for most technical computing, unless performance becomes an issue.

----------

I would actually say learn C, not C++.

You also seem to be ignoring that the OP is not operating in a vacuum. They should learn the tool their colleagues are using. We don't know if their code is OOPy or not, but a lot of technical computing C++ code I see these days makes heavy use of the STL.

B
 

foijord

macrumors newbie
Jul 18, 2012
6
0
Norway
This would only be true if you are starting from scratch. With STL much of the drudge work is already done for you, just use the library, plus the OP is not working in a vacuum.

Yes, you should definitely use STL. However, there's much more overhead if you're using C++, you have the edit/compile/test cycle, which slows you down, you have to manage your build system, whether you use Xcode or something else, if your program grows in size, compilation time will start to be an issue, you'll spend a lot of time hunting down memory corruptions, etc. etc. This is just my experience over the years.

The above quote also suggests that there are plenty of examples to work from. Why introduce Python when perfectly good solutions already exist in C++?

See above.

Personally, I find MATLAB to be the right tool for most technical computing, unless performance becomes an issue.

Yes, but he knows MATLAB, and decided it's not sufficient for his needs.
 

feanorkinslayer

macrumors newbie
Original poster
Jul 19, 2012
4
0
London
Thanks for all the info people, I appreciate it a lot. I have read some more in to it and seen that Xcode is useful. It's taking hours to update though!

Looks like for my first year Matlab will be sufficient (emailed supervisor), but in year 2 I'll need to be using c++ as that is what the collaborators in Europe use. I'll have a look at those websites and books you have all kindly suggested.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
I would actually say learn C, not C++. 90% of the people I've met at school who say they know C++ in fact mean they know C; they don't know a single thing about objects, which unless I'm mistaken, is the only thing the ++ in C++ refers to.

You can use C++ without any of the OOP, using C instead of C++ for anything not trivial also means 90% longer development time. :D C has it's place but unless you have a good reason to use it, it should not be chosen over C++ as a default imo.
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
Yes, but he knows MATLAB, and decided it's not sufficient for his needs.

Or not. ;)

Looks like for my first year Matlab will be sufficient (emailed supervisor), but in year 2 I'll need to be using c++ as that is what the collaborators in Europe use.

For the record, you can use MATLAB as a front end to lots of C++ code, so you may be able to leave your heavy lifting code in C++, but the UI and visualization stuff can be handled at a higher level in MATLAB.

e.g. http://www.mathworks.com/support/solutions/en/data/1-GQC9NF/index.html

Also for the record I've tried to integrate Python into my workflow, but have so far not found the huge gains in efficiency that many proponents, like foijord, suggest. It's probably just me.

B
 

feanorkinslayer

macrumors newbie
Original poster
Jul 19, 2012
4
0
London
Or not. ;)



For the record, you can use MATLAB as a front end to lots of C++ code, so you may be able to leave your heavy lifting code in C++, but the UI and visualization stuff can be handled at a higher level in MATLAB.

e.g. http://www.mathworks.com/support/solutions/en/data/1-GQC9NF/index.html

Also for the record I've tried to integrate Python into my workflow, but have so far not found the huge gains in efficiency that many proponents, like foijord, suggest. It's probably just me.

B

I did hear whilst learning Matlab that it can be integrated with c/c++. I guess that makes sense because Matlab is based on c right?
 

feanorkinslayer

macrumors newbie
Original poster
Jul 19, 2012
4
0
London
Many bits of it are written in C/C++, but you can also easily integrate fortran, perl, etc...

It's a flexible tool, what you do with it depends on you and your needs.

B

I thought so. What I will be doing is still a bit of a mystery to me..I mean I know the subject but the ins and outs will take me a while to learn!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.