Professional Python Software Development⚓
If you want to be professional about software development, you need to take a few considerations when working on your project.
The first consideration that might upgrade your project to a professional level, is to take into account some design and development principles.
The second consideration is to consider that your are working on a software, that users including you have to interact with in a specific way. Hence, you need to decide what type of software you intend to create.
Basic development principles⚓
Unless you are working on a quick proof of concept or throw-away project, you are developing something so it can be reused, either by yourself or other people. If other developers contribute to your project, they need to understand how the project works, how it is organized, the rules for contributing, etc.
To that end, there are general principles, that are good to keep in mind when developing software (in python, or even generally): readability, maintainability, modularity, etc. The list is not exhaustive at all.
Readability⚓
Your code must be easily readable, meaning we should be able to understand its intent and how it works. This is necessary for other contributers that may need to amend your code, or at least develop functionalities that integrate well with your code.
This is also necessary if you are developing an API, as users need to understand what each function or class they can call is doing.
It is linked to the next software development principle: maintainability.
Maintainability⚓
If your code is not a quick throw-away project, you should take steps to ensure it can last. This means making sure it can be maintained (either by yourself or other contributors), that means we should be able to modify it to fix bugs, optimize its execution (e.g making it more efficient in terms of memory and/or computational time) or extend its functionalities with new ones.
To that end, we should not have to modify code in all your project just to add a single functionality, or patch a broken functionality.
Another principle can help you make your code maintainable, and making your functionalities reusable throughout your code in the process: modularity.
Modularity⚓
Your code should be split into well defined independent components, whenever possible. This leads to a better maintainability as those components can be used or tested in isolation. A bug in a single component should not spread to your entire project, if it is modular.
Another advantage of a modular project is that those components if independent enough, could be developed in isolation and in parallel, which is useful in collaborative projects.
As mentioned in the beginning of this page, this list is not exhaustive. There are many design and development principles, and ways to group them.
Types of software⚓
There are numerous types of software that can be develop in python. Here is a non-exhaustive list of the most current types.
Scripts⚓
The first python file you probably wrote is a script, which is to be executed as-is, often with few dependencies, by the python interpreter. This is perfect for very small projects, making scientific experiments.
In this case, the project is a list of loosely-coupled files each an executable script. There are often no arguments/inputs to provide to the scripts, as they contain all data and configuration needed. It is nonetheless possible to share source code between them, so as not to rewrite the same functionalities again and again.
A script can be simply executed by the python interpreter:
1 |
|
Example of such script:
1 2 |
|
CLI⚓
Whenever those scripts share a common theme, and can be used in different context, it may be interesting to add arguments to them (or even entire subcommands), that can be entered by a user in the command line when executing them. If you create one python entry file handling those commands/arguments, you have basically created a Command Line Interface (CLI).
Examples of such CLI software include the python interpreter itself, along with
every shell command you can enter in the terminal (ex: cd
, mkdir
, etc).
Such a python CLI can only be called from a terminal (hence the name). It looks like this:
1 2 3 |
|
Program⚓
Whenever your software is interactive, be it from the command line or a Graphical User Interface (GUI), and can run uninterrupted for as long a user needs it, you are generally talking about a program. Also of course, whenever your software does not need to be run from the command line.
A program can be as complex as you need: a simple user interface, a GUI, a background service, a server, etc.
Note
All CLIs are programs, but not all programs are CLIs.
Examples of such programs are Firefox
or VS Code
.
API⚓
An API is a set of functionalities that is designed to be called from other software.
A python library, such as numpy
or matplotlib
are API.
So is an HTTP REST API, designed to be called over the internet, often by other API or websites.
In the case of a python library, it needs to be importable by other project source code that use or integrate it.
Notebooks⚓
A type of software specific to python is the notebook. It mixes executable code blocks with markdown documentation in a single file, and is particularly adapted to self-contained tutorials, or quick explorative development.
Except in the case of tutorials or courses, notebooks are rarely the only final product of a python project, but can accompany it, especially in the case of a python library.