In this book, we encourage a hands-on approach on programming. This means that you should have a computer with tools for programming installed. Most importantly, these include an editor, where you write code commands, and an interpreter or a compiler to execute your programme. There are various editors, interpreters and compilers to choose from, and as they constantly evolve, we will not discuss them in this book explicitly. Instead, the online material will provide up-to-date suggestions for beginner-friendly tools.
All programming ought to start first by thinking about the problem and developing an approach to solve the problem - an algorithm. This is not always the case. Thinking is sometimes hard, and programming is easy.add refs or remove We seek to emphasise the importance of first thinking about the problem throughout the book. Our first exercise focuses on the Roman emperor Caligula, who was born in 12 AD and died in 41 AD. Based on these details, we have two goals for our first program:
As highlighted above, code is just text. Code is written so that it expresses to the computer what needs to be done. Specific commands that communicate to the computer what needs to be done are used for this purpose. Looking at the two goals we have, we can identify the following commands:
In both R and Python, command print() is used both to print text and numbers. Similarly, the command - is used to indicate that a subtraction is computed. Based on these two hints, we can already sketch out the code to solve this issue; see Code 2.2.