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

Programming and Computer Science in Physics

  1. Jun 26, 2011 #1
    I read ZapperZ's (apologies if I misspelled his username) guide to becoming a Physicist and I saw a portion about learning to program etc.

    He recommends learning at least two languages suggesting maybe FORTRAN and C or C++. This coming Fall I'll be taking a course in Java based Programming and I was wondering if this would be of use to me (beyond teaching me the basics of Programming as a Science) or if it would just be something I would have to sit through until I could take another language. The course offered after Java I/II is called Object Oriented Programming, I believe. What is entailed in Object Oriented Programming and should I consider taking this too? What is the reasoning behind recommending FORTAN? I've only heard that it's a very old language and I would have thought it to be outdated o_O? But I am far from knowledgeable on the topic...

    I was also wondering if I could get some recommendations on computing software used in Math and Science in general. I know of a few software names but I do not know know how they work in any detail. To my knowledge Mathematica, Maple & Matlab are among the big names in the category and I was wondering if someone could help me understand the differences in these softwares and which would be most useful to an Undergraduate student in Physics.

    Thank you in advanced for your time,
    Elwin
     
  2. jcsd
  3. Jun 26, 2011 #2

    phinds

    User Avatar
    Gold Member
    2016 Award

    Object Oriented Programming (OOP) is about non-sequential programming methodology, which is used by Java, C++, C#, VB.NET and I think all robust modern programming languages. C is a sequential programming language that you learn on the way to learning C++ (It's the syntactical underpinning of C++).

    Why anyone would want to learn FORTRAN I don't know. I hypothesize that BECAUSE it is a very old language there are a TON of scientific programs written in it. FORTRAN was first compiler language that got widespread use, and as a side issue probably the worst; it is so bad that when it came out, the ACM (Association For Computing Machinery) banned it from formal papers, requiring ALGOL instead. ALGOL was much better but was supported by an IBM rival (Burroughs) and therefor shunned by IBM, thus its failure to catch on as a widely used language AND thus FORTRAN's success (IBM owned the computer world back in those days and Burroughs eventually went out of business).

    If you learn JAVA, learning C++ is easy (and vice-verse). If you learn FORTRAN, nothing is easy.
     
  4. Jun 26, 2011 #3
    I'm a few years in with C and Java and I like them both. I'm not sure which is easier to pick up, on the one hand, getting used to OOP concepts with Java is a small hurdle, and with C, learning how to manage memory and other low level things takes some time.

    Both languages are similar to many others, OOP aside. A lot of what you learn will count for any language you want to learn.

    Best thing is just to pick one, get the environment setup and make a few small programs!

    Oracle - Java Tutorial
    http://download.oracle.com/javase/tutorial/

    C & C++ Tutorials
    http://www.cprogramming.com/tutorial.html
     
  5. Jun 26, 2011 #4
    Programming is extremely useful, if not essential, to the study of Physics. A great majority of physical problems are studied using computational physics. For example, in Astrophysics and plasma physics you must write software to solve the equations of motion for systems such as galaxies, star clusters, etc, because there are just too many objects to keep track of and usually you will run into the problem of facing nonlinear behavior. Computational physics is the application of numerical techniques to physical problems. The reason that we must use it to solve physical problems is because most phenomena in nature is nonlinear and the equations that describe nonlinear phenomena (Nonlinear Differential Equations, etc) usually do not have analytic solutions; that is, they do not have solutions that can be written down as a sum or product of elementary functions (sin, cos, e^x, etc). They can only be numerically approximated.

    With that said as to the importance of Computational Physics let me explain why Fortran is used and what is the difference between C++, C, Java, etc.

    To my knowledge, Fortran is used because it has many different numerical software packages that Physicists, mathematicians, and researchers from various disciplines can take advantage of in their simulations. The second reason is that it is very old. Yes being old is a reason to use it because a lot of software has already been written in Fortran and it is very difficult to change programming languages when you're working on massive project that spans decades (I've seen some of these before and they are not pretty).

    There are two programming paradigms that you should be aware of if you are to start writing software. There is the procedural paradigm and the Object Oriented paradigm (these are not the only paradigms but the most popular and most successful). Procedural programming languages such as C, Perl, Fortran, etc, are written around the idea of using procedures (functions, methods, subroutines, etc) to organize their code. (This is the worst explanation I've ever given but you should read in to it).

    Object Oriented languages such as C++, Java, Python, Ruby, etc, are written around idea of creating independent entities called objects that maintain their own state and send and receive messages to other objects. They still have procedures but each object is responsible for it's own procedures (usually called methods if defined in the object).

    Ok, so don't worry if you don't understand all the terminology I just used. You'll learn it eventually (Polymorphism, Inheritance, Encapsulation, Extensibility, etc).

    Always be aware that when you ask 5 people what the best language for such-and-such a task is you will get 3 answers. The importance of a programming language is usually subjective. A person will probably tell you that the best language for the job is the language that they know the best. It really doesn't reflect anything about the programming language except for their own knowledge of it and their ignorance of others.

    With that said I think you should learn Java, Matlab or Mathematica, and C++. It is much easier to write graphical visualizations in Java than it is C++ (for beginners at least) and it has a nice garbage collector so that you don't have to worry about memory management (unless you get into advanced multithreaded apps). Matlab or Mathematica is essential as well because of the HUGE repertoire of math packages and graphing capabilities, not mention the hundreds of other things I don't have time to mention. Learning C++ is also essential. It is about 20 times faster than Java (at least that's what one of my programming profs told me once) and is one of the most widely used languages in the industry. It's used in video games, operating systems, drivers, graphics, simulations, you name it its there.

    Also if you learn Java then you will also learn Object Oriented Principles because the structure of the Java syntax forces you to write Object Oriented.

    I would also sugest that you learn a scripting language such as Ruby, Python, or Perl. These come in handy so often. Just for simple things like sorting through tons of files, pulling out data from them, saving csv files, posting them to the web, etc.

    If you need further direction send me a message on here.
     
  6. Jun 26, 2011 #5
    For as long as you are asking opinions, I will throw in my 2 cents: Fortran and Python

    I tell you...people out there underestimate Fortran.

    Sure is old, but there is a reason why is old...because it has not died! And it is over 50 years old. There is a lot to be said about marketing and universities trying to attract students with their latest offerings...that's probably why Fortran stopped being offered, and they probably do not even teach C anymore, they probably teach Java as the very first language...talk about a huge marketing engine (Sun Microsystems) behind a language...I recently read and article about preople from the industry complaining about that...that universities are focusing too much in showing students how to quickly put together some program, webservers, or fancy looking GUIs without really teaching how to do good, effective programming, and of course learning about good memory management.

    For a physicist, C has nothing on Fortran; in fact, Fortran has what C has and them some. Learning how to program in Fortran is very easy; you have all the same flow control structures, arrays, structures, etc. Additionally, since Fortran 90, Fortran has the ability to handle arrays in many operations in a very friendly manner, you know, as if they were scalars.

    In academia and in scientific community Fortran, I believe, still rules. As metioned before, many well established numerical libraries are written in Fortran...in fact, the core libraries for MATLAB are written in Fortran.

    Then, it comes Python...

    ...again, if you are planning on being a physicist and not some webserver programmer...I would suggest Python over Java, any day. Sure, Java was written to overcome C++ shortcomings but Java is always Object Oriented and you need to learn all sort of things before you can program in Java.

    Python is very english-like and concise, you can program in Python rather easily and you don't have to know Object Oriented programming, you can start including OO as you see fit. I noticed that a previous poster included Python as an OO language...it can be, but it does not have to. I have seen it over and over that you can program in Python with a lot less code that you would need in Java...we are talking less than half! more like in the 20 to 30%, I have heard.

    There is a very large engineering and scientific community behind Python. There are modules out there that make the design of scientific applications in Python very easy, even GUI-based applications and you never have to see a widget or worry about anything like that. Also, there are several major visualization kits for Python, etc...Also, applications are starting to choose Python as their scripting language.

    After you get our opinions here, I really encourage you to google a handful of choices and see what you find out there...you will see.
     
  7. Jun 26, 2011 #6

    fluidistic

    User Avatar
    Gold Member

    Fortran 90 is the only language taught for undergraduate physics students in my university, for a numerical analysis course. I found it to be pretty simple to learn; I mean the basics of course.
    So far I've enjoyed it very much and I wish I could work on a project involving some computations, I'd be glad and I'd use Fortran unless I'm told not to.
     
  8. Jun 27, 2011 #7

    rcgldr

    User Avatar
    Homework Helper

    To the original poster, I'm not sure it matters much which language you learn first. If Fortran is offered as a class you might want to consider that as an option, as it's fairly easy to learn and mathematically oriented. C can be easy to learn if the class starts off with simple programs. C++ is a superset of C, so the difficulty in learning it would depend on goals of the course (for example basic programming versus user interface stuff (like Windows)). The main issue is what language is most commonly used in the curiculum that you'll be following.

    Matlab is a combination tool and programming language that can help you quickly get answers to mathematical problems, and is popular for both students, engineers, and physicists.

    All of these are sequential (procedural languages) in that the program specifies the order in which operations are to be performed. What makes the object oriented languages different from older languages is that they encourage combining related variables and functions into structures (classes) to create the "objects". Some programs may be event driven, and may include multi-tasking, but the code to handle each event is still procedural.

    One example of non-sequential programming is a type of associative programming such as manually wired plugboards used on early computers (unit record tabulators) as "programs", and the archaic languages designed to be similar to plugboard programming, FARGO, RPG, ... The programmer specifies linkages between input and output fields, and what operations to be performed with the fields, but there is no control of the order. It's as if all the operations are performed in parallel. I would not recommend this type of programming to anyone as a first language, because the concept is so different than normal procedural programming languages.

    http://en.wikipedia.org/wiki/Plugboard

    Another example of non-sequential programming is declaritive programming, and which I also wouldn't recommend as a first language type:

    http://en.wikipedia.org/wiki/Declarative_programming
     
    Last edited: Jun 27, 2011
  9. Jun 29, 2011 #8
    Thank you for the links, I'll be sure to check them out and let you know how it goes.
     
  10. Jun 29, 2011 #9
    I think I have a few questions I will message you with soon but I'm not sure what I want to ask. I'll look into the languages you suggested first.

    Thanks for the advice.
     
  11. Jun 29, 2011 #10
    I think I'll look into Python then. I think they're going to require that I take Java but I don't think it will hurt me awfully in the long run.

    Thanks for the help.
     
  12. Jun 29, 2011 #11
    If you're getting into physics, you'll be surprised how much you see FORTRAN. The idea that it is an old language is kind of silly, since there is an update every few years (90,95,2003,...). I've seen it in electromagnetism projects, ocean optics code everywhere (RIT's modtran is in FORTRAN 77 and still being used today to model the atmosphere), and phytoplankton research at NASA.

    Java will give you basic ideas about programming, but you want to get into FORTRAN and C/C++ as fast as possible. Matlab is a good tool to know, but it is rarely used for anything other than testing or pretty graphs.
     
  13. Jun 29, 2011 #12
    If I'm trying to get into a language quickly, what do you recommend I begin with and how can I pace myself? I have a rather complicated schedule (or it feels as such to me) and I'll end up in an odd mix of elementary classes and higher order classes this upcoming fall (like Programming 1 and QFT and PDE x.x'.....) I have about 2 months to burn through some basics of a language I'd guess [with a 16 hour summer load that I may need to consider].
     
  14. Jun 29, 2011 #13
    Most structures of computer programming languages are similar. The transition from FORTRAN to C to Matlab is very easy since their syntax is very similar. I would recommend starting in C or FORTRAN because they can be used as great building blocks to learn other languages quickly. Find a book that has programming challenges in it and do two chapters a week (if you plan on doing this outside of classes). Cygwin is a great Unix shell if you are planning on programming in a Windows OS.

    Let me know what language you decide on and I can possible recommend a book (maybe even a PDF of a book if possible).
     
  15. Jul 2, 2011 #14
    I think I'm going to start with Matlab since it will be a fairly smooth start compared to some other languages I could choose from. I'm a little bit Computer Science stupid so while I know what a shell *is* I'm not sure why it would be of use ^^;... I know that for Java people have writing environments that can compile and run code that they're working on and I know that a shell takes commands and processes them like DOS does but I can't do much more than ping a website with DOS. How will having Unix shell be of use for programming in the above languages? Is it going to be where I actually run the programs usually or where I would test aspects of the programs?

    Thanks for your time and if you have a Matlab book or pdf you could recommend that would be fantastic. If not I am fortunate enough to go to a university with a mediocre library where I may be able to find something, x.x' maybe.
    Elwin
     
  16. Jul 2, 2011 #15

    rcgldr

    User Avatar
    Homework Helper

    Cygwin creates a Linux like environment that runs under Windows, so it's more than just a command line shell. Eventually you'll want to use what ever OS your school mostly uses, Linux or Windows. If you're writing generic console stuff (no GUI), it's possible to write it so it works with both OS types.

    I assume you'll be running Matlab under Windows.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Programming and Computer Science in Physics
  1. Computer Science (Replies: 8)

Loading...