1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Programming language for engineers

  1. Feb 19, 2009 #1
    Im starting my bachelor degree in mechatronics engineering this semester, i have very little knowledge in programming and so want to start learning a language. Ideally a language that would give me the upperhand for employment or one that is most relevant to engineering.( maybe they all are i don't know)

    I have done a little bit of research into which languages are requrired in job advertisments some which pop-up include MATLAB, Labview, simulink, Solidworks, PLC, scada, dephi, c, c++, and others.

    Basically which programming language is most suited for a beginner to learn that will be useful to the course im doing?

    Help is greatly appreciated.
  2. jcsd
  3. Feb 19, 2009 #2
    In order:
  4. Feb 19, 2009 #3
    I would say in this order:
  5. Feb 19, 2009 #4
    I'd say learn Python or C/C++. Once you've got that down, picking up Matlab, Verilog/VHDL, etc. later on will be easy.

    Starting out learning Matlab before you've taken any classes is not going to be very fun. You can do a lot more educational and 'fun' things with Python or C. Most Matlab books are going to offer dry examples that will be over your head. Not to mention you'll have to either pay or pirate (not recommending this!) Matlab software, while C and Python compilers can be had for free!
  6. Feb 19, 2009 #5
    I would recommend C++, with it you'll be able to easily understand MATLAB as well as C (for embedded programming). Then you can teach yourself assembler (perhaps for an AVR microcontroller) and you'll be good. Alternatively you could consider consider C# or Java (yuck).C# is kind of cool, I haven't had much time to do anything with it, but it looks very good.
  7. Feb 19, 2009 #6


    User Avatar
    Science Advisor
    Gold Member

    Note that whereas it is true that Matlab can be used to as a programming language it can also be used as a sophisticated calculator, and that is how most people use Matlab at first.

    Most Matlab programs are just very simple scripts and unless you are doing something fairly sophisticated there is no need to use things like if-blocks, while loops etc. At most you might use a For loop to assign values to a matrix and a few functions. Hence, you do not really need to know how to "program" in the usual sense of the word in order to write useful Matlab scripts.
    In fact, in the "old days" before version 6 it was best to avoid all loops and control statements since they made the programs VERY slow (in more recent version is JIT compiler is used so now it is ok to use loops).
    This still affects the way most Matlab programs are written.

    My point is that writing Matlab scripts is VERY different from writing programs in e.g. C.
    Pythin (with Scipy) is the only programming language that I have ever used that reminded me of Matlab (which is sort of the point with Scipy).

    Hence, knowing Matlab is -in my view- more a "math-related" skill than a "programming-related" skill. It is very useful if you are e.g. modelling physical systems etc; but there is no point in learning Matlab if you are planning to e.g. design hardware; then you are better off learning VHDL etc.
  8. Feb 20, 2009 #7
    He just started his engineering degree this semester - learning VHDL is going to be basically impossible. I would never recommend that for someone as their first language (f95toli - I realize you didn't recommend he learn VHDL first, I'm just saying this so he doesn't go off and try to do it).

    I agree with what you said about Matlab, I think he's better off just picking that up during his courses.

    Go with Python or C/C++ for your first language. It's not always a great idea to start off with C/C++, but since you're only going to be tinkering to get some background in programming I don't think it will hurt.
  9. Feb 20, 2009 #8
    This is going to be a little tldr; but I have some strong opinions about this.

    The correct guidance depends on what you want to get out of learning to program. If you want to have the bare minimum of understanding for practical programming as an engineer, then you could probably learn a little C++, maybe some Fortran and Matlab, and leave it at that. However, this would be a great disservice to you!

    If you want a real understanding of programming from a deep perspective, I would recommend you learn 1 language from each of these categories:
    Procedural (eg: Fortran)
    Object Oriented (eg: Java/C++/Python)
    Functional (eg: Scheme/Lisp)
    Declarative: (eg: Prolog/Regular expressions)
    Math/Array-based: (eg: Matlab)
    Assembly (Choose some embedded cpu in an interesting application and learn how to program it)

    Java is a good place to start because it is pretty newbie-friendly and you can make little games and such without as much hassle. Python might also be a good place to start.

    In each of these cases, try to use the language's strengths to solve your programming problems - use array operations instead of loops in Matlab, use recursion rather than looping in Scheme, use object-oriented structures in C++, and so forth. This is basically what the first few CS-for-CS-majors classes will do at top universities. Now This is a big task, but if you do it then you will have a great depth and understanding of programming in general. Even though you may never use a functional programming language again, just knowing it will make you a better programmer in whatever other language you use. You will be able to pick up the fundamentals of any other language in a weekend or so.

    Ok just a note because you mentioned it: Solidworks is not a programming language, it is a CAD program. You use it to draft 3D models of mechanical parts and assemblies, similar to how you would build a model in 3d animation programs (Maya, Max, Lightwave, Silo, Blender, Rhino, etc), except it is aimed at engineering applications. The main difference is that models are precisely specified parametrically, and in return there is less low-level mesh control. It's all point-and-click, there is no programming involved.

    If, by the initial post, you want to learn a CAD program, Solidworks is a great starting point. I would recommend not doing AutoCAD. A lot of people just use AutoCAD because it has big name-recognition, but it is a fundamentally 2D program. They started with 2D many decades ago and tacked on 3D aspects as computers became powerful enough to handle it. If you start with AutoCAD you will develop a lot of bad habits. SolidEdge and Inventor are pretty good alternatives to SolidWorks. Modern parametric modeling programs are all very similar so if you know 1 you know them all.
  10. Feb 20, 2009 #9
    Thanks for the helpful input!

    Looking at the course outline more closely it shows that the first computer-related course im taking involves Matlab.

    These are the books they recomend for it:
    Highly Recommended

    Palm W.J., Introduction to Matlab 7 for engineers 2ed, 84.50


    Chapra S, Applied Numerical Methods with Matlab for Engineers &, 121.46

    I guess i have to take matlab as my first language, i was thinking of learning c++ first(until found out that im using matlab) do you guys think that I should self-teach c++ while doing matlab at uni in the same time? or is that too much and will it get confusing? or should i just stick with matlab?
  11. Feb 20, 2009 #10
    Matlab is kind of an unusual language to start with, but it might work? Post back in a few months and let us know how it goes, I'm actually curious.

    C++ is a very powerful but dangerous language. If you're not careful it might bite you in the face. Having a beginner start with C++ is like having a toddler play with a set of knives IMO. It also has a lot of weird little idiosyncracies that are not present in other languages. But a lot of people started there so it must be OK.
  12. Feb 20, 2009 #11

    Vanadium 50

    User Avatar
    Staff Emeritus
    Science Advisor
    Education Advisor
    2017 Award

    My opinion is that long term it's probably more useful to learn to program than any specific language. (And being able to cobble something together that happens to run is not what I mean by learning to program).
  13. Feb 20, 2009 #12
    I'll stick by Matlab first. The guy is studying to be an Engineer not a programmer. Having said that, knowing C or C++ is probably also required in a career sense. Employers stick it in resume requirements and expect it. It's use in hardware design in very small; in terms of things like DSP signal processing is common. But then a lot of assembly language diving is also done.
    As illustrated above, being truly competent in programing is a full college major. If in addition signal processing is including that's even more of a burden. When the study concentration is on programing, the actual engineering is short-changed. I have seen good engineers hack together extremely bad programs and most programmers (with few exceptions) make a hash of actually doing programs that deal with engineering.
    I take engineering as dealing with real world functioning; whereas programing is trying to construct things in a realm where you get to make up the rules out of clouds as you go along:):)

    There is a free compatible program "Octave" which has been around (and improved) for a long time. The documentation is also freely available.

  14. Feb 20, 2009 #13
    I think learning a good general purpose language like python or ruby would be the best choice, while industry might still rely on those old strongly typed languages now I definitely think, especially for people who primary job is not programming that these more intuitive and easier to pick up languages like python are ruby are going to become more ubiquitous in the future. In addition programming python gets your mind conceptually ready for the other closer to the machine languages you might need to use sometime down the road. Learning a language like C++ can be a long and tedious ordeal and should probably only be undertaken if it is required.

    I should note that I mean this from a general prospective as I have no special knowledge of what sorts of programming is undertaken by the typical mechtronics engineer.
  15. Feb 21, 2009 #14

    I hear that every now and then.....but what does it mean?
    how can a language be dangerous?

    and isn't c generally taught first in American Uni's rather than c++?

    c is my first language btw...
  16. Feb 22, 2009 #15
    c++ all the way.

    Just be careful and deliberate... use good programming practice and develop good habits. You'll be fine.
  17. Feb 22, 2009 #16


    User Avatar
    Science Advisor

    I'll take this off-topic a bit, and ask if it's just me, or do engineering types (such as myself) swear by MATLAB (and its various toolboxes, and occasionally Simulink) while science and programming types almost always go with C++ or Fortran?

    The various mentalities at play, or just vendor lock in (inasmuch as C++ has a 'vendor')?
  18. Feb 22, 2009 #17
    Honestly, I just don't really get Matlab. I don't find it any easier to use than C/C++. Oh well.
  19. Feb 22, 2009 #18


    User Avatar
    Science Advisor

    As a formal programming language, sure. However, I think many of us engineering types started off by using MATLAB as a glorified calculator / matrix solver, and then went on from there (usually along the lines of 'automating' a process via functions, and then MATLAB scripts, and then almost full-blown programs). And the (ab)user friendliness / tolerance is (IMO) second to none, as is the online 'help' documentation.

    EDIT: Almost as if it weren't *really* a programming language.

    EDIT: ...And I just remembered what my username on this forum was... :-D
  20. Feb 22, 2009 #19
    When you are presented with a programing problem once every 4-8 months, you ask what it does for you and how hard will it be to make it do what you want. Matlab, Octave, and Scilab all do a great deal of calculational programing for you. Actually APL and J do more but are a bit harder to get started in; and are not as obvious in the notation. Thus they are harder too present and get reviews for.
    C++ and C easily allow a great deal more freedom in the algorithms, moving away from physical models into a intellectually (dream?) created realm (for better or worse). C++ is also supposed to be amenable to larger scale programs and portabilitity. I can't speak to "large scale" but I think the portability aspect is overblown. The only real case where I have seen it effectively used is in Linux which is basically done in C; but that is quite impressive.
    Personally my programing has been along the lines of physical modeling, signal processing, control, and drivers. In these case the ease of notation involved in the scientific languages counts for a lot. In signal processing if Matlab, Simulink, Scicos, and Scilab fails in performance; it usually results in machine language code. A professional programmer did point out to me that this "failure" is the result of the compiler. He was right and this necessity hopefully fades into the past as compiler and library performance improves. I have studied Python a little and it also seems provide a great deal of engineering support; but not the notational support.
    In the end; it's how much the language (or formalism) can do for you for a given task. In engineering you want computational and modeling support; in programing (say routing calls or balancing millions of accounts) you want structural support and flexibility. In both cases you must be able to get reviews of the actual code and performance in order to get verify your mind is in the right place.
    Be aware; sometimes performance, maintainability, etc.. are not obvious. In my brief excursion into Prolog many years ago I found the maintainability to be quite good; something that to me was quite counterintuitive.

    Standard disclaimer: Your mileage will vary.
  21. Feb 22, 2009 #20
    I don't understand why you're in such a rush to take programming classes. It's better to learn the fundamentals of your subject first. Programming, in my opinion, is the most boring subject on Earth. I took classes in C++ and hated every minute of it. It wasn't until I took a computational physics class with Matlab that I started to enjoy programming, and realized I was actually pretty good at it.
  22. Feb 24, 2009 #21
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook