#basics Clear
Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
Rust Move vs Borrow — the Core Rule
Rust's ownership model: passing a value transfers ownership (move); taking a `&value` lets you read without taking ownership; `&mut value` lets you modify without taking ownership. Only one mutable borrow OR many immutable borrows at a time.
Go Pointers — When and Why
Use pointers when you want to mutate the callee's value, share a large struct without copying, or distinguish "no value" via nil. Go has no pointer arithmetic — much safer than C.
Go Channels — Basics
Channels are typed pipes between goroutines. Unbuffered = synchronous handoff; buffered = up to N values queued. Close a channel to signal "no more values" — receivers see ok=false.
Go Struct Embedding (Composition over Inheritance)
Go has no inheritance. Embed a type to "promote" its fields and methods as if they were on the outer type. Same effect as inheritance for most purposes, but explicit.
Kotlin val vs var — Prefer Immutability
`val` is read-only (can't reassign the reference); `var` is mutable. Default to `val` everywhere — Kotlin's style guide recommends it, and a Compiler warning fires if a `var` is never reassigned.
Go Variadic Functions
`...T` in the last parameter slot accepts zero or more T values. Pass a slice by suffixing with `...` to spread it. Used everywhere from `fmt.Println` to custom builders.
Go Empty Struct Sentinel (struct{})
`struct{}` is a zero-size value — no memory cost. Use it as the value type in a Set (`map[T]struct{}`), as a channel signal (`chan struct{}`), or as a marker type.
SQL SELECT with WHERE / ORDER BY / LIMIT
The four-clause workhorse: pick columns, filter rows, sort them, return the top N. Standard across every database.
Go Type Switches
When you have an `interface{}` (or any) and need to dispatch on its underlying type, use `switch v := x.(type)`. Cleaner than a chain of type-assertions.
Kotlin Lambdas and Function Types
Kotlin functions are first-class values. A lambda is `{ args -> body }`; its type is `(InputTypes) -> ReturnType`. Single-argument lambdas can use the implicit `it` parameter.
Kotlin when Expressions — Powerful switch
Kotlin's `when` is an expression (returns a value), supports ranges, type checks, multiple values per branch, and arbitrary boolean conditions. Replaces nested if/else AND traditional switch.
Go defer / panic / recover
`defer` runs a statement when the enclosing function returns — LIFO order. `panic` aborts; `recover` (inside a deferred func) catches a panic and converts it back to a normal return. Use sparingly.
Kotlin Nullable Types — String? and the ? Operator
Kotlin distinguishes `String` (never null) from `String?` (may be null) in the type system. The compiler refuses to compile code that could deref a possibly-null value — the famous "no more NullPointerException" feature.
Go Multiple Return Values + Named Returns
Go functions can return multiple values — most idiomatically a `(result, error)` pair. Named returns let you document the meaning of each value AND enable naked returns in short functions.
Go Methods and Receivers
Methods are functions with a receiver argument. Use pointer receivers when you mutate, when the struct is large, OR for consistency (mixing pointer + value receivers on the same type is a common bug source).
Go iota — Auto-Incrementing Constants (Enums)
Go has no `enum` keyword but `iota` inside a const block gives you the same effect. Each line is the previous expression with iota auto-incremented.