Funktion: Der Baustein der Logik

Ein wiederverwendbarer Codeblock für eine bestimmte Aufgabe.

Functions are the primary tool for abstraction and code reuse in software engineering. They allow developers to group a sequence of instructions into a single unit with a name. When a function is called, the program's execution jumps to the function code and then returns to the original point. This promotes the 'Don't Repeat Yourself' (DRY) principle, making code more modular and maintainable. Modern programming paradigms treat functions as 'first-class citizens,' meaning they can be assigned to variables, passed as arguments, and returned from other functions.

        graph LR
  Center["Funktion: Der Baustein der Logik"]:::main
  Pre_variable["variable"]:::pre --> Center
  click Pre_variable "/terms/variable"
  Rel_recursion["recursion"]:::related -.-> Center
  click Rel_recursion "/terms/recursion"
  Rel_compiler["compiler"]:::related -.-> Center
  click Rel_compiler "/terms/compiler"
  Rel_computational_neuroscience["computational-neuroscience"]:::related -.-> Center
  click Rel_computational_neuroscience "/terms/computational-neuroscience"
  classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
  classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
  classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
  classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
  linkStyle default stroke:#4b5563,stroke-width:2px;

      

🧒 Erkläre es wie einem 5-Jährigen

Eine Funktion ist wie eine Maschine in einer Fabrik. Du steckst etwas hinein (Rohmaterial), die Maschine macht ihre Arbeit, und etwas kommt heraus (ein fertiges Spielzeug). Du kannst dieselbe Maschine immer wieder benutzen!

🤓 Expert Deep Dive

Der Aufrufstapel (Call Stack) verwaltet Aktivierungsdatensätze. Endrekursionsoptimierung (Tail Call Optimization) verhindert Stapelwachstum. Closures erfassen Variablen des umgebenden Gültigkeitsbereichs. Reine Funktionen (Pure Functions) haben keine Seiteneffekte.

🔗 Verwandte Begriffe

Voraussetzungen:

📚 Quellen