TGViewer
Terminal Notes Terminal Notes @terminalnotes · 30 subscribers
Post #13 37
📌 #Concept: First-Class Functions

In languages like Go, Python, and Rust, functions are described as "First-Class." This is a fundamental concept in software engineering.

The term was coined by computer scientist Christopher Strachey in the mid-1960s. He drew a parallel to "citizenship."

In a society, a "First-Class Citizen" has full rights: they can own property, vote, and travel freely. A "Second-Class Citizen" has restrictions. In programming terms, if a function is "First-Class," it enjoys the same rights and privileges as primitive data types like an integer or a string.

In languages without first-class functions, a function is just a static block of code. It is distinct from data variables. You can call it, but you cannot store it in a variable or pass it directly to another function. Examples are: Java (Pre-version 8), Pascal, & Algol


🔆 Technical Definition

For a language to support first-class functions, it must allow functions to be:
1. Assigned to variables.
2. Passed as arguments to other functions.
3. Returned as values from other functions.

🔷 Example in Go

In Go, functions are values. In the example below, we treat the add function just like an integer variable; we assign it and pass it around.

package main

import "fmt"

func main() {
// 1. Assigning a function to a variable
// 'add' is now a variable holding a function
add := func(x, y int) int {
return x + y
}

// 2. Passing that variable to another function
process(add)
}

// This function accepts another function as a parameter
func process(operation func(int, int) int) {
result := operation(10, 5)
fmt.Println("Result:", result)
}


💠 Why It Matters

This capability is the foundation of Higher-Order Functions (a function that operates on other functions). It allows developers to write flexible code, such as middleware in web servers (common in Go) by abstracting logic into passable parameters.

🔘 @TerminalNotes <- #programming
More from @terminalnotes
  1. Aug 28, 2026🔗 Students should only use AI for things they already know how to do well The author argu…
  2. Jul 16, 2026آیا هوش مصنوعی داره قدرت تفکر رو از ما می‌گیره؟🏃‍♂ یه مقاله‌ی جالب توی وبلاگ ArtFish منتش…
  3. Jul 9, 2026🔘 @TerminalNotes
  4. Jul 5, 2026خلاصه ویدیو ها: چطور ابتکار عمل داشته باشیم و از صفر پروژه بنویسیم. برای جونیور دولوپر برن…
  5. Jul 5, 2026🔗 Tutorials Are KILLING Your Growth | Prime Reacts 🔘 @TerminalNotes <- #youtube
  6. Jul 5, 2026🔗 How To Get Out of Tutorial Hell (Step by Step Guide) 🔘 @TerminalNotes <- #youtube
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →