|| How To Write Readable Code ||

Introduction

Here is a small collection of tutorials and lessons aimed at bridging the gap between beginner and intermediate coders.

I have spend a while helping people with their projects on Facebook groups, at work and at makerspaces, and I have spotted some common themes that hold less experienced coders back from writing really good code, and getting their projects working cleanly and quickly.

Content Overview:

These tutorials start with writing and using our own functions, the first step to go from following the examples in the Arduino IDE, or copying projects online, to writing and organising our own code.

We will quickly cover software timers and the millis() function, which we can use to replace delay() functions.

Then we will begin laying the groundwork for more complex program structures, using state machines and learning how to describe a task before writing any code.

The second half of these tutorials is designed to demystify some of the tools we have available to us to make life easier, starting with debugging and using the serial monitor. We will learn to use GitHub to organise the different programs we write, make it easy to share our code, use libraries and collaborate with others.

The last few lessons will focus on writing libraries, in order to learn what they are, how to use them and how to structure our own. We will also cover some aspects of Object Oriented Programming alongside this.

By the end of these lessons you should have several new techniques to approach writing code, new tools with which to save, share and manage your code, new approaches and tools to apply when debugging projects, and a template for writing your own libraries.

Our Approach for These Lessons

This is not a sketch, project or instructable to build or code something specific; this is a series of lessons to help people relatively early in their Arduino journey, who have picked up the basics, but may be struggling to write code in a structured way.

Most of the examples here are not full working sketches, complete, or sometimes even meant to represent actual code, they are mostly examples on how to structure code itself and how to think about approaching a problem when working with microcontrollers.

What will you need to know already?

To follow these tutorials, it would be best if you were familiar with the basics, able to flash an LED, control output pins, sample digital pins and analogue pins, understand the different basic variables, where and why they are used.

You probably would have read through some of the examples contained within the Arduino IDE, you may be successfully copying and pasting huge chunks of code from websites and mostly getting them to compile and run, you may be scratch writing you own programs, following examples and tutorials closely, but struggling to understand why things work, or write more complex code.

The tutorials are fairly self contained, so if you feel like you already understand a subject, you will not miss anything by skipping ahead to follow one of the tutorials which might teach you something new, however each one will assume that you have the knowledge contained in the former ones.


What will I get out of it?

It is my hope that by reading through these Tutorials, and applying the methods to some of your own code, you can boost your ability to lay out code in ways that are readable and efficient. This will help you understand the code you are using, learn to work through problems and debug your code, and communicate to others the problems you are facing more succinctly.

What follows will be a series of lessons that I wish I had been taught when I was starting out, I hope they are approachable for beginners to intermediate coders.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.