Comparing Python and Matlab for teaching in science

How easy are they to learn?

Python is a standard language for courses designed as an introduction to computer programming.

Here is a quick survey of some major US Universities:

Of the introductory programming courses run by Computer Science departments in the UK Russell group, 12 teach Java as a first language, 4 teach Python, 4 teach C and 3 teach Haskell 1.

Common languages other than Python in introductory programming courses are Java, C, and Haskell. Neither Java nor Haskell are widely used in psychology or scientific programming. C has a niche use for system programming and speed optimization, but it is a bad choice for the kind of high-level programming that most scientists use for their work.

I don't know of any university where their main introduction to programming course uses Matlab. One reason may be the opinions shown in this survey of computing languages. Sadly the source site had gone down at the time I wrote this, but the Archive.org copy has pages summarizing Python and Matlab. Abstracting from my earlier summary: the survey responses suggest that Matlab is a niche language, and is harder to learn than Python. Matlab code is less elegant, less readable, harder to maintain and harder to re-use.

In particular, Matlab rates much higher than Python on the question "This language is unusually bad for beginners", "This language has an annoying syntax" and "Writing code in this language is a lot of work".

Computer science departments often choose the language for the lessons it can teach about programming languages, rather than their general use for doing real work. The fact that institutions like Berkeley and MIT are switching to Python from other languages suggests that Python has enough range to cover both domains (see below).

Number of users

  • Popularity of Programming Languages: "The PYPL PopularitY of Programming Language Index is created by analyzing how often language tutorials are searched on Google.". October 2017 - Python second at 17.6% (after Java); Matlab 11th on 2.2%.
  • TIOBE index: "The ratings are based on the number of skilled engineers world-wide, courses and third party vendors. Popular search engines such as Google, Bing, Yahoo!, Wikipedia, Amazon, YouTube and Baidu are used to calculate the ratings.". Python 5th (after Java, C, C++, C#) at 3.9%. Matlab 13th at 1.9%.

Trends

  • The Incredible Growth of Python: analysis of StackOverflow search trends in high-income nations. Python was the most visited tag of any language in June 2017, at around 10%, and has had 27% growth from 2016 to 2017, with a linear trend since 2012. In contrast, Matlab was at 0.4% and had about an 18% drop from 2016 to 2017. Much of the growth of Python is in "data science" searches.

Range

  • Data analysis: Python >> Matlab. Matlab is not a serious contender in data science. The StackOverflow data science search tag statistics show machine-learning as the top tag with 2173 questions, Python is second with 945 and Matlab is 52nd with 60 questions.
  • Statistics: Python ~= Matlab. Both have deficiencies. Python has the major machine learning toolbox.
  • Real-time programming: Python == Matlab ? (Psychopy == Psychtoolbox - they both claim roughly around 12K active users: Psychopy users, Psychtoolbox Wikipedia page);
  • Shell scripting: Python >> Matlab;
  • Tutorial and demo development: Python > Matlab (Jupyter Notebook);

For example, for a course on brain imaging, students should be able to:

  1. write simple command line scripts for handling files and directories;
  2. script their analyses in FSL and other packages;
  3. present stimuli for experiments;

Matlab is not a good choice for the first two tasks.

Convenience, access, transfer

Matlab has a fairly convenient installer, but there are similar installers for Python - such as the Anaconda Python Installer.

Unlike Matlab, Python and all its standard packages are available for free, so a student can install a full copy on any machine they want, and they can take their installation to their next lab or next job without worrying about Matlab license fees.

Using Python makes it easier to collaborate with researchers in universities that cannot afford or will not pay for Matlab licenses.

Culture

Python is open-source. This may be the reason for the following features of its community:

  • strong culture of testing and quality;
  • well-developed packaging;
  • tradition of users becoming contributors.

Employability

Python programming is a desirable skill in industry; Stackoverflow Jobs: Python currently gives 721 hits, Stackoverflow Jobs: Matlab gives 36.

Moving from Matlab to Python

See this excellent white paper.

Most scientific users of Python install the following Python packages:

For example, the Anaconda installer installs Python, these packages, and many more.

These packages together give you a rough equivalent to a standard Matlab installation with some toolboxes installed.

There is no direct Python equivalent of the Simulink application - see Simulink alternatives.

links

social