GoByte Blog
Engineering lessons and marketing playbooks from the team behind GoByte.
Latest, page 6
RSS-
Generators: a function you can pause
GoByte Skills #7: Calling a generator function runs none of its body. Each next() resumes a frozen frame up to the next yield, so a billion values cost one frame of memory. Plus the one pass trap that fails silently.
-
Streams: nothing runs until the end
GoByte Skills #6: filter and map do not filter or map anything. They write down a recipe, and no element moves until a terminal call drives the pipeline, pushing elements through one at a time. Bonus: why count() can skip your peek.
-
Sealed types: the switch that cannot forget
GoByte Skills #5: Seal the hierarchy, drop the default, and adding a type turns every switch that missed it into a compile error with a line number.
-
Virtual threads: blocking is cheap again
GoByte Skills #4: 10,000 tasks that each sleep 1 s finish in about 1.1 s on a 14 core laptop, in plain blocking Java. Virtual threads park and free the carrier. The catch on Java 21: synchronized pins it.
-
Context: cancel the parent, the children hear it
GoByte Skills #3: One cancel() at the root closes Done on every context below it, and closing a channel wakes every waiter at once. Context is a tree, not a kill switch. Also: why a dropped stop() leaks.
-
errors.Is: wrap it, keep the cause
GoByte Skills #2: %v prints the exact same message and quietly drops the chain. %w keeps it, and errors.Is walks it link by link, so the cause survives every layer of context.
-
Go channels: the queue that says no
GoByte Skills #1: A buffered channel is a bounded queue. When it is full, the send parks until there is room, so the slow consumer sets the pace. Backpressure in one argument to make(), plus the exact order a real run prints.
-
Vim from zero: a global command repeats one change
:g runs a command on every line that matches. :g/^item /normal cwadd changes each order line that starts with item and a space. A note line stays.
-
Vim from zero: a register holds what you yanked
A yank copies text into a register. "ayi" on item latte = "oat" copies oat. "ap puts that note at the cursor. The register is the clipboard you can name.
-
Shell from zero: read the exit code
A command returns a number when it finishes. 0 means it worked. An empty drink name fails test -n. The program prints 1. Check the code before you trust the result.
-
Shell from zero: local keeps the name inside
local makes a variable private to the function. The function prints muffin. The script then prints latte. The caller's drink is unchanged.
-
Motion from zero: the second step starts where the first ended
Two steps share one object. The second step's fromX is the first step's x. The program prints 0 then 24, then 24 then 48.