Discover Software Craftsmanship
What do a developer, baker, and cabinetmaker have in common? All three of them are craftspeople—and in certain cases, artists.
A developer is a craftsperson?
Yes, sort of. For several years now, the concept of software craftsmanship has been a hot topic. But what is it?
It’s a way of programming that prioritizes the method and quality of the result. The aim is not just to create a program that works but a well-constructed program. A well-constructed program is less prone to bugs, so you can see how this fits in with the course objective!
Software craftsmanship involves three key elements:
A state of mind: The desire to create clean and maintainable code and constantly improve its quality.
Tools: Using a set of tools to monitor and debug programs.
Methodologies: SOLID, Test Driven Development (TDD), behavior-driven development (BDD), design patterns, Python Enhancements Proposals (PEP), etc.
Software craftsmanship is not a destination, but a journey, which helps developers become more productive, efficient, happier, and more fulfilled in their work.
Next, you’ll learn about some of the characteristics of software craftsmanship.
Discover Design Patterns
When you encounter a technical problem in programming—and even in daily life—it’s very likely that other people will have experienced the same situation. So wouldn’t it be helpful to learn from other people’s mistakes? That’s where design patterns come in!
A design pattern is a general solution to a programming problem. This problem might apply to several areas but will use the same design pattern. For example, imagine you’re thinking about creating a class and realize that if the object resulting from this changes, several other objects will need to be informed of the change as they’re using it.
How can you structure your class so that the objects aren’t too dependent on each other?
You could develop an interesting solution, but hundreds of clever developers have already done that! It’s called the observer pattern. It allows your classes to “observe” what others do that could affect them. So, why not take advantage of it?
There are many design patterns, often taking the form of a diagram of classes with a definition and the cases where it can be applied. Your role is to translate the principles from a given design pattern into algorithms or take inspiration from how others have done this.
Using design patterns helps create a more flexible and maintainable program with as few bugs as possible. In addition, they help ensure your program will work as predicted, as they have been widely tested.
Discover Test-Driven Development
Test-driven development (TDD) is a popular tool used by software craftspeople. It ties in with the phrase seen at the start of the chapter “Identify the Three Different Types of Bugs” in part 1: “If it’s not tested, it doesn’t work.”
To put this into practice, apply what’s known as the Red-Green-Refactor method.
Red: Start writing a test to check a feature you won’t code until afterward. But how can you approve the test if the feature doesn’t exist? Good question! The test won’t be approved, so it will be red at this stage.
Green: The time has come to code the feature and test it. If everything works as it should, the test changes to green.
Refactor: This stage is for improving and perfecting. The aim is to end up with clean code, but it doesn’t have to be perfect.
Of course, coding tests can take time, especially because you have to remember to update them during the refactoring stage (and later on, too, if the code changes). However, going through the Red-Green-Refactor cycle shouldn’t take long. The idea is to code small features, step by step.
You can change all or part of your test with each cycle. The test might even become useless with time. It’s always worth applying TDD, as it will make your code clean and functional. It will also be more maintainable and have fewer bugs in production.
PEP 8 and PEP 20
It would be impossible to talk about software craftsmanship in Python without mentioning Python Enhancement Proposals (PEP). Python is an open-source language with a vibrant community that recommends writing clear, clean, and effective Python code. These recommendations, known as PEP 20 and PEP 8, set the rules for Python code style.
Why are these so important? Well, mainly because you’ll probably work with others on your projects. So if you want to make your code as readable as possible, it’s a good idea to apply PEP 8!
Let’s Recap!
Software craftsmanship is an approach focused on the coder’s skills and code quality.
A design pattern is a tested and approved solution for a general problem based on the experience of many developers.
TDD is an approach based on writing tests, implemented using the Red-Green-Refactor method.
Python Enhancement Proposals (PEP) are recommendations for writing good Python code.
We’re coming to the end of our adventure! 😭 Test your new skills with the last quiz, and then we’ll review the concepts we covered during the course.