Fonksiyon

Parametreler ve dönüş değeri olan yeniden kullanılabilir kod bloğu.

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["Fonksiyon"]:::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;

      

🧒 5 yaşındaki gibi açıkla

Bir fonksiyon fabrikadaki bir makine gibidir. İçine bir şey (hammadde) koyarsınız, makine işini yapar ve dışarı bir şey (bitmiş oyuncak) çıkar. Aynı makineyi tekrar tekrar kullanabilirsiniz!

🤓 Expert Deep Dive

Çağrı yığını (call stack) aktivasyon kayıtlarını yönetir. Kuyruk çağrısı optimizasyonu (TCO) yığın büyümesini engeller. Kapanışlar (closures) kapsam değişkenlerini yakalar. Saf fonksiyonların yan etkileri yoktur. Köriyleme (Currying) çok argümanlı fonksiyonları dönüştürür.

🔗 İlgili terimler

Ön koşullar:

📚 Kaynaklar