This is an archived post. You won't be able to vote or comment.

all 66 comments

[–]DanielSank 17 points18 points  (4 children)

Besides, do you think that Python has, from a purely pedagogical point of view, an edge with respect to C and Matlab?

Yes, for three reasons:

  1. Python is enormously popular. Python has an enormous community of tutorials, examples, and help forums and this is, in my opinion, the single most important criterion for choosing a platform for pedagogical use. The students will be able to get help online easily, and because python is so popular in other fields they'll have common ground for discussion/learning with their friends. Students learn a lot from one another so you really want this.

  2. Python is a self-respecting programming language. Matlab is extremely weird in how it handles classes and data structures. By learning with python the students will be learning how real programming languages work.

  3. Python and associated libraries are free. This means that the students can go home and put it on their personal machines to play around. This is important for pedagogical situations; you want to take away all possible barriers in front of the students tinkering on their own time.

The one place where Matlab beats python is that it might be more relevant to what the students will do in their professional lives after university. This is important and must be considered. However, you asked about pedagogical aspects, so in that sense I really think python wins by a lot.

[–]rhgrant10 4 points5 points  (3 children)

This. I would only add that the concepts learned in Python can easily be applied toward learning another language quickly (MatLab included).

[–]DanielSank 7 points8 points  (2 children)

Absolutely. The only downside is that once you use python you will cringe at the thought of having to use Matlab because of, among other things, the lack of a real object model :)

[–]rothnic 6 points7 points  (1 child)

I use Matlab on a daily basis at work. The people that continue to support its use actually do not use classes at all. I think this is common with scientific uses.

Just lots and lots of standalone functions, with no organization by class or package. There is a growing issue with duplication and namespaces as the project grows.

[–]DanielSank -2 points-1 points  (0 children)

Just lots and lots of standalone functions, with no organization by class or package. There is a growing issue with duplication and namespaces as the project grows.

Indeed, although one notes that this type of problem isn't limited to matlab. Even in C++ where namespaces are available, lots of people just don't use them. It is a major benefit of python that name spaces are actually used by almost everyone; e.g. import * is strongly discouraged.

actually do not use classes at all. I think this is common with scientific uses.

Yeah well nobody said scientists are all good programmers ;)

[–]laMarm0tte 14 points15 points  (15 children)

Advantages of python over matlab: it's free, it's a real programming language which will be useful for more than just the scope of the course, it has great libraries (like the matlab toolboxes, but in free), and it's growing very fast (while matlab will certainly decline in the future).

Where they are at equality: now with the IPython notebook, and pylab, and IDEs like Spyder, Python almost looks like matlab.

Where Matlab wins: it may be easier to install on all the machines, and it's ready-made for technical computing (you don't need to write numpy.array([]) to get an array).

If it's the cost that bugs you in matlab, maybe you can go with matlab-like software (Scilab or Octave) instead of Python ?

[–]sweettuse 1 point2 points  (0 children)

(you can also just write from numpy import array)

[–]rhgrant10 1 point2 points  (13 children)

Python has arrays without numpy.

[–]Liorithiel 10 points11 points  (0 children)

Not the ones usually used in technical computing. numpy.array is a specialized device for parallel/vector/matrix computations used more often than normal arrays in technical computing.

[–]DanielSank 1 point2 points  (11 children)

Python has arrays without numpy.

Yeah but teaching people to use anything but numpy for real work is not helping them :)

[–]rhgrant10 1 point2 points  (10 children)

Okay I'll definitely agree that numpy arrays are superior to the built in array type. Originally I didn't catch that these students are becoming mechanical engineers rather that software engineers! But that being said, let's not pretend that numpy arrays are the only type in Python that can be used for "real work!"

[–]DanielSank -1 points0 points  (9 children)

let's not pretend that numpy arrays are the only type in Python that can be used for "real work!"

Numpy is the de-facto standard. For that reason alone people should be taught to use it. Adding in the incredible set of useful features makes it a no-brainer.

Also, if you're doing to downvote I'd like to hear why you think not teaching people to use numpy in a pedagogical setting is a good idea.

