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.
Setup Instructions | Download files required for the lesson | |
Duration: 00h 00m | 1. Introduction | How can code design make your code more FAIR? |
Duration: 00h 12m | 2. Why should you care? | Why should you know about code design? |
Duration: 00h 24m | 3. Code structure | How to structure a code in a scalable and reusable way? |
Duration: 00h 36m | 4. The Zen of Python |
What are PEPs? How to write clean? How can I do this efficiently with Pylint? |
Duration: 00h 48m | 5. Principles of Code design | How to write maintainable, readable, resusable and scalable code? |
Duration: 01h 00m | 6. Don’t touch your code anymore! | How can you modify your code configuration without touching it? |
Duration: 01h 12m | Finish |
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
.
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.