“Science is what we understand well enough to explain to a computer; art is everything else.” – Donald E. Knuth

About the Lectures

Overview

To state the obvious,

  1. programming is awesome
  2. economics is fascinating
  3. mathematics and statistics are powerful and beautiful tools

So, being the intelligent, thoughtful, fun loving guys that we are, we’ve decided to mix them all together into an entire website, just for you

Topics include

  • economic theory and empirics
  • related mathematical and statistical concepts
  • algorithms and numerical methods for studying economic problems
  • the basics of coding skills and software engineering

The intended audience is upper level undergraduate students, graduate students and researchers in economics, finance and related fields

There are two versions of the website, a Python version and a Julia version

Our point prediction is that these will be the two most important languages for scientific computing in the medium term, for economics and more broadly

Both are modern, well designed, open source, high productivity languages

Python is a general purpose language featuring a massive user community in the sciences and an outstanding scientific ecosystem

Julia is a recent arrival specifically orientated towards scientific computing that mixes high productivity and high performance

Programming in these languages is a lot of fun

The next few sections tell you a little bit more about Python, Julia and why we chose these languages

Open Source

We use Python and Julia because of their quality and power (as well as the fun factor, of course)

But the second best thing about Python and Julia is that both are free and open source

When you start out, the “free” component of this pair will probably be the most appealing

It means that you, your coauthors and your students can install them and their libraries on all of your computers without cost, or having to bother about licenses

Over time, however, you will most likely come to value the “open source” property as much, if not more

The first advantage of open source libraries is that you can read them and learn how they work

For example, let’s say you want to know exactly how pandas computes Newey-West covariance matrices

No problem: You can go ahead and read the code

While dipping into external code libraries takes a bit of coding maturity, it’s very useful for

  1. Helping you understand the details of a particular implementation
  2. Building your programming skills by showing you code written by first rate programmers

Even better, you can modify the library to suit your needs

In particular, if the functionality provided by a given library is not exactly what you want, you can always modify it

Another, more philosophical advantage of open source software is that it conforms to the scientific ideal of reproducibility

Research you produce using Julia or Python will be open, transparent and reproducible

Python or Julia

We offer these lectures in two flavors: Python and Julia

That leaves you with a choice to make

Below we offer some guidance by comparing the relative merits of these languages

Point One: Both are Great Choices

Perhaps this isn’t what you want to hear when trying to make a choice, but

  • Both are outstanding languages for modern scientific computing
  • The similarities between Python and Julia are more significant than the differences

Some Similarities

Both are modern, well designed, interactive, high productivity languages

Both are open source, including the core language and almost all important libraries

In many cases the syntax and design choices are similar (e.g., Julia borrows many nice features from Python)

Both can be interfaced with low level languages either directly or using existing tools

Both offer convenient interfaces to parallel programming

Julia has received more hype as a high performance language but there are very straightforward techniques to achieve similar speeds in Python (e.g., Numba)

Interoperability

Regardless of which language you choose to focus on, you can call Python from Julia and vice versa

In fact integration of these two languages is progressing rapidly

See, for example, the Jupyter project

The Differences

That’s said, there are some differences that might help shape your choice

Julia’s Advantages

  • Third party libraries are often written entirely in Julia, making them

    • Easy to install
    • Easy to dive into and read / change / edit
  • The focus of the language is bound to scientific applications, which means that

    • Syntax for common scientific operations can be more straightforward
    • Many standard scientific functions are part of the core language

Julia’s Disadvantages

  • It’s still early days for Julia, which means that

    • The language itself and the libraries have not fully stabilized and are likely to break backwards compatibility
    • The set of existing scientific tools is still only a fraction of what’s available in Python
  • Knowledge of Julia is still a niche skill

Python’s Advantages

  • Python is supported by a vast collection of standard and external software libraries

  • Knowledge of Python is a highly marketable skill

  • The fact that Python is a general purpose programming language means that knowledge of Python can be useful for all manner of problems

    • For example, these lectures are themselves compiled from templates using a variety of tools written in Python
  • Over the last decade, Python has become one of the core languages of scientific computing

  • Python is popular because it is simple to pick up and yet powerful enough for very sophisticated applications

Python’s Disadvantages

  • For scientific operations, the standard implementation of Python is typically slower than Julia, C or Fortran, so additional steps are required to obtain fast execution speeds

(The steps are mostly straightforward and detailed in the lectures)

  • Many scientific Python libraries include compiled code or code in other languages that needs to be compiled, making them less accessible

Python vs Julia Programmers: A Profile

Perhaps you can relate to one of these categories

Traits that Suggest Happy Python Programmer

You’d rather find someone else’s tool for solving a given problem than have to write your own from scratch

You do a lot of empirical work, combining a variety of data sources and data formats

Your programming needs are relatively diverse

Traits that Suggest Happy Julia Programmer

You are continually involved in computationally intensive work where runtime speed is a major bottleneck

You use relatively sophisticated algorithms

You write a lot of your own routines from scratch

Nothing pleases you more than the thought of diving into someone else’s code library and dissecting its internals

In the End it’s Personal

All of this is just indicative

Remember that

  • The best tool always depends on the task towards which the tool is addressed

  • Every programming language is the product of a multitude of design decisions

    • inevitably some of these are subjective

For example, a data model that fits the thought patterns of one individual can easily seem confusing or obscure to another

Because of this, perhaps the best way to choose between Julia and Python is to try both and see which one you like more

Still Can’t Decide?

Learn both — you won’t regret it

How about Other Languages?

But why didn’t you include language XYZ?

We get a lot of these emails...

MATLAB

MATLAB is a high productivity scripting language with fast vectorized operations and a large user base

While MATLAB has many useful routines and libraries, it’s starting to show its age

It can no longer match Python or Julia in terms of performance (Julia or Python + Numba) and design

MATLAB is also proprietary, which comes with its own set of disadvantages

Given what’s available now, it’s hard to find any good reasons to invest in MATLAB

Incidentally, if you decide to jump from MATLAB to Python, this cheat-sheet <http://cheatsheets.quantecon.org/> will be useful

R

R is a very useful open source statistical environment and programming language

Its primary strength is its vast collection of extension packages

Julia and Python are more general purpose than R and hence a better fit for this course

Moreover, if there are R libraries you find you want to use, you can now call them from within Python or Julia

C / C++ / Fortran?

Isn’t Fortran / C / C++ faster than Julia / Python? In which case it must be better, right?

Actually this is an outdated view

For a start, you can now achieve speeds close to those of compiled languages in Julia or Python (Python + Numba) through just in time compilation

But more importantly, remember that the correct objective function to minimize is

total time = development time + execution time

In assessing this trade off, it’s necessary to bear in mind that

  • Your time is a far more valuable resource than the computer’s time
  • Languages like Python or Julia are much faster to write and debug in
  • In any one program, the vast majority of CPU time will be spent iterating over just a few lines of your code

What this means is that there still might be a role for C / C++ / Fortran in your program but it will at most be

  • Speeding up just a few lines of code and then calling this compiled code from Python or Julia
  • Taking a legacy library written in C / C++ / Fortran and calling it from Python or Julia

Last Word

Writing your entire program in Fortran / C / C++ is best thought of as “premature optimization”

On this topic we quote the godfather:

We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. – Donald Knuth