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

Help picking a programming language

  1. Mar 26, 2013 #1
    Hello to every one,

    I am looking through the threads for some information on which programming language to pick on
    but I can't find an answer that covers me. So I was hoping you could help me out.

    So I am a Civil Engineer doing a research degree. My work involves many numerical simulations.
    I am currently making my codes in Matlab and the run finely. Matlab is a good tool but it runs realy slowly.
    So for example my codes take at the time minutes to half an hour for a physical system of a few hundreds of degrees of freedom, but I will soon be looking on systems of thousands and possibly millions of dofs, so I am looking at something faster.
    At a later stage I will also be manipulating and getting information out of many different databases
    and I might be willing to create a stand-alone program with a decent GUI for a company to use.

    So far I have been trying to decide between python, fortran, C# and C++.
    I seem to be closing down on C++ but I would like some contribution from people who know these languages better.

    Any info is highly appreciated
  2. jcsd
  3. Mar 26, 2013 #2

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    In general you should pick whatever you find easiest to learn - so try the ones that interest you.
    Out of your list, I would lean towards C++ over C# and python over fortran ... my bias is mainly ideological: I prefer free/libre software where possible. iirc the C# platform is still proprietary.

    Have you had a look at GCC (the Gnu Compiler Collection) - GCC is an integrated distribution of compilers for several major programming languages. These languages currently include C, C++, Objective-C, Objective-C++, Java, Fortran, Ada, and Go.

    You probably won't need all the features.
  4. Mar 26, 2013 #3
    Thanks for your reply Simon.

    The main idea is to use a language that will do my work in the shortest time possible, calculation-wise.
    I will be trying to combine high accuracy (academia-research) with speedy calculations (industry).

    But what I am trying to avoid is spending say 3 months to get the basics of a language and create my algorithm
    and then find that in another language I could have done the same in a fraction of the time.
    That is why I want to establish the best possible route, at least for now.
    A language that is easy to learn is not my concern tbh.
    My understanding is generally good of how languages work and I also know that learning a language
    as opposed to 'learning' a language is a long process, definitely longer than my projects time.

    I will have a look at GCC ;)
  5. Mar 26, 2013 #4

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    Cool - for just algorithmic number crunching you'll probably try C. I don't think I ever took advantage of object oriented stuff converting matlab scripts. afaict python is quicker to learn but generally slower in computation.

    Of course the absolute fastest for computation, given you don't mind the learning curve, is to program directly in machine code :D
  6. Mar 26, 2013 #5
    Now, that would be hard-core stuff!!! :)

    So you suggest C instead of C++?
  7. Mar 26, 2013 #6


    Staff: Mentor

    Don't just look primarily for speed look for maintainability, flexibility, organization and structure as well as prototype systems often become ugly production systems that are hard to maintain and extend without proper upfront planning and design.

    You should also consider Java. Its cross-platform, a eeffective internet api, a rich GUI environment and has a large set of libraries to go with it. For Java databases look at H2 database. For modeling a physical system look at Open Source Physics (compadre.org) which has ODE solvers and graphics for creating interative visual simulations.

    For development, you should invest in time to learn SVN or GIT and use an IDE like NetBeans or Eclipse. I use NetBeans and SVN at work and feel NetBeans is a tad better than Eclipse in that all the plugins I need are present and not third party.
  8. Mar 26, 2013 #7

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    C++ is object oriented, supporting classes etc. Otherwise it's the same as C.
    Most teach-yourself-C++ courses start with C anyway, though some people advocate going right to C++ to avoid picking up "bad habits".

    gcc does both so...

    I honestly cannot advise you because I don't know enough about what you are going to need or what basic programming knowledge consists of these days. A quick look should tell you where you feel at home.

    jedishrfu has some good points - you should look to the future since you don't want to have to get good at a language you then discover won't let you advance.

    There's quite a lot of advise in "similar threads" below if you really want.
  9. Mar 26, 2013 #8
    Thanks jedishrfu, I will have a look at those.
    I installed Code::Blocks to experiment with, but at first I need to establish in what I want to work with.

    Simon, thanks for the clarification. I tried the similar threads which do have info but didn't help me decide.
    I did first steps with C++ and Python and both seem ok, meaning I didn't feel lost and understood the basic steps etc.

    It seems so confusing as you have a lot of options with different advantages and disadvantages.
    And I see that for every answer I am looking for, 10 more questions arise.
    In the end what I would love would me a faster Matlab. M++ or JaMa would it be named, I wouldn't mind :D

    Anyway, thanks for your comments guys
    I'll keep on the look-out and see if something feels to match better.
    I might just follow what will seem more interesting in a personal level.
  10. Mar 26, 2013 #9


    Staff: Mentor

    If you just want to play with java to see if you like it or not, try the processing.org IDE. Its designed for graphics artists to design interactive art in code using the OpenGL graphics api. They have a lot of examples and there are a couple of books on how to use it (Getting Started with Processing by the authors of Processing)
  11. Mar 26, 2013 #10


    User Avatar
    Homework Helper

    Find out what language your school primarily uses for numerical simulations, and use that. There's probably a library of code in that language that you can take advantage of. Does your school have a super computer that you'll be using? If so, you may need to learn a second language, most likely Fortran, for that computer (or use Fortran for that computer and PC).
  12. Mar 28, 2013 #11


    User Avatar
    Gold Member

    Of the four languages you mentioned ( python, fortran, C# and C++ ), I have used the latter three extensively and Python only a little. C# would be better, IMO, than C++. The .NET Framework that it runs on (on Windows) is highly optimized for good performance, and it is a more modern, clean and safe language than C++. Once a C# program has "warmed up" (that is, once all its code has been called once and just-in-time compiled), it actually runs as native code just like a C++ program would, and is about as fast. And C# is just much nicer to deal with in every way by hiding, just for example, integer storage size issues from you (for the most part--you can still overflow an integer in ANY language).

    It does sound like you are going to need to learn about multi-threading--a non-trivial side trip--if you want to develop user interfaces for your computations.

    However, depending on the algorithms that you are coding, you might want to look into parallel programming languages such as Erlang (one of many examples) but only IF the algorithm itself can be analyzed to have parallel elements. I've used Erlang a little bit, which is why I mention it, and it allows for independent nodes that you can "call"; requests will queue up on a node in first-come-first-served order and then execute there. If your computations can be broken into a bunch of independent nodes that can work in this manner, this could save much time, because in modern computers, compilers for languages like Erlang can actually allocate different physical processing elements (think quad-code processors, just for example) to different nodes.

    Finally, if you have a massively parallel algorithm, there are cloud-based languages (MapReduce is an example) that can allocate computations out to different "machines" in the cloud in parallel. Most cloud computing is not free, but if you are at a major university, you might find free cloud facilities. If you are interested in concurrent computing, you can read "The Art of Concurrency" by Clay Breshears to get a good introduction to the technology--which is radically different from traditional programming. Companies such as Google, who process enormous amounts of data, are relying heavily on concurrent software.
    Last edited: Mar 28, 2013
  13. Mar 29, 2013 #12
    According to the Computer Language Benchmarks Game http://benchmarksgame.alioth.debian.org/
    programs written in C run the fastest but those are micro benchmarks that are very unreliable.
    C# is good for creating GUIs under Windows. For platform independance Java is probably better. However Python is also great for creating GUIs. You can by the way use two languages to write your programs, e.g. C for the number crunching and some other language for the rest. Every language offers some way to make the code interact with C code. I also like Scala a lot. It's a high level language yet it's as fast as Java and it comes with features that make parallization easier.
  14. Mar 29, 2013 #13


    User Avatar
    Gold Member

    I will agree with DrZoidberg that Scala is a very nice language. It is a superset of Java, and includes several "parallel processing" capabilities, including a decent implementation of the "actor's model". The actor's model is similar to Erlang that I mentioned above, allowing for a kind of parallel processing for programs that can run as completely independent "nodes"--each node (basically, a program) automatically processes requests in the order they are received, asynchronously (which provides a performance boost, as multiple CPU's or cores can be used to implement the different processing nodes).
  15. Mar 29, 2013 #14

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    Oh yes... then there's JAVA - which is probably the best all-rounder mentioned so far.
    You are only talking about converting matlab m-files designed for number crunching right? Not so worried about the GUI for instance, or running fancy animations? In which case, all the options are very similar - you'll be using a small subset of the languages capabilities.

    Part of the Gnu Compiler Collection is GCJ
    GCJ is a portable, optimizing, ahead-of-time compiler for the Java Programming Language. It can compile Java source code to Java bytecode (class files) or directly to native machine code, and Java bytecode to native machine code.

    There are free/libre implimentations of the JRTE ... the main advantage being that it is cross-platform. JAVA is also the backbone of Android.

    If you are absolutely stuck with windows, something that handles the dot-net framework is probably a good idea in the long run .... that would normally be C#, which is best at it. However, there are alternatives approaches.

    There are free/libre implimetations of JAVA besides the GCJ approach:

    What you end up doing really depends on the details of what you need and where you see yourself heading.
    There are extensive howto's (even software) for converting matlab m-files to JAVA, C++, or python ... so any of those would suit your immediate purpose.

    Everyone has their favorites though.
    Happy hunting.
  16. Mar 31, 2013 #15
    Thanks for all of your replies.
    They have been really helpful!

    Simon, no I will not convert my m-files but write them from scratch in the language I end up using.

    Happy Easter,
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook