Função
Bloco de código reutilizável com parâmetros e valor de retorno.
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["Função"]:::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;
🧒 Explique como se eu tivesse 5 anos
Uma função é como uma máquina em uma fábrica. Você coloca algo dentro, a máquina faz seu trabalho e algo sai. Você pode usar a mesma máquina repetidamente!
🤓 Expert Deep Dive
A pilha de chamadas gerencia registros de ativação. A otimização de chamada de cauda elimina o crescimento da pilha. Closures capturam variáveis do escopo. Funções puras não têm efeitos colaterais. Funções de ordem superior aceitam ou retornam funções.