Summary and Schedule

This is a new lesson built with The Carpentries Workbench.

Welcome to this training course on Code design!

This lecture on Code Design introduces essential principles and best practices for writing clean, maintainable, and efficient code. It begins with the importance of good code design and goes through examples of non-optimally written code, trying to identify where we could make improvements. We will then learn how we can write clean code, adhering to naming conventions, commenting, and following PEP 8 guidelines. The lecture then explores some fundamental principles such as DRY, KISS or YAGNI that are useful to keep in mind when writing new code. Finally more we will also explore how to atually stop touching our code by creating configuration files and command line interfaces.

This course is aimed at researchers, including postgraduate research students, who write software (whether a few scripts or something more substantial) as part of their research and who want to follow best practices to make their code easier to develop, read and maintain.

This course is intended for researchers who use the Python programming language, but the basic concepts can be applied to other programming languages.

The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.

Setup


Installing Python


Discussion

In order to teach this course we will work on some short pieces of code. [Python][https://www.python.org/] has been chosen as the language to fulfill that task.

If you already have python 3 installed in your system then you are good to go. If not I suggest you use Anaconda to setup a virtual environment. To that end you should install [Miniconda3][miniconda3] on your system prior to attending the course.

If you are already familiar with Python and Virtual Environments you can simply create a fresh virtual environment to use for the course.

Please follow the instructions at Installing Miniconda for your Operating System.

You will have to create a virtual environment to undertake the course. If you have installed Miniconda as described above you open a terminal (Windows use the Git Bash Shell) and create a Virtual Environment called git-collaboation.

BASH

conda create --name git-collaboration python=3.11
conda activate git-collaboration

Linting


Discussion

We will learn what is code linting and we will use one tool called pylint. You will need to install this tool in order to use it. It is important to install the correct version of the software. For this lecture we will use pylint 3.2.2.

To install pylint with pip

BASH

pip3 install pylint==3.2.2

To install pylint with conda

BASH

conda install pylint=3.2.2