Translinguisme/Programmation
Types et valeurs
Types
Langages | Types de variable supportés |
---|---|
C | char, double, enum, float, int, long, short, signed, struct, union, unsigned, void |
Java | boolean, char, byte, short, int, long, float, double, void
Boolean, Character, Byte, Short, Integer, Long, Float, Double, Void, Object, String, Enum, Date, File, Class, Method, ... |
LibO Basic | boolean, currency, date, double, float, integer, long, single, string |
Python | basestring, bool, complex, dict, exception, file, float, fonction, frozenset, int, list, long, module, none, NotImplementedType, object, set, slice, str unicode, tuple, type, xrange[1] |
SQL | bigint, bit varying, char, date, datetime, decimal, double precision, float, integer, numeric, real, smallint, time, varchar, year[2] |
VB | Byte, Boolean, Integer, Long, Single, Double, String[3] |
PHP | NULL, boolean, integer, float, string, array, object |
HTML | text, file, radio, checkbox, submit, hidden |
Valeurs
Langage | Référence/ pointeur nul | Test nul | Chaîne de caractère Caractère |
Entier | Flottant | Booléen | Allocation/libération mémoire |
---|---|---|---|---|---|---|---|
Ada |
|
|
"Un exemple accentué à moins de 1." |
512 0x200 -123 |
3.14 314.159E-2 |
False True |
allocation :
libération :
|
C | (void*)0 |
|
"Un exemple accentué à moins de 1\x80." |
512 0x200 -123 |
3.14 314.159E-2 |
0 1 |
allocation : ptr = malloc(size) libération : free(ptr)
|
Java | null |
isEmpty() |
"Un exemple accentué à moins de 1\u20AC." |
512 0x200 -123 |
3.14 3.14D 314.159E-2 |
false true |
allocation : ref = new class(arguments...) libération : ref = null; /* garbage collector */
|
JavaScript | null |
typeof X != 'undefined' |
"Un exemple accentué à moins de 1\u20AC." |
512 0x200 -123 |
3.14 314.159E-2 |
false true |
allocation : ref = new prototype_constructor_function(arguments...) libération : ref = null; /* garbage collector */
|
Pascal | nil |
|
'Un exemple accentué à moins de 1.' |
512 $200 -123 |
3.14 314.159E-2 |
False True |
allocation :
libération :
|
PHP | null |
is_null() isset() function_exists() |
False True |
||||
Python | null |
is None |
"Un exemple accentué à moins de 1\u20AC." |
512 0x200 -123 |
3.14 3.14 314.159E-2 |
False True |
|
VBA | null |
isEmpty() |
False True |
||||
SQL | NULL |
MySQL : isnull() , ifnull() MSSQL : isnull() |
False True |
Syntaxes de base
Structure du code
Langage | Bloc d'instructions | Condition simple | Condition à cas multiples | Boucles | Sous-programmes | Module | Programme principal | Capture d'exception |
---|---|---|---|---|---|---|---|---|
Windows PowerShell (DOS) | ( ... ) |
if ...condition... ...commande... else ...commande... |
for %%var in ( liste_ou_file_pattern ) do ... | call :nom ... ... :nom ... goto :eof |
séquence des commandes du fichier | |||
Shell Unix | if ... fi |
séquence des commandes du fichier | ||||||
Python | indentation | if ... : ... elif ... : ... else: |
while ... : for ... : |
Déclaration : implicite par la hiérarchie des répertoire utilisation : import module; from module import names; |
try: ... except ... : ... | |||
Ada | begin ... end; |
if ( ...) then ...elsif ( ...) then ...... else ...end if; |
case ( ...) when ... => ... when others => ... end case; |
while ( ...) loop ... end loop; |
function nom( parametre: type; ...) return type is ... begin ... return ...; end; procedure nom( parametre: (in /out /in out ) type; ...) is ... begin ... end; |
nom.ads (spécification) :package nom is ... end nom; nom.adb (corps) : package body nom is ... end nom; utilisation : with package,...; -- déclarer use package,...; -- utiliser l'espace de nom |
procedure nom is ... begin ... end; |
|
Pascal | begin ... end; |
if ... then ...else if ... then ...... else ... |
case ... of ... : ... else ... end; |
while ... do ...repeat ... until ...; for var := start to end do ...for var := start downto end do ... |
function nom( parametre: type; ...) : type; ... begin ... nom := ...; end; procedure nom( parametre: type; ...); ... begin ... end; |
unit nom; interface ... implementation ... end. |
program nom; ... end. |
|
C | { ... } |
if ( ...) ...else if ( ...) ...... else ... |
switch( ...) { case ...: ...... default: ...} |
while ( ...) ...do ... while ( ...); for ( ...; ...; ...) ... |
type_retour nom(type param,...){...} | utilisation :#include fichier |
int main(int argc, char** argv) { ... } |
|
C++ | { ... } |
if ( ...) ...else if ( ...) ...... else ... |
switch( ...) { case ...: ...... default: ...} |
while ( ...) ...do ... while ( ...); for ( ...; ...; ...) ... |
type_retour nom(type param,...){...} | utilisation :#include fichierusing namespace namespace; |
int main(int argc, char** argv) { ... } |
try { ... }
|
PHP | { ... } |
try { ... }
| ||||||
Java | { ... } |
if ( ...) ...else if ( ...) ...... else ... |
switch( ...) { case ...: ...... default: ...} |
while ( ...) ...do ... while ( ...); for ( ...; ...; ...) ... |
type_retour nom(type param,...){...} | Déclaration (1ère ligne) :package package; utilisation : import package.(classe ou *); |
public static void main(String[] args) { ... } |
try { ... }
|
JavaScript | { ... } |
if ( ...) ...else if ( ...) ...... else ... |
switch( ...) { case ...: ...... default: ...} |
while ( ...) ...do ... while ( ...); for ( ...; ...; ...) ... |
function nom(param,...){...} | séquence des commandes du fichier | try { ... }
| |
Visual Basic | rien | if ... then ... elseif ... then ... end if |
while ... wend do while ... loop for ... next |
call | on error resume next
| |||
LibO Basic | rien | if ... then ... elseif ... then ... end if |
while ... wend do while ... loop for ... next |
Commentaires et commandes de bases
Langage | Ligne de commentaire | Bloc de commentaire | Écha- ppement |
Afficher | Saisir | Déclaration | Définition | Égal | Différent | Et | Ou |
---|---|---|---|---|---|---|---|---|---|---|---|
Windows PowerShell (DOS) | rem | <# ... #> | ^ | echo | pause, SET /P variable=[promptString], choix multiple : choice, copie : copy con | variable : set, fichier : cp, copy, xcopy | = (on appelle ensuite les variables avec %variable%) | ==, EQU | !==!, NEQ | -and[4] | -or |
Shell Unix | # | : <<'END'...END | \ | echo | sleep, read | fichier : touch, cp, mv | = | = | != | && | || |
Python | # | '''...''', """...""" | \ | raw_input() | rien | def | == | != | and | or | |
Ada | -- | rien | \ | Put(), Put_Line() | Get(), GetLine() | variable:type | := | = | /= | and | or |
Pascal | rien | {...} ou (*...*) | Chr() | Write(), Writeln() | Read(), Readln() | var variable:type | := | = | <> | and | or |
C | rien | /*...*/ | \ | printf(), fprintf(), sprintf(), puts() | scanf() | voir le paragraphe types | =, adresse de pointeurs : == | == | != | && | || |
C++ | // | /*...*/ | \ | cout<< | cin>> | voir le paragraphe types | =, adresse de pointeurs : == | == | != | && | || |
PHP | //, ou # | /*...*/ | \ | echo, printf | $_GET, $_POST | Objet : new | =, variable : $ | == | ! | && | || |
Java | // | /*...*/ | \ | System.out.println() | BufferedReader.readline(), JTextArea,JTextField.getText(), JOptionPane.showInputDialog() | voir le paragraphe types, Objet : new | = | ==, objet : .equals() | != | && | || |
JavaScript | // | /*...*/ | \ | alert() | prompt() | var | = | == | != | && | || |
HTML | <!--...--> | <!--...--> | & | rien | <input> | rien | = | rien | rien | rien | rien |
SQL | --, Oracle : rem, @[5] |
/*...*/ | " | select | table : create table | variable : :, table : update, insert | = | not | and | or | |
Visual Basic | ', rem | rien | " | MsgBox | InputBox | variable : dim fonction : sub |
=, fichier : .CopyFile fichier, feuille : .new |
= | <> | and | or |
LibO Basic | ', rem | rien | " | MsgBox | InputBox | variable : dim fonction : sub |
= | = | <> | and[6] | or |
Syntaxe et traitement de chaînes
Langage | Retour à la ligne | Concaténation | Wildcard | Classer | Longueur | Majuscule | Minuscule | Rechercher dans une chaîne | Rechercher remplacer | Tronquer une chaîne | Rogner |
---|---|---|---|---|---|---|---|---|---|---|---|
Windows PowerShell (DOS) | \r\n | commandes traitant le résultat de la précédente : | | * | sort /r | |||||||
Shell Unix | \n | commandes : &&, ;, commandes traitant le résultat de la précédente : |, variables : >>, fichiers : cat | * | sort | |sed 's/.*/\U&/' ou |tr '[:lower:]' '[:upper:]' |
|tr '[:upper:]' '[:lower:]' | fichier : find, locate, programme : whereis | find -exec sed -i | fichier : head, tail | ||
Python | \n \r ou \r\n [7] | + | * | sort() | len() | .upper() | .lower() | .find() inverse : .rfind() |
.replace() | [] | .strip() |
Ada | \n \r ou \r\n [7] | chaines : & , commandes : ; |
* | Gnat.Heap_Sort_G[8] | variable'Size |
Characters. Handling. To_Upper() |
Characters. Handling. To_Lower() |
chaîne( début.. fin)
| |||
C | \n \r ou \r\n [7] | chaines : strcat, commandes : , | *, déclaration : ... | qsort() | sizeof | -=32 | +=32 | strpbrk(), strchr() | strncat() | ||
PHP | \n \r ou \r\n [7] | . | * | natcasesort() | strlen() tableau : sizeof(), count() |
strtoupper() | strtolower() | strpos() | str_replace() | substr() | trim() |
Java | \n \r ou \r\n [7] | + | * | Collections.sort() | .length() | .toUpperCase() | .toLowerCase() | .indexOf(), regex : .find() |
.replaceAll() | .substring() | trim() |
JavaScript | \n \r ou \r\n [7] | + | * | sort() | .length | .toUpperCase() | .toLowerCase() | .indexOf(), .lastIndexOf() | .replace() | .substr() | .trim() |
HTML | <br/> | rien | rien | rien | rien | rien | rien | rien | rien | rien | |
SQL | rien | ||, concat | like %... | group by | count, length | upper()[9] | lower()[10] | like CHARINDEX()[11] |
REPLACE() | substring()[12] | |
Visual Basic | _ | & | * | len() | UCase() | LCase() | instr() inverse : instrrev() |
replace() | left(), mid(), right() | ||
LibO Basic | _ | & | * | len() lignes tableau : UBound() colonnes tableau : LBound |
.SearchString | left(), mid(), right() |
Langage | Attribut de classe | Constructeur | Libération | Attendre | Lister le répertoire courant | Sortie | Date du jour | Ligne courante |
---|---|---|---|---|---|---|---|---|
Windows PowerShell (DOS) | erase, del | pause | dir | exit | date | |||
Shell Unix | rm, rmdir | sleep, wait | ls | exit | date | |||
Python | type() | self | del | time.sleep() | os.path.normcase(f) | boucle : break fonction : return |
import time... | import inspect... |
Ada | automatique | delay secondes; |
||||||
C | *, déclaration : ... | free() | sleep | |||||
PHP | gettype(), is_numeric()[13], is_int(), is_integer(), is_float(), is_real(), is_double(), is_long(), is_scalar() | $this-> | unset(), unserialize() | sleep() | __FILE__ | boucle : break fonction : return programme : exit, die |
date("d/m/Y") | __LINE__ |
Java | instanceof | this | StringBuffer.delete(0, sb.length()) FileInputStream.finalize() |
.sleep() | File[] files = new File(".").listFiles() | fonction : return programme : System.exit(0); |
||
JavaScript | getAttribute() | this | delete | window.setTimeout() | object.BuildPath(path, name) | return | ||
HTML | rien | rien | rien | rien | rien | |||
SQL | rien | delete | WAITFOR DELAY | fonction : RETURN | GETDATE() | |||
Visual Basic | .save, .saveas | Set MaVariable = Nothing Erase MonTableau[14] Kill MonFichier ou filesys.DeleteFile MonFichier |
Sleep[15] | dir() | fonction : Exit, End fichier : .close goto |
now() | ||
LibO Basic | .storeToURL() | kill | wait | dir() |
Conversions
Langage | Connaitre le type | En entier | En décimal | En caractère | En chaine | Déclarer un tableau | Lire un tableau | Trier un tableau |
---|---|---|---|---|---|---|---|---|
Python | type() | int() | ord() | str() Tableau : " ".join(MaListe) |
Tableau = range(1, 2) | Tableau[1] | .sort() | |
Ada | 'Value | 'Image | ||||||
C | StrToInt() | itoa() | ||||||
PHP | gettype() | intval(), ord() | floatval() | chr() | strval() Tableau : join() Objet : json_encode() |
$Tableau = array (1 => 'un', 2 => 'deux']); ou$Tableau[1] = 'un'; $Tableau[2] = 'deux'; |
$Tableau[1] | asort() Selon plusieurs colonnes : array_multisort() |
Java | .class .getClass() | Integer.parseInt() | Float.parseFloat() | .charAt(0) | .toString() | int [] Tableau = {1,2}; | Tableau[1], .arraycopy() |
.sort() |
JavaScript | typeof() | parseInt() | toString() | var Tableau = new Array(1, 2); | Tableau[1] | .sort() | ||
SQL | describe Matable Monchamp T-SQL : SQL_VARIANT_PROPERTY(MonChamp, 'BaseType') |
convert() | create table Tableau | select * from Tableau | order by | |||
Visual Basic | Typename() | CInt() | CDec | rien | CStr() | Dim Tableau(2) As Integer | Tableau(1) | rien |
Voir aussi Coder avec Unicode/Conversion.
Manipulation de fichiers
Langage | Ouvrir | Fermer | Fin de ficher | Insérer | Tout lire | Lire une ligne | Lire un caractère | Rechercher | Vider | Supprimer | Renommer |
---|---|---|---|---|---|---|---|---|---|---|---|
Python | .open() | .close() | .write() | .readline() | |||||||
C | fopen() | fclose() | fputs() | fgets() | fgetc() | fseek() | remove() | rename() | |||
PHP | fopen() | fclose() | feof() | fwrite(), fputs(), file_ put_ contents() | file(), file_ get_ contents() | fgets() | fgetc() | fseek() | fflush() | ||
Java | FileInputStream() | .close() | .readLine() | delete() | .renameTo() | ||||||
Visual Basic | open | .close | eof() | input | line input |
Manipulation de fichier Excel
Pour construire un fichier .xls, en plus de la liaison de données de MS-Excel, il est possible de le façonner depuis une base de données, un autre fichier, ou ex-nihilo avec du code :
Langage | Ouvrir | Fermer | Sauvegarder | Écrire | Paramètres des cellules |
---|---|---|---|---|---|
PHP PEAR[16] | $this->Spreadsheet_Excel_Writer_Workbook($filename); $workbook = new Spreadsheet_Excel_Writer(); |
$workbook->close(); | $workbook->sendFile(); | $worksheet->write(x,y,'Contenu'); | $format = $workbook->addFormat( array( 'Size' => 10, 'Align' => 'center', 'Color' => 'black', 'FgColor' => 'red')); |
PHPExcel | |||||
Visual Basic[17][18] | .Workbooks.Open(ActiveWorkbook.Path & "\" & "NomDuFichier") | .Close | .Save | Sheets(1).Cells(x,y).Value = "Contenu" ou Sheets("feuille 1").Range(x & y).Value = "Contenu" |
Range(x & y).Font.Size = 10 Range(x & y).HorizontalAlignment = xlCenter Range(x & y).Font.Color = vbBlack ou Range(x & y).Font.Colorindex = 2 Range(x & y).Interior.ColorIndex = 4 |
LibO Basic | .storeAsUrl(url,Array()) | .Close | .executeDispatch(document, ".uno:Save", "", 0, Array()) | getCellByPosition(y, x).value = "Contenu" ou getCellByName("A1").value = "Contenu" |
.CharColor .cellBackColor .CharHeight .CharWeight |
Commandes communes aux shells Windows et Unix
Comparatif des shells Windows et Unix
Commande | DOS | Unix |
---|---|---|
Liste des variables d'environnement | set | printenv |
Point de montage | subst | mount |
Regex
- Pour plus de détails voir : Catégorie:Expressions rationnelles.
Langage | Résultat du premier groupe de capture |
---|---|
Lua | %1 |
Python | \1 |
PHP | $1 |
Java | $1 |
Visual Basic | $1 |
Voir aussi : http://php.net/manual/fr/reference.pcre.pattern.posix.php
Faux-amis
Langage | isnull |
---|---|
MySQL | Renvoie un booléen |
SQL Server | Renvoie une valeur ou une autre selon si la condition est null |
Notes et références
- ↑ Python/Les types de base sur Wikiversité
- ↑ http://msdn.microsoft.com/fr-fr/library/ms191530%28v=sql.90%29.aspx#_ole_automation
- ↑ Visual Basic/Les types en VB sur Wikiversité
- ↑ http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/
- ↑ http://www.querytool.com/help/1135.htm
- ↑ http://wiki.services.openoffice.org/wiki/FR/Documentation/BASIC_Guide/Operators
- ↑ 7,0 7,1 7,2 7,3 7,4 et 7,5 Le retour à la ligne dépend du système d'exploitation et pas du langage de programmation dont le compilateur ou interpréteur peut être capable d'accepter les trois séquences possibles afin de réutiliser des codes sources provenant de systèmes différents :
\n
pour Unix, Linux\r
pour Mac OS\r\n
pour DOS, Windows
- ↑ http://rosettacode.org/wiki/Sort_an_integer_array#Ada
- ↑ http://msdn.microsoft.com/fr-fr/library/ms180055.aspx
- ↑ http://msdn.microsoft.com/fr-fr/library/ms174400.aspx
- ↑ https://msdn.microsoft.com/fr-fr/library/ms186323%28v=sql.120%29.aspx
- ↑ http://msdn.microsoft.com/fr-fr/library/ms187748.aspx
- ↑ Renvoie vrai si la variable est de type numérique, même si elle contient des lettres. Utiliser
preg_match ("/[^0-9]/", $nb);
dans ce cas - ↑ Définit chaque ligne à Nothing
- ↑ Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
- ↑ Programmation PHP/La librairie PEAR DB
- ↑ Fichiers en VB sur Wikiversité
- ↑ http://cisternino.free.fr/informatique/excel/vba/cours_vba_excel_fiche_07.pdf
- Programmation C/Opérateurs
- Hello world sur Wikipédia
- PowerShell sur Wikipédia (en anglais)
- Conditions sur Wikipédia (en anglais)
- http://tldp.org/LDP/abs/html/dosbatch.html
- « Apprendre le JavaScript depuis le PHP »