Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Best Programming Language for a Math Major?

  1. Jun 25, 2012 #1
    I always see people on this forum encouraging math majors to learn to program so I was wondering what language is best to learn? Also, what is the best way to learn the language besides taking a class?

    I have only taken 2 math classes so far so I definitely can't tell you what areas I'm interested it, but my goal is to go for a PhD (if I can get accepted).





    Thanks! :biggrin:
     
    Last edited: Jun 26, 2012
  2. jcsd
  3. Jun 26, 2012 #2

    chiro

    User Avatar
    Science Advisor

    Hey nickadams.

    Some people might say a language like Python is good one to start off on, but I disagree and I'll outline my reasons why.

    My language recommendation is C, not C++ if you haven't programmed before.

    The reasons why C is preferrable is that 1) C is a compiled language not an interpretative language which means you will have to get used to making sure everything is defined correctly. This gets you into a good routine for coding in general.

    2) The other thing relates to the fact that it's compiled in the way that you will have to debug your code in a way that you will need to understand your errors from a low enough level.

    The reason for the above is this teaches you how stuff works at a low enough level which will increase your understanding of what's going on, and introduce you to the painful part of programming which is debugging. Once you do enough debugging, you will not only be able to know where the errors are, but why and that's the most important. You'll also be able to write better code as you progress.

    3) It leads naturally to C++. C++ is a common language and it's also a compiled one which is used very extensively for many applications, in particular ones that need performance. The reason for this is that modern C++ compilers do a very good job of creating optimal code. You also get the features of C++ which allow you to transition into object oriented programming if you choose to, and if you end up doing more coding you probably will.

    For math purposes this is good because sometimes you need to use compiled libraries or create your own routines that use them and whether they are a compiled 3rd party library or DLL (or SO for you *nix people), C++ is ready to use both of these.

    4) It's portable. Not only is it compiled, but with all the standard libraries and other platform-invariant libaries out there, you get the best of both worlds. Java is platform-independent too but needs a VM, whereas if you use the right libraries you get platform-independence plus the benefits of compiled code.

    Not only that, if a new platform comes up and you need to add support for it, you can do it yourself instead of having to wait for someone else to do it (minor thing to consider).

    5) It's a popular language. This translates into many libraries, examples, repositories and so on being available. Also means there is a higher chance of you having to use it if the chance comes. I should say that a lot of languages are 'popular', but this also has age by its side and it is still used for the right reasons.

    The big benefit IMO is the transition to C++: All valid C code should compile on a C++ compiler with no problems, and learning C to begin with means you can worry about how procedural code actually works before looking at the extensions.

    If you don't understand how procedural code really works, you won't understand OOP and this is the primary argument for learning C: you focus on learning the procedural stuff properly and then move on to the extensions and new paradigms.

    Remember that state and flow-control are the most important things to a programmer.
     
  4. Jun 26, 2012 #3
    Thanks chiro! What do you think is the best way for a complete beginner to learn C without taking a class?
     
  5. Jun 26, 2012 #4

    rcgldr

    User Avatar
    Homework Helper

    Matlab is good for students, but it's more of a high end math tool than a programming language.

    You should find out what your school recommends or what programming classes the school uses as part of it's math program. Although C and C++ are very popular, it's possible that your school's graduate math department uses Fortran instead. Some of the math oriented stuff at companies I worked for was done in Visual Basic, mostly because it was the quickest way to create interactive user interfaces (like graphs) for math based applications.

    As far as learning a programming language, there are some tutorial web sites. I don't know which ones to recommend, but you could try doing a search for "learning" in "programming and Comp Sci" forum to see what others have recommended before, or wait and see if anyone posts recommendations in this thread.
     
    Last edited: Jun 26, 2012
  6. Jun 26, 2012 #5
    This site has a great C tutorial, Learn C The Hard Way, and C Programming.com is a good resource too.

    The best way to learn is to jump in and have a go. You will need to set up a development environment first - if you are running Windows you might want to look into mingw, there are others, maybe someone else will have a recommendation. I run Linux in a virtual machine and do my C coding that way.
     
  7. Jun 26, 2012 #6

    turbo

    User Avatar
    Gold Member

    nickadams, what is your concentration in math, and what do you hope to do with it? Fortran is still not dead, and it can be quite useful.
     
  8. Jun 26, 2012 #7
    Actually, I kind of disagree about learning C as your first language or as the language to use if you are a math major....for a compiled language, I would recommend Fortran over C, if you are a math major.

    Fortran is simpler than C and easier to learn. Some of the good reasons for C given above, apply to Fortran too and even more so. Age? Fortran is older than C and many of the linear algebra, simulation and other libraries have been in use so much that they are practically bug free. Fortran has been used inside the scientific community A LOT. When it comes to libraries, Fortran libraries are more compatible than C, etc., etc.

    To this day, the famous Matlab uses Fortran 90 libraries for backbone linear algebra calculations...not C, not C++.

    Fortran does not suffer of memory leakage the way C or C++ do.

    The thing is, for a math major, I wouldn't even recommend any of the compiled languages, just yet...I think you are better off with something like Mathematica, but it is expensive.

    But there are free environments like Python with numpy/scipy/matplotlib. Python comes with a lot of libraries for various types of analysis....that's what I am using now.

    Then, of course, there are other a-la-matlab environments like Octave, Freemat, Scilab.

    For a math major, maybe environments like Euler, Maxima, or Sage may have more weird stuff to offer that you might appreciate; they also plot stuff right away...if you are using Fortran or C...you do NOT want to plot....you rather be in a environment that know how to plot what you want and may even offer interactivity to interact with the plot.

    But most of all.....don't take our opinions that seriously, everybody is different and has different taste. Instead, take the all this advise with a grain of salt, take notes of the names being mentioned and go read about them....maybe even download and install (I think Sage can be used on-line).

    my 2 cents
     
  9. Jun 26, 2012 #8
    that stuff looks great; thanks Adyssa!

    I have only taken 2 math classes so far so I definitely can't tell you what areas I'm interested it, but my goal is to go for a PhD (if I can get accepted). I can't say if I want to do pure or applied cuz I just don't have enought experience to say what I prefer yet.

    The computers at my school have mathematica, maple, matlab, etc. so I don't need to worry about buying them. I wish I could tell you guys more specifically what I want to do with the programming but I don't even know; I was just looking to learn a language because I'd seen it recommended a lot on this site.
     
  10. Jun 27, 2012 #9
    C is probably your best choice for understanding programming on a fundamental level. It can do everything (with some/a-lot work).

    MATLAB is very good for matrix/vector operations and visualization or working with large quantities of values. MATLABs differential equation solver is based on Maple

    Mathematica I believe is best for higher level mathematics, though I have not used this program myself.
     
  11. Jun 27, 2012 #10
    It depends on what you want to get out of programming.

    Take a look at Scheme if you want to play with a language with mathematical simplicity and don't care too much about learning about the hardware or picking up a language that's used in the real world.

    Check out Javascript if you want something simple but also highly useful. It might be a bit of a challenge to figure out how to run your code at first. But it's built into every web browser.

    If you use unix/linux and want to start learning something practical immediately, check out shell scripting or awk.

    C was my first favorite language. But, since you'll be working at such a low level, it will take a while before you can write C programs that do anything useful. C is ideal, though, if you want to learn how the machine works.

    Matlab or Mathematica sound reasonable if you want to solve math problems. I haven't used them.

    You probably don't know at this point exactly what you want. Look at a few languages and if one looks interesting, follow your fancy.
     
  12. Jun 27, 2012 #11

    chiro

    User Avatar
    Science Advisor

    I don't know if you can do this in FORTRAN, but in common C++ compilers (and some C ones), you can write direct inline assembly which is good when you need to write specialized instructions including things like vector processing on either normal platforms (SSE,SSE2) or on specialized architectures.

    Most people will never have to touch this stuff but for highly optimized numerical routines, they may have to.
     
  13. Jun 27, 2012 #12
    Current applied math major here. Having worked for various defense contractors and NASA, the languages I've used are C, MATLAB, IDL, and FORTRAN. If you're going to get into HPC, you're going to need to learn MPI and C++.

    Projecteuler.net (WFS) is a great website to help you learn how to program in any language. It will also develop your critical thinking and algorithm development skills.
     
  14. Jun 28, 2012 #13
    I second that, you might even learn some new mathematics in the process!
     
  15. Jun 29, 2012 #14
    I would recommend Mathematica any day of the week. It's much more convivial and powerful than most other tools out there and one of the major problems in math is visualizing mathematical data, which mma is arguably the best tool for. There is all the different tools needed to do functional and procedural programming with an online help system inside the program containing many examples for each functions.

    Beside this, if you need stronger foundations in Computer Science you can get your hands into python for a month or two to learn the basics before jumping into straight C. That's what we did when I went through intro to programming in CS.

    C is very slow to build programs with. It's one of the oldest but still more powerful computer languages. You can build C programs with mathematica through the Compile function using CompilationTarget -> "C". You will need an external compiler.

    Pointers are easier to learn in C than in C++ as a general rule. You will be in Object Oriented programming once you start C++.

    Ruby is easy to learn and has a certain flow to it, it's also a OO language.

    Python has SciPy and NumPy which are libraries designed to help making scientific and number theoretical programming faster. It's still slow, buggy, and lacks options. You'll have to deal with a miriad of different packages if you go deep into python, which isn't fun to deal with.

    MathLab and Maple are good too for mathematicians. They look very much alike and share characteristics with mma and other software packages for maths.

    Fortran, Prolog and pascal are all good if you follow a course designed to learn programming, otherwise, I'd stay away from them. They are quite old and not as powerful or general as the other programming languages available.

    My top 10:
    1. Mathematica
    2. C
    3. the rest...

    lol I hope it helps, aurevoir!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Best Programming Language for a Math Major?
Loading...