Gollum-Online

Programmiersprachen im Vergleich

Fünf Sprachen, mein Schatz, und alle sagen dasselbe, nur mit anderen Zungen. Wer eine kann, lernt die anderen schnell. Schnell, ja!

Sprachen anzeigen
ThemaJavaC#PythonJavaScriptPHP
Ausgabe
System.out.println("Hallo");
Console.WriteLine("Hallo");
print("Hallo")
console.log("Hallo");
echo "Hallo";
Kommentar
// Zeile
/* Block */
// Zeile
/* Block */
# Zeile
"""Docstring"""
// Zeile
/* Block */
// Zeile
# Zeile
/* Block */
Variablen
int n = 3;
String s = "Ring";
var x = 1.5;
int n = 3;
string s = "Ring";
var x = 1.5;
n = 3
s = "Ring"
x = 1.5
let n = 3;
const s = "Ring";
const x = 1.5;
$n = 3;
$s = "Ring";
$x = 1.5;
Typisierung statisch, stark statisch, stark dynamisch, stark dynamisch, schwach dynamisch, schwach (optional Typen)
Strings verbinden
"Hallo " + name
$"Hallo {name}"
f"Hallo {name}"
`Hallo ${name}`
"Hallo $name"
'Hallo ' . $name
Verzweigung
if (n > 0) {
  ...
} else if (n == 0) {
  ...
} else { ... }
if (n > 0) {
  ...
} else if (n == 0) {
  ...
} else { ... }
if n > 0:
    ...
elif n == 0:
    ...
else:
    ...
if (n > 0) {
  ...
} else if (n === 0) {
  ...
} else { ... }
if ($n > 0) {
  ...
} elseif ($n === 0) {
  ...
} else { ... }
Zählschleife
for (int i = 0; i < 3; i++) {
  ...
}
for (int i = 0; i < 3; i++) {
  ...
}
for i in range(3):
    ...
for (let i = 0; i < 3; i++) {
  ...
}
for ($i = 0; $i < 3; $i++) {
  ...
}
Liste / Array
List<String> l =
  new ArrayList<>();
l.add("Ring");
var l = new List<string>();
l.Add("Ring");
l = []
l.append("Ring")
const l = [];
l.push("Ring");
$l = [];
$l[] = "Ring";
Für jedes Element
for (String s : l) { }
foreach (var s in l) { }
for s in l:
    ...
for (const s of l) { }
foreach ($l as $s) { }
Dictionary / Map
Map<String,Integer> m =
  new HashMap<>();
m.put("Ring", 9999);
var m = new Dictionary
  <string,int>();
m["Ring"] = 9999;
m = {"Ring": 9999}
const m = { Ring: 9999 };
// oder new Map()
$m = ["Ring" => 9999];
Funktion
static int dbl(int x) {
  return x * 2;
}
static int Dbl(int x) {
  return x * 2;
}
def dbl(x):
    return x * 2
function dbl(x) {
  return x * 2;
}
const dbl2 = x => x * 2;
function dbl(int $x): int {
  return $x * 2;
}
Klasse
class Ring {
  private int wert;
  Ring(int w) {
    this.wert = w;
  }
}
new Ring(5);
class Ring {
  public int Wert { get; }
  public Ring(int w) {
    Wert = w;
  }
}
new Ring(5);
class Ring:
    def __init__(self, w):
        self.wert = w

Ring(5)
class Ring {
  constructor(w) {
    this.wert = w;
  }
}
new Ring(5);
class Ring {
  public function __construct(
    private int $wert
  ) {}
}
new Ring(5);
Fehler fangen
try { ... }
catch (Exception e) { ... }
try { ... }
catch (Exception e) { ... }
try:
    ...
except Exception as e:
    ...
try { ... }
catch (e) { ... }
try { ... }
catch (Exception $e) { ... }
Blöcke { } { } Einrückung! { } { }
Läuft auf JVM (kompiliert zu Bytecode) .NET (kompiliert zu IL) Interpreter Browser, Node.js Webserver (Interpreter)
Typisch für Unternehmenssoftware, Android Windows-Apps, Spiele (Unity), Web (ASP.NET) Data Science, KI, Skripte Webseiten, Web-Apps Websites, WordPress