The essentials of tricks and variables

If you want to be able to make your own shoes, you'll need to talk to a professional who is used to making shoes. He or she will teach you the tricks of the trade to make your job easier. Depending on the material to be used, the type of shoes to be made... you'll know in advance how to proceed in this type of situation, which will facilitate your work.

It's the same with coding. We're going to look at six typical situations that frequently arise in programs and see how they can be solved methodically. Then, when you're faced with a new program to create, you can ask yourself "What are the tricks of the trade I need to apply to write this program correctly and completely?". All you have to do is line up the lines of code corresponding to the various tricks of the trade, and you'll easily reach your goal.

Make sure you understand the principles of these different tricks, as they will be important in your future as a coder. It's a good investment in your future.


The aim of this chapter is to teach you how to perform six standard tricks. The six tricks we'll be covering are as follows:

  1. the counter;
  2. the sum;
  3. the signal;
  4. smallest and greatest;
  5. first and last;
  6. last becomes penultimate.

We're also going to look at a special structure: these are little memory boxes that allow you to remember certain things.