Protocol

Protocol Protocol is a piece of code which you can use and develop like the original author and you don’t modify it when you can build on top. When you modify what you could have built on top of, you break the chain between you and the original author. You are no longer using the same thing. You are no longer developing the same thing. You forked, and a fork is a separation. The moment you separate, you carry the full weight of everything beneath you alone. Every fix the original author makes, you must redo. Every improvement they ship, you must port. You chose to own what you did not need to own, and now you maintain what you did not need to maintain. ...

evgnomon

Struct

Struct A struct is a plain bundle of fields — state without behavior. Where a class pairs data with operations, a struct is just the data. The same minimal Color record across languages: Zig const std = @import("std"); const Color = struct { r: u8, g: u8, b: u8, }; pub fn main() !void { const c = Color{ .r = 255, .g = 128, .b = 0 }; try std.io.getStdOut().writer().print("#{x:0>2}{x:0>2}{x:0>2}\n", .{ c.r, c.g, c.b }); } Go package main import "fmt" type Color struct { R, G, B uint8 } func main() { c := Color{R: 255, G: 128, B: 0} fmt.Printf("#%02x%02x%02x\n", c.R, c.G, c.B) } Python from dataclasses import dataclass @dataclass(frozen=True) class Color: r: int g: int b: int c = Color(255, 128, 0) print(f"#{c.r:02x}{c.g:02x}{c.b:02x}") Rust struct Color { r: u8, g: u8, b: u8, } fn main() { let c = Color { r: 255, g: 128, b: 0 }; println!("#{:02x}{:02x}{:02x}", c.r, c.g, c.b); } C #include <stdio.h> typedef struct { unsigned char r; unsigned char g; unsigned char b; } Color; int main(void) { Color c = {.r = 255, .g = 128, .b = 0}; printf("#%02x%02x%02x\n", c.r, c.g, c.b); } C++ #include <cstdio> struct Color { unsigned char r; unsigned char g; unsigned char b; }; int main() { Color c{255, 128, 0}; std::printf("#%02x%02x%02x\n", c.r, c.g, c.b); } C# using System; public readonly record struct Color(byte R, byte G, byte B); var c = new Color(255, 128, 0); Console.WriteLine($"#{c.R:x2}{c.G:x2}{c.B:x2}"); TypeScript interface Color { r: number; g: number; b: number; } const c: Color = { r: 255, g: 128, b: 0 }; console.log(`#${c.r.toString(16).padStart(2, "0")}${c.g.toString(16).padStart(2, "0")}${c.b.toString(16).padStart(2, "0")}`); JavaScript const c = { r: 255, g: 128, b: 0 }; const hex = (n) => n.toString(16).padStart(2, "0"); console.log(`#${hex(c.r)}${hex(c.g)}${hex(c.b)}`); Kotlin data class Color(val r: Int, val g: Int, val b: Int) fun main() { val c = Color(255, 128, 0) println("#%02x%02x%02x".format(c.r, c.g, c.b)) } Scala final case class Color(r: Int, g: Int, b: Int) @main def run(): Unit = val c = Color(255, 128, 0) println(f"#${c.r}%02x${c.g}%02x${c.b}%02x") Java public record Color(int r, int g, int b) { public static void main(String[] args) { Color c = new Color(255, 128, 0); System.out.printf("#%02x%02x%02x%n", c.r(), c.g(), c.b()); } } Bash #!/usr/bin/env bash # Bash has no structs. We approximate one with an associative array # whose keys are the field names. declare -A c=([r]=255 [g]=128 [b]=0) printf "#%02x%02x%02x\n" "${c[r]}" "${c[g]}" "${c[b]}" Update Structs are often treated as immutable — produce a new value with one field changed rather than mutating in place: ...

evgnomon

Why Click When I Can Say?

Why Click When I Can Say? Why should I click when I can say? We use code and/or code use. With AI we make AI AI. A click is a guess. You see a pixel on a screen that someone else drew there, and you point at it because they asked you to. You did not name the thing, you did not describe the thing, you just hit the target that was placed in front of you. The click is the user obeying the interface, not the interface obeying the user. Every click is a vote for the designer of the box. ...

evgnomon