This Subject Update covers some of the basics in teaching coding. Links to further information are available in each section.
In programming there are often multiple ways to solve a problem. For example, if you want to make your mBot keep driving forward if there is not an obstacle right in front of it, but stop when there is one, you might write a piece of code like this:
However, this piece of code works too:
The two programs both solve the same problem, but approach it slightly differently. In this case, both solutions are fairly similar in logic and length. However, sometimes there is a ‘better’ solution. For example, when making the car drive in a square, you might repeat steps to drive and turn multiple times like this:
Or you can write your program like this:
Both solutions work, but the second solution would be considered ‘more elegant’.
Some coders like to talk about writing 'elegant code'. But what does that mean? When you think of elegance in the literary world, you may think of long, beautiful sentences and descriptive paragraphs. In coding, it's different. It's more important to be clear and concise, like a straightforward recipe. Elegant code should be clean, concise and easy to understand.
Find out more in the How to: Write elegant code Subject Update.
It is rare to write a working program the first time you try. Do not worry about failing. To fail is to make your First Attempt In Learning. Mistakes in your code show that you are trying.
Debugging is a systematic way for your students to iron out their mistakes. Instead of giving them the answers, you should encourage your students to work through potential problems step-by-step, starting from basic issues and working up to more complex issues.
Find out more in the How to: Debug code Subject Update.
Programs can include comments which are ignored by the computer but are meant for humans to read to help them understand the program. When you write code it is helpful to add comments to it to let other people know what it does or remind you what it does when you've not looked at in a while.
Find out more in the How to: Comment code Subject Update.
Code should be shared so we can learn from others and so we can work together to write better code. Code is written to solve a problem, and this is very rarely only a problem for one person. By sharing your code, you are helping others solve their problems, and, by letting them see the actual code, they can understand how it works and apply it to solve other similar problems.
By working together in this way, we can solve bigger programs rather than having everyone individually solve the same smaller problems repeatedly and making no progress. Computer software where the code is available for anyone to use and see is called open source. The largest open source community in the world can be found on github.
Computing | Ages 7-11
Code Smart is a computing and robotics education programme based on driverless car technologies. Code Smart takes students on a journey from complete beginners to code creators.
Computing | Ages 11-14
Code Smart is a computing and robotics education programme based on driverless car technologies. Students will develop their ability to code as well as their design thinking as they tackle smart city challenges.