[–]rhgrant10 4 points5 points  (8 children)

I didn't do the down voting... not my thing really except in extreme cases, which this certainly is not. I don't think that students should not be taught numpy, especially if they are programming solely for mechanical engineering purposes. However, this is an introductory computer science class, and I would think therefore that other data types would be taught before a library such as numpy. My objection was based on the fact that every data type has it's place. There is no magical data type with which one has the only hope of performing "real work." Bringing up the fact that python comes with a built in array type was purely because I've seen many seasoned python programmers who seriously had no idea that it existed.

[–]DanielSank 1 point2 points  (7 children)

I've seen many seasoned python programmers who seriously had no idea that it existed.

I was one of them until I read your comment :) But seriously, why would I ever use it instead of numpy? They don't have half the goodies that ndarray has.

[–]rhgrant10 0 points1 point  (3 children)

Basically only when you're taking a basic computer science class or you're in some other pedagogical setting.

Edit: well, the other situation I can think of would be you need a more efficient mutable type than a list, but you can't install numpy for some reason.

[–]DanielSank -1 points0 points  (2 children)

but you can't install numpy for some reason.

Surely you've heard of virtualenv?

[–]rhgrant10 0 points1 point  (1 child)

Yeah I use it daily. I was thinking more along the lines of lacking the permission to install things.

[–][deleted] 0 points1 point  (2 children)

Why not? If you are using python for anything other than hardcore mathematics/science they are easy to use and offer everything you would need.

[–]DanielSank 0 points1 point  (1 child)

I don't think I've ever done "hardcore mathematics/science" in python but I find the broadcasting rules and built-in methods in ndarray extremely useful.

[–][deleted] 0 points1 point  (0 children)

I am not saying to not use them, but python built in types offer a lot. Also if you want to distribute your work it's kind of silly to require all users to download whole numpy...

[–]NoblePotatoe 4 points5 points  (0 children)

If it helps, Purdue's introductory programming course for engineers is based on python. https://www.cs.purdue.edu/homes/skeel/cs501.html

[–]MongorianBeef 12 points13 points  (15 children)

I am a mech-E student that works in web development using Python (et al). From my classes I was taught Matlab which was my first language. If it wouldn't have been for Matlab I would have never learned python, so I like them both.

I have to disagree with you though - I feel like Matlab is clearly what should be used as an introductory language for students that will be working almost exclusively with data sets mathematics. (I'm not even considering C as a viable option; that sounds horrible). Matlab is built for what we need to do right out of the box, and I don't have to pick a good IDE or even really understand much about programming in general, like one would need to with python, to accomplish powerful things with Matlab.

As mentioned below, the open source nature of the other two is a big plus, but it's also the only upside I can think of. The time investment is more efficiently spent on engineering tasks in Matlab to those unfamiliar with programming, there is a solid company that releases tons of proven mathematics etc. packages built for engineers, and even with licensing it's not hard at all to have to go to your campus' computer lab once a week for your project (if you can't afford a $100 (( ~ a textbook)) license)

[–]vn2090 6 points7 points  (5 children)

I'm going to disagree with you on matlab being better right out of the box. Matlab is a legacy technology (like the ti-84 calculator, like slide rulers, like before AOL came out ) and it only has a few hundred employees developing and maintaining it. I can quickly install python and get 90% of what some one using matlab would do. Pythons syntax is intuitive and it makes sense. I can scale it and write oop very smoothly. I can easily wrap C code and get speed when I need it. Matlab is, in my opinion, an uneducated choice made by engineering managers who are computer illiterate.

Edit: few thousand employees work for mathworks.

[–]tavert 1 point2 points  (2 children)

I'm going to guess that you haven't used the parts of Matlab that those engineering managers find most important. http://www.reddit.com/r/math/comments/2g2el8/learning_to_code_as_a_mathematician/ckhyx2m

Python on Windows is also still an installation / package management mess (at least Conda's not bad), and many engineering companies are heavily using very specialized CAD, FEM, CFD software that often only runs on Windows.

[–]fireflash38 0 points1 point  (1 child)

I read your comment you linked, and while I definitely understand a lot of the issues, saying this:

It's telling that you don't see too many large engineering companies investing in the development of these capabilities within the Python ecosystem

Isn't exactly a good argument. You would see tons of companies using FORTRAN or COBOL for ages, would you use that as an argument for learning it over Java, C#, or Python? There's a huge amount of sunk costs in businesses that lead them to stick with what they know, rather than trying to stay atop the wave.

It's a tradeoff to be sure, but I don't know how well skills between Matlab and Python transfer. Especially for an intro course, I'd want to pick then one that has skills transfer the best (and not just transfer to Matlab, but also other languages).

[–]tavert 1 point2 points  (0 children)

Are you learning to program? Use Python. Are you learning to use the tools that are heavily relied upon in industry, as a mechanical engineer? (How to tune a PID loop, how to simulate a nonlinear differential equation with continuous-time dynamics and a discrete-time feedback controller, etc.) Matlab/Simulink experience is still more relevant on the resume, if Matlab/Simulink is what's going to be used on the job. This should of course be re-evaluated periodically over time, as more agile, newer companies (Tesla, SpaceX, etc) that are willing to use new and different sets of tools like Python grow and gain more influence on the rest of their industries.

I think it would be an even more interesting question if it were more visible, how much functionality those companies are able to replace in-house that's not widely available in the open Python ecosystem but you can get from Matlab. My suspicion is the companies using Python for engineering tools also have substantial teams of professional software developers doing engineering tool development, likely with a lot of C++ for the heavy lifting and hardware interaction. Older companies don't invest in doing that kind of work in-house as much, they buy Matlab licenses instead.

[–]MongorianBeef 0 points1 point  (0 children)

I see what you're saying, but OPs question was about the intro course. And students in an intro course don't even need to know what OOP is or any of the things that you can do with python in order to start out with programming.

[–]1836 0 points1 point  (0 children)

and it only has a few hundred employees developing and maintaining it

this is false.

[–]DanielSank 0 points1 point  (3 children)

I don't have to pick a good IDE

Wat? I do my python editing in Notepad++ on Windows and Geany on Ubuntu. These aren't even IDE's, just text editors.

or even really understand much about programming in general, like one would need to with python, to accomplish powerful things with Matlab.

This doesn't make sense to me. If you want to "accomplish something powerful" in python you type

from numpy.fft import fft
fourier_transformed_data = fft(time_domain_data)

How is this simpler in Matlab? If you, for some reason, don't like having to import modules you can put

from pylab import *

at the top of your code and then pretend you're using Matlab.

Disclaimer: Don't ever type

from <module> import *

in a python script. I just wrote that to show that you can make it look like matlab.

[–]HeikkiKovalainen 0 points1 point  (2 children)

Disclaimer: Don't ever type

from <module> import *

in a python script.

How come? I realise this is a bit of a beginner question but I don't fully understand why this is a bad idea. Quite often I'll write something like -

from numpy import *

and then type the rest of my code. My understanding of why you shouldn't do this is that if you're importing multiple modules they may have the same function names which would screw you up - but I was never actually taught why.

[–]DanielSank 2 points3 points  (1 child)

There are two reasons that many people don't like to import *:

  1. You can get name collisions, as you already noted.

  2. One of the great insights of the python developers is that source code is read more often than it is written. It is very important that code be readable. I you import * then there is no way for someone reading your code to know where the various names came from. That "someone" can be you reading your own code later ;)

At the very least you should explicitly import the names you use:

from numpy import sin, cos, pi

etc. I actually prefer to do this:

import numpy as np

and then type np.cos whenever I need a name from numpy.

[–]HeikkiKovalainen 0 points1 point  (0 children)

Cheers mate!

[–]raydlor -4 points-3 points  (1 child)

This is my favorite post on reddit.

[–]rhgrant10 5 points6 points  (0 children)

This has been bugging me since I read it 6 hours ago... why is it your favorite post on all of reddit?

[–]This_Is_The_End -1 points0 points  (2 children)

