Programming in Python – Notebooks or scripts?

Programming in Python – Notebooks or scripts?

I started with Python in around 2007, by programming with scripts. Like so: 


# Python Program to find the area of a triangle

#input
a = 5
b = 6
c = 7

# calculate the semi-perimeter
s = (a + b + c) / 2

# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)

        

A year or so later I picked up programming with IPython notebooks (Jupyter came later). A notebook can represent the same program as

No alt text provided for this image

The latter is visually pleasing. But, for my programming, particularly, teaching tasks, I rarely use notebooks. Why?

I have been using computational notebooks for some time. Perhaps the first notebook interfaces were those of MathCAD and Wolfram Mathematica (around 1988). I started using MathCAD in 1995 and used quite a bit of Mathematica for my graduate research starting from 1996. Particularly I was very happy with the formatting options of Mathematica and how beautiful it could make mathematical expression look, blended with stylized text and nice graphics. But for longer programming tasks I always went for writing code (those days Java).

I am perhaps a bit reluctant to use notebooks (Juypter) in general programming. While there are definite advantages in using them, there are some downsides too.

Advantages:

1.      Did I say how good the ‘code’ look?

2.      They are great for ‘exploring a problem. (Quickly and interactively go through a dataset, for example).

3.      A great communication tool. For tutorials, presentations, etc. You can publish them easily on the web

4.      For using many cloud computing platforms and other online services, usually, little ‘programming’ has to be done by the user to use the high level APIs provided. In these cases, if the system supports notebooks, there is no harm in using them to get work done.

There are many others.

But there are distinct disadvantages too (for me)

1.      Notebooks are beginner-friendly on the surface. But once you start experimenting with them, there are pitfalls in the non-linear workflow (Jumping around from cell to cell). It is very easy for a beginner to make mistakes, and non-reproducible results if due care is not taken. They also often complicate the task of setting up a usable computing environment for a beginner, with data and code organized for easy access.

2.      If you are doing substantial code development, scripting is a very natural way to do it.

3.      I like good debugging tools. I use debuggers of Wing IDE (proprietory) and VS Code (Open source) quite a bit in my coding style. While notebooks have some debugging support (Jupyter Lab has a good debugger), I like the natural way of interactive debugging of IDEs.

4.      Version control and test-driven development are at the heart of any substantial programming project. While it is possible to do them with notebooks, they are not as elegant as with plain source code. 

Those are some.

I still do use notebooks occasionally. But, don’t like to use them when teaching python. Setting up a good python programming environment with a good distribution (WinPython, Anaconda, ) and an IDE (VS Code) on a computer is easy for an absolute beginner.  I believe having a basis in programming with scripts do a lot of good for beginner programmers.  After all, if you know that, understanding a notebook (and making some changes) is easy! What do you think? 

True jupyter has its own downside

Like
Reply

To view or add a comment, sign in

More articles by Assela Pathirana

Others also viewed

Explore content categories