Funkcja
Wielokrotnie używalny blok kodu z parametrami i wartością zwracaną.
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["Funkcja"]:::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;
🧒 Wyjaśnij jak 5-latkowi
Funkcja jest jak maszyna w fabryce. Wkładasz coś do środka (materiały), maszyna wykonuje pracę i coś wychodzi (gotowa zabawka). Możesz używać tej samej maszyny w kółko!
🤓 Expert Deep Dive
Stos wywołań (call stack) zarządza rekordami aktywacji. Optymalizacja ogonowa (TCO) eliminuje wzrost stosu. Domknięcia (closures) przechwytują zmienne zakresu. Czyste funkcje (pure functions) nie mają skutków ubocznych. Currying przekształca funkcje wieloargumentowe.