Skip to main content

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

BrickQuestion to ask yourselfExample
Value and typeWhat information is manipulated?number, text, boolean
VariesWhat name do we give to this value?prix, utilisateur
ConditionWhen to run this branch?if, else
LoopWhat action should be repeated?for, while
FunctionWhat behavior deserves a name and clear entries?calculerTotal()
CollectionHow to group several values?table, list, dictionary
ScopeWhere is this value accessible?block, function, module
ErrorWhat to do when the expected hypothesis is false?exception, error result
Input/outputHow 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.