1

Once day, I talked to my Prof. about Computational Physics and he showed me his work. I'm quite surprised that why Prof. use C++ for computation because C++ quite complicated. I heard he talked about memory talk about pointer. Why didn't he use Python or Java that more easier? no need to manage memory no need to busy with pointer.

fronthem
  • 497
  • 1
  • 6
  • 14
  • 3
    The reason is probably historical. – Bernhard Aug 11 '13 at 10:38
  • 2
    Related: http://scicomp.stackexchange.com/questions/304/c-vs-fortran-for-hpc – Bernhard Aug 11 '13 at 10:39
  • 1
    This is not a question about Physics. Programming is engineering, which is off-topic here. – Deer Hunter Aug 11 '13 at 10:44
  • 3
    This question appears to be off-topic because it is about programming languages, not physics concepts. –  Aug 11 '13 at 12:31
  • In my experience, people mostly use Fortran, Matlab and Python for this. C++ is not really that popular (maybe there has been a slight increase recently, if you count CUDA as C++). – fjarri Aug 11 '13 at 12:32
  • @Bogdan CUDA is accessible even without C++, e.g. from Mathematica – Ruslan Aug 11 '13 at 14:20
  • @Ruslan: I know (I use Python bindings myself), but a significant number of people still choose to write in pure CUDA. – fjarri Aug 11 '13 at 14:49
  • @Bogdan Since the rise of ROOT and Geant4 nuclear and particle physicists make heavy use of C++ (replacing fortran77 that we used with CERNLIB based tools), and while in a lot of ways that is not "computational physics" it does add up to a heck of a lot of code written for physics work. – dmckee --- ex-moderator kitten Aug 11 '13 at 16:58
  • My experience is if you get into classes and structures that are at all complicated (as will be so for lattice models and likely for other particle physics apps) and your design goes wrong in a garbage-collected language like Java, Python etc, then memory leaks are an impossible nightmare to track down. Many modern programming language features beyond what C++ gives you are wonderful - garbage collection and loss of control of memory just isn't one of them in my opinion! – Selene Routley Aug 12 '13 at 01:02

1 Answers1

13

I can't really know why your professor used C++, but there are several reasons why you would:

  • Performance: Scientific computations might require top-notch performance. C++ allows for very low level control over the hardware and has many possibilities for micro-optimization while still providing high-level abstraction. Of course, this is also the reason that C++ is quite complicated.
  • Historical reasons: C++ has been the de facto general programming language for quite a while. Your prof's code might need to be compatible with other projects. Plus, I think there are more libraries for C/C++ than for any other language, your professor might have to make use of such a library. It is also possible that C++ is the standard language for this kind of thing in your professor's university or field, simply because it used to be the best choice.
  • Maybe your professor only knows C++...
JSQuareD
  • 1,072
  • @Dimensio1n0: latter=second or last, in english? – kalkanistovinko Sep 08 '14 at 20:03
  • @kalkanistovinko Latter is often used in reference to the second of two things, i.e. "this" or "that", where "that" is the latter. It also can mean: "situated or occurring nearer to the end of something than to the beginning". Here it seems to be referring to "Maybe your professor only knows C++...". – UserNotDefined Jun 27 '16 at 23:44
  • Re "maybe your professor only knows..." - I know a very accomplished academic that insists on using IDL. He has a ton of libraries in IDL, and sees no reason to change it up to Matlab, Python, or any other language. It is a tool that works for him. Don't underestimate the power of "existing libraries". – Floris Jul 29 '16 at 02:48