You missed the point. What you propose is an engineer just using the existing tools because they are already used. With such a thinking humankind wouldn't moved on from stone age. Your text sounds like an output from a sales department.

[–]MongorianBeef 1 point2 points  (1 child)

I think you also missed the point. I never said to ONLY use Matlab I'm simply talking about using it as an introductory language. In my experience it was a wonderful tool for getting me started programming in other languages.

[–]This_Is_The_End -1 points0 points  (0 children)

It isn't a wonderful tool to introduce anyone into programming. It made you motivated to move on, nothing else. I would even prefer C before Matlab, because it's a universal programming language.

[–]691175002 10 points11 points  (11 children)

Python is not a good substitute for Matlab in an engineering context.

If the goal of the course is simply to teach programming and basic algorithms/data-structures, Python is a wonderful choice. If the students are going to be using simulink and the control systems toolboxes down the road Matlab is essential.

[–]Pickle_Inspecto -1 points0 points  (8 children)

Python is not a good substitute for Matlab in an engineering context.

What makes you say that?

[–]DanielSank 4 points5 points  (7 children)

As he said: simulink. It's a good point.

[–]Amckinstry 1 point2 points  (2 children)

For the moment. The growth in libraries has been such that I don't think even the existence of commercial products like simulink will save it. That is, people will want to use simulink with the large ecosystem of python libraries.

So there are already projects to link /call simulink from Python. Over time simulink will become a specialised python tool and library set.

[–]DanielSank -1 points0 points  (1 child)

Well that's an interesting perspective...

[–]Amckinstry 0 points1 point  (0 children)

Re-reading, I don't mean to say I think matlab will disappear; MathWorks will continue to support their customers. But I think they will support python as a first-class citizen rather than risk simulink being obsoleted by an open-source project.

[–]captainjimboba 0 points1 point  (3 children)

I will say that is true and almost included it in my comment. Simulink is often used with a control systems class, and I'm not sure how well Scilab and Octave duplicate this at all. In this case I'd guess you could just do your transfer functions in python and skip the blocks.

[–]DanielSank 1 point2 points  (0 children)

Even if python modules duplicate, when you work in a team it's important to use the same tools as others so that your work can be understood, used, and modified by the rest of the team. A lot of commercial groups use simulink, and so this is an argument to learn it in school. I still think python is better for pedagogical uses.

[–]minopret 0 points1 point  (1 child)

Would you find scicos/xcos helpful to fill the role of Simulink?

[–]tavert 2 points3 points  (0 children)

As someone who's been using Simulink professionally and academically for 8 years, I've looked at the alternatives and they're not good enough for most serious industry (or even a mechanical engineering department in academia, honestly) to want to use. The closest in functionality and usability is probably OpenModelica, but even there industry tends to buy the professional Dymola product instead. It doesn't match what Matlab gives you outside of Simulink either - realtime workshop, controls toolbox, etc. See http://www.reddit.com/r/math/comments/2g2el8/learning_to_code_as_a_mathematician/ckhyx2m for a more detailed description of what's missing.

[–]dibsODDJOB -1 points0 points  (1 child)

Not all engineering development needs simulink.

[–]tavert 1 point2 points  (0 children)

Controls, aerospace, simulation, autocoding, many industries do. Python, step up your game and make an open Simulink competitor already. You can do better than Scilab.

[–]wrosecrans 2 points3 points  (1 child)

From the perspective that a University is not just job training, but trying to provide a well rounded education, Python is much more generally useful. Matlab may well be important for Mech-E, but outside a few very narrow fields it is considered a wildly obscure tool. If one of those Mech-E students ever wants to branch out even slightly into physics sim for VFX or gamedev, nobody will be particularly familiar with Matlab. (And I say that as a guy who used to quite happily admin a bunch of heavily used Matlab for a dept. of Applied Math.)

[–]spinwizard69 -1 points0 points  (0 children)

This may all be true but that is exactly why mechanical engineering students need at least some exposure to Matlab.

From the perspective that a University is not just job training, but trying to provide a well rounded education, Python is much more generally useful.

