Home - JawaharT/Best-Practices-On-Azure-Sphere GitHub Wiki
The Purpose of this Tutorial?
This tutorial is designed for beginners that are new to IoT and Embedded systems as well as C but have the basics of software development in high-level languages such as Python or JavaScript. Then this tutorial and the Azure Sphere platform are ideal for those getting started.
What and Why are Best Practices Important?
This tutorial will guide you through the Azure Sphere platform as well as the basics of C development. This tutorial will run through examples of code showcasing how not to implement software and then explain the best practice to perform them appropriately. There will also be exercises to complement the learning spread across the Learn Module.
What is C?
C is an intermediate-level compiler-based programming language that is used for desktop and embedded systems development. C unlike high-level languages provides the developer the ability to have finer control over memory and efficiency which is ideal for microcontrollers with very limited resources like Azure Sphere. One of the main reasons for this is because many high-level languages are interpreted where one statement at a time is translated into machine code. Compilers translate the whole program into machine code after the initial scan has been successful. This does not mean interpreted languages are bad for embedded systems, as the MITS Altair from 1974 used BASIC as its primary language which is interpreted. There are memory and performance issues to consider when using an interpreted language for embedded systems.
If you are coming from another programming language such as Python or JavaScript, you might also want a further understanding of the differences between C and Python:
Python:
Advantages | Disadvantages |
---|---|
Has native object-oriented programming features | First compiled into bytecode before interpreted by C |
Easy to implement complex data structures and easy to read programs | Due to its interpreted nature, errors show during runtime and will stop the program completely, not ideal in IoT |
Many built-in libraries | Slow execution time depending on the system it is used for |
C:
Advantages | Disadvantages |
---|---|
Easier to understand than Assembly | Issue of scalability |
It performs the same task all the time so there is no need for any hardware changes | For beginners, the concept of pointers can become difficult to understand |
Low cost of development and build | Compiler only shows errors after running the program, as a result checking code in large programs becomes complex |
In addition to the tables above, C converts human-readable programs into machine language (combination of zeros and ones) in an optimised manner due to its compiled nature. This increases performance in embedded systems. C is, therefore, the perfect middle-ground between low and modern high-level languages. Hence this is the main language of choice for the Azure Sphere Circuit Boards.