In a terminal far, far away, a script started running...
> No hype. Just notes worth keeping 💭
🔘 @TerminalNotes <- #memory
user@terminal:~$ bash ./magic.sh
> No hype. Just notes worth keeping 💭
🔘 @TerminalNotes <- #memory
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
👤 Martin Fowler
🔘 @TerminalNotes <- #quote
📌 #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
🔆 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
💠 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
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
This media is not supported in your browser
VIEW IN TELEGRAM
Beautiful things don't ask for attention.
🎥 The Secret Life of Walter Mitty 2013
🔘 @TerminalNotes <- #life #quote
❤1
The only way to learn a new programming language is by writing programs in it.
👤 Dennis Ritchie
🔘 @TerminalNotes <- #quote
📌 #concept: Populating
In software development, populating describes the process of taking an empty or partially initialized data structure and filling it with meaningful data. It is the bridge between "getting" data (fetching) and "using" data (rendering or processing).
Most applications follow a standard lifecycle for data handling:
1. Fetch: Retrieve raw data from a source (Database, API, JSON file).
2. Initialize: Create an empty container (List, Array, Map).
3. Populate: Iterate through the raw data and fill the container.
🔆 Analogy
Think of a form on a clipboard.
🔹 The Structure: The blank form with boxes for "Name" and "Age".
🔸 The Data: The person standing in front of you.
🔹 Populating: The act of asking them questions and writing the answers into the boxes.
🔷 Example in Go
Here we fetch raw IDs and use them to populate a list of User objects:
🔘 @TerminalNotes <- #programming
In software development, populating describes the process of taking an empty or partially initialized data structure and filling it with meaningful data. It is the bridge between "getting" data (fetching) and "using" data (rendering or processing).
Most applications follow a standard lifecycle for data handling:
1. Fetch: Retrieve raw data from a source (Database, API, JSON file).
2. Initialize: Create an empty container (List, Array, Map).
3. Populate: Iterate through the raw data and fill the container.
🔆 Analogy
Think of a form on a clipboard.
🔹 The Structure: The blank form with boxes for "Name" and "Age".
🔸 The Data: The person standing in front of you.
🔹 Populating: The act of asking them questions and writing the answers into the boxes.
🔷 Example in Go
Here we fetch raw IDs and use them to populate a list of User objects:
// 1. Initialize empty container
var activeUsers []User
// 2. Fetch raw data (simulated loop)
rawIDs := []int{1, 2, 3}
// 3. Populate
for _, id := range rawIDs {
newUser := User{ID: id, Name: "Guest"}
activeUsers = append(activeUsers, newUser)
}
🔘 @TerminalNotes <- #programming
تو این روزایی که وضعیت اینترنت جالب نیست، اپلیکیشنهای Todo که دنبال سینک کردنن و به اینترنت و VPN نیاز دارن (مثل Notion) رو مخ میرن. واسه همین یه Todo Manager جمعوجور با Go نوشتم که همه چی رو لوکال توی یه فایل JSON ذخیره میکنه و دیگه کاری به نت نداره:
📥 GitHub: togo
کی میدونه؛ ممکنه باز بهکار بیاد.
🔘 @TerminalNotes <- #project
📥 GitHub: togo
کی میدونه؛ ممکنه باز بهکار بیاد.
پ.ن: نمونش توی وب بود ولی به کل بازنویسیش کردن به gui. چرا خب؟ کامند لاین به این خوشگلی :)
نسخه cliش رو بر اساس فیچرها و نیازهای خودم نوشتم.
🔘 @TerminalNotes <- #project
👍2🔥1
💢 فیش ورژن 4 و تغییر Keybind های دیفالت
توی fish shell از ورژن 4 به بعد، اومدن bind های پیشفرض رو عوض کردن و ماسل مموری کاربرای قدیمی رو به چالش کشیدن. مثال تفاوت
🔹Version 3
🔸Version 4
توی ورژن 3 کلمه پاک میشه ورژن 4 توکن.
🛠 راه حل
اگه مثل من به ورژن 3 عادت دارید، برای برگشتن به رفتار قدیمی فایل
و کد زیر رو داخلش paste کنید:
پ.ن: فیش یه مکانیزم autoload داره که هر فایلی توی
قرار بگیره به عنوان یه فانکشن مستقل لود میشه.
🔗 Issue 10926
🔘 @TerminalNotes <- #linux #fish
توی fish shell از ورژن 4 به بعد، اومدن bind های پیشفرض رو عوض کردن و ماسل مموری کاربرای قدیمی رو به چالش کشیدن. مثال تفاوت
alt+backspace بین ورژن 3 و 4:🔹Version 3
curl https://wttr.in/Tehran # before
curl https://wttr.in/ # after
🔸Version 4
curl https://wttr.in/Tehran # before
curl # after
توی ورژن 3 کلمه پاک میشه ورژن 4 توکن.
🛠 راه حل
اگه مثل من به ورژن 3 عادت دارید، برای برگشتن به رفتار قدیمی فایل
fish_user_key_bindings.fish رو توی مسیر زیر بسازید:~/.config/fish/functions/
و کد زیر رو داخلش paste کنید:
function fish_user_key_bindings
bind alt-left prevd-or-backward-word
bind alt-right nextd-or-forward-word
bind alt-backspace backward-kill-word
bind alt-delete kill-word
bind ctrl-left backward-token
bind ctrl-right forward-token
bind ctrl-backspace backward-kill-token
bind ctrl-delete kill-token
bind ctrl-alt-h backward-kill-word
end
اسم فایل و فانکشن نه تنها باید با هم یکی باشن، بلکه باید دقیقا همین اسم باشن — چون fish_user_key_bindings یه هوک هاردکدشده fish هست که بعد از لود شدن bind های پیشفرض صدا زده میشه.
پ.ن: فیش یه مکانیزم autoload داره که هر فایلی توی
~/.config/fish/functions/قرار بگیره به عنوان یه فانکشن مستقل لود میشه.
🔗 Issue 10926
🔘 @TerminalNotes <- #linux #fish