Common core of programming
A language has its syntax, but most programs rely on same gestures: representing information, making a decision, repeating a action and break down a problem.
The essential bricks
| Brick | Question to ask yourself | Example |
|---|---|---|
| Value and type | What information is manipulated? | number, text, boolean |
| Varies | What name do we give to this value? | prix, utilisateur |
| Condition | When to run this branch? | if, else |
| Loop | What action should be repeated? | for, while |
| Function | What behavior deserves a name and clear entries? | calculerTotal() |
| Collection | How to group several values? | table, list, dictionary |
| Scope | Where is this value accessible? | block, function, module |
| Error | What to do when the expected hypothesis is false? | exception, error result |
| Input/output | How does the program communicate? | keyboard, file, network |
The same reasoning, several syntaxes
title="JavaScript"
function estMajeur(age) {
return age >= 18;
}
title="Python"
def est_majeur(age):
return age >= 18
The punctuation changes, but the model remains the same: a function receives a value, evaluates a condition and returns a result.
Objects, classes and paradigms
Objects, classes or inheritance are not required in all languages. They belong to certain ways of organizing a program. Other approaches favor functions, data transformation or the description of the expected result.
Start by mastering the common building blocks. The paradigms then become design choices, not lists of words to memorize.
Check your understanding
Write pseudo-code for a program that receives a list of temperatures, ignores invalid values and returns the average. Identify the values, loop, condition, function and error case before choosing a language.