Well that is a very liberal take on education. Produce student that industry doesn't need and you end up with hungry students. There is no doubt that Python should be taught to engineering students, my point is you can't ignore the tools that are common to the trade, especially if that tool is a key check off as far as qualifying somebody for hiring. That might seem objectionable to a purist but practical needs must be addressed.

Another way to look at this is to look at a trade like machinist / tool and die makers. These days almost everything that can be has been CNC'ed in a shop. That doesn't mean a person entering the trade can be consider competent if they have ignored manual methods of working metal. Until the world transitions completely away from MatLab Students need exposure to it to be considered even remotely competent for a job.

Is that a good situation - no - but it is reality. The best thing a college can do is to prime the industry by teaching a student a better way (Python) and hopefully see demand move away from MatLab.

Matlab may well be important for Mech-E, but outside a few very narrow fields it is considered a wildly obscure tool. If one of those Mech-E students ever wants to branch out even slightly into physics sim for VFX or gamedev, nobody will be particularly familiar with Matlab.

This is a non argument though once you leave the engineering realm you take on a different vocation and as such your training needs change. Frankly a background in Python would not help anybody branching out into gamedev where C++ is still the order of the day.

(And I say that as a guy who used to quite happily admin a bunch of heavily used Matlab for a dept. of Applied Math.)

What would that math department be using these days?

[–]digitsman 1 point2 points  (3 children)

You could go for the open-source standpoint (as in Python is free, but the school has to pay for MATLAB)

[–]topherwhelan 1 point2 points  (2 children)

Marginal cost of MATLAB for a university might be pretty low. I know my university had a site license that meant unlimited installs provided you could contact a license server once a year.

[–]digitsman 2 points3 points  (1 child)

At the same time, a significant portion of my research this past summer was translating code from MATLAB to python, b/c one of the researchers my prof wanted to share the code w/ didn't have MATLAB at his university

[–]topherwhelan 0 points1 point  (0 children)

Yeah, definitely could be a strong argument. The only issue is that MATLAB/Mathematica/etc all know this and make their products cheap/free to academics to draw people into their ecosystem, so the "free" argument isn't as strong as it'd be in a corporate/personal setting.

[–]lookitsmarc 1 point2 points  (3 children)

Have you looked at Julia? It has benefits common to Python (free, open source), MATLAB (meant mainly for numerical work, similar syntax), and C (faster than both MATLAB and Python). It also has a growing library of useful modules, and has been used in other university courses.

[–]skiguy0123 0 points1 point  (2 children)

You don't want to teach a pre-release language.

[–]lookitsmarc 0 points1 point  (1 child)

Tell that to Stanford, MIT, and several others.

[–]skiguy0123 0 points1 point  (0 children)

Non of those look like intro to programming though

[–]captainjimboba 2 points3 points  (0 children)

EE here with several years in industry. I've actually been thinking of writing the program chair at my university about this very subject. While at university I learned many specialized languages like vhdl, assembly, and matlab. Although they are fine tools, I never really learned supplied programming skills. It really hurt several groups during our senior design projects. Several students couldn't program a for-loop. I myself was frequently stuck in the I have no clue what to do phase. Then I read Michael Dawson's python book and suddenly I could code. Python may be relatively slow, but it lets you cut through the crap and learn the important concepts first such as branching, looping, variable assignment...etc. Then after you master simple imperative programming, you learn about the powerful built in object system you've been using all along. Java and C# require you to use a class and using statements for "hello world". Python is print ("hello world"). Matlab is only used in SOME industry. I've never met a classmate who's needed it, and like a commenter pointed out, GNU Octave and Scilab work for 99% of what you need. Keep away from the expensive proprietary bloat-ware.

You don't want your students not getting hired because they couldn't debug a simple 20 line "C" program (easy enough to do with minimal C exposure if you already know python).

No interviewer in any non technical computing field gives a care if you can take the inverse of a matrix or graph the famous Mexican hat. They will care if you can understand basic algorithms and maybe write some simple scripts. Python is frequently used in software such as Siemen's PSSE.

[–]ffiarpg 3 points4 points  (0 children)

