nickadams said:
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!
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.