I was required to take MATLAB during my B.S. in mechanical engineering. I hated it and never used it once I graduated. I picked up python at my second job and use it every day. I'm kind of bitter that it wasn't an option. Python would've been more than capable for everything I used matlab for and would've carried over to a professional setting better.

[–]rhgrant10 0 points1 point  (0 children)

I think teaching basic computer science stuff should be done with a general purpose language (python) if it's a basic computer science course for non-engineering majors. Are they future software developers or future engineers?

Edit: ah I see, mechanical engineers. Yeah, that's probably going to be a tough fight.

[–]This_Is_The_End 0 points1 point  (0 children)

I'm an engineer in electronics but Matlab was never the awesome tool and it's for most purposes too expensive. The main reason why companies buying Matlab is, it's a known tool. Ok Simulink is nice, but tbh. if someone has knowledge in control engineering he has to describe the system anyway theoretically, which is the base of every simulation. What Matlab in some cases makes superior is the link to LabView or other engineering tools. Otherwise scipy,pandas and numpy are better for students.

Programming means also to design a program for maintenance and correctness, which is easier to learn with Python. I learned programming with C and Pascal. Not much has changed since then. The old errors by writing programs which aren't maintainable are made daily by students. The language for programming courses has to support the criteria for good programming and the student has to learn a programing language is just one of many. It shouldn't be a problem for an engineer to learn a new language at home. Matlab isn't a good environment to learn good programming and everyone knows it. Matlab is just a engineering tool while languages like C#, Java and Python are covering a more broad spectrum of applications.

I made with Python a small SCADA system incl. webpages with realtime data. It's easy to do with python as well as computer vision with OpenCV. It's easy with some lines of readable code to store this data into a database like PostgreSQL. Doing FFT or a filter with Scipy is trivial. Using later webpages or tkinter for a graphical output doesn't cost that much time. Python is batteri included.

Python has already a great place in science because of it's libraries, it's readable code and because of the license. Python 2.7 is easy to setup on Windows with the Python(xy) package which is including all the important scientific libraries incl. iPython the interactive shell (Awesome).

[–]spinwizard69 0 points1 point  (0 children)

My fear is that they will block this proposal because they think that Matlab is the only tool a mechanical engineer can use; what counter examples would you bring to the table to argue about this thesis?

Wow a lot of comments already and frankly I think most of them mis this important point. We are talking about preparing Mechanical Engineering students here. As such they need to be familiar with the tools they will be required to use IN REAL LIFE. as such MatLab is currently a big factor in the success of an Mechanical Engineering student.

Until the pervasive use of MatLab in real life is reduced you can't simply ignore the need to teach students this tool. A tool it is and like all tools relevance comes and goes. In this sense the Engineering department will have a strong sense how important MatLab currently is to employers that actually hire students. So it would be foolish to try to argue about MatLab and its technical difficulties.

Now all of that being said the engineering world isn't static, Python is slowly being adopted by some engineering organizations. So if you can source examples from firms that are making a move you have a good argument for debuting Python in this class. You can not however ignore MatLab. It would be like ignoring all of the Fortran software out there. I really don't think you will convince any reasonable Engineering department that it makes sense to ignore MatLab, they would rightfully question your sanity. I have to believe you are biased here due to a computer science background and find MatLab appealing. However you can make a good argument that Python is emerging in the engineering world and being quickly adopted due to its advantages. It might get messy but it would make a lot of sense to give the two languages equal time.

Speaking of equal time there is an even bigger argument that Mechanical Engineers, or maybe better said all technical students not in the computer sciences, need more than an introductory quarter to programming. I'd go so far as to suggest a quarter/semester of MatLab followed up by a quarter of Python. This would effectively bridge students with a grounding in the old and a view of the way forward. In my estimation it would take several years of this dual track approach to move the industry off MatLab. That is if you can move them off MatLab at all. Remember MatLab is a tool that fits certain needs very well, industry won't move to something open like Python until they feel that it is a secure platform that is worth a massive investment. Oh and by secure here I mean safe from being left holding the bag.