Evan Hahn's blog

https://evanhahn.com/blog/

My blog, mostly about programming.

フィード

記事のアイキャッチ画像
When Array uses less memory than Uint8Array (in V8)
Evan Hahn's blog
In short: in V8, Uint8Arrays have some overhead that makes them larger than equivalent Arrays. But after about 150 elements, they start to be much more compact.Sometimes, I have a JavaScript array of integers between 0 and 255. Like this:[1, 2, 3]I thought, in theory, using Uint8Array should use less memory. Like this:1new Uint8Array([1, 2, 3])After all, Uint8Arrays know every element is exactly one byte large. Arrays, with their flexibility, can’t guarantee that. What if the array has strings or objects inside? But modern JS engines are full of optimizations. Maybe they do something clever.Of course, Arrays and Uint8Arrays have different uses. You probably shouldn’t use an Array to store large amounts of binary data, and you can’t use a Uint8Array to store an array of objects. But let’s take a very narrow view:Assuming you’re storing a list of byte-sized integers, when, if ever, does using an Array use less memory than a Uint8Array?The testI wrote a simple script that spawns Deno proc
2日前
記事のアイキャッチ画像
Notes from May 2025
Evan Hahn's blog
A roundup of my notes from May 2025. I also did this last month, the month before, the month before that, and so on…Things I did this monthThe world is in a lot of trouble right now. Many of us techies are asking: how can I help? I published a list of tech jobs for good, which I hope helps someone find a gig doing a good thing.(I also wrote a simple script to help with the Markdown in that post, which is a lot less interesting.)I explored the cultural legacy of Zelda II: The Adventure of Link, along with a few other articles over on Zelda Dungeon. Also in video games, I listed things I wish I had known about Ring Fit Adventure, a fitness game I’ve been playing for years.I added my name to the “DWeb Principles”, which “define the values of a decentralized web based on enabling agency of all peoples”. I encourage you to give it a read and, if you agree with the values, add your name!I started writing an explainer about BOCU-1, an obscure character encoding…but I don’t think I’ll finish t
4日前
記事のアイキャッチ画像
Simple script to sort Markdown lists
Evan Hahn's blog
Sometimes (like in my recent blog post about tech jobs for good), I want to sort a Markdown list. But I can’t use normal tools like Vim’s :sort because the lists have formatting. For example, take this Markdown:- Badgers- **Crocodiles**- [Aardvarks](https://aardvark.example)It should get sorted like this:- [Aardvarks](https://aardvark.example)- Badgers- **Crocodiles**But all the tools I tried will sort this incorrectly because of the Markdown formatting…so I wrote a simple Deno script.Run this with something like deno run sort-markdown-list.ts < list_to_sort.md:import { toText } from "jsr:@std/streams/to-text";import { remark } from "npm:remark";import strip from "npm:strip-markdown";const cleanLine = (markdown: string): string => remark() .use(strip) .processSync(markdown) .toString() .trim() .toLowerCase();(await toText(Deno.stdin.readable)) .trim() .split("\n") .sort((a, b) => cleanLine(a).localeCompare(cleanLine(b))) .forEach((line) => console.log(line));This script has a few issue
4日前
記事のアイキャッチ画像
List of "tech for good" job boards
Evan Hahn's blog
The world is in a lot of trouble right now. Many of us are asking: how can I help?This is a short list of “tech for good” job boards I’ve found:80,000 Hours job boardAll Tech Is Human job board (requires signup)AltProtein.Jobsapply.coopClimate tech company listClimatebaseDigital Rights community (Mattermost and job board)fossjobs.netOpen Source JobHubOSdev job boardTech Jobs for GoodUnited Nations job boardWords of Mouthlocal civic tech groups’ job boards, like Chi Hack Night in Chicago or SF Civic Tech in San FranciscoNot all of these boards are great. In fact, a few of them list tech jobs that I think are bad! But I’ve found these lists useful, and hope they’re useful to you.If you know more job boards or have any feedback, please reach out.
7日前
記事のアイキャッチ画像
Things I wish I knew about Ring Fit Adventure
Evan Hahn's blog
I’ve played a lot of Ring Fit Adventure, the fitness game for Nintendo Switch. Here are some things I wish I knew when I got started.Jump over battles to skip themYou can jump over enemies to avoid fighting them!I first discovered this when watching a speedrun of the game. If you see some enemies in a level, you can use your (double) jump to avoid the battle completely. This is useful if you want to get to the end of a level faster, or if you don’t want to stop running.Sometimes this is a little tricky and I miss, and I believe some fights can’t be skipped. And skipping too many fights seems to defeat the purpose of the game!Jiggle the Ring-Con to delay an exerciseRing Fit typically waits for you to be in position for about three seconds before it starts an exercise, but sometimes it guesses wrong and starts before you’re ready!To avoid this, I jiggle the Ring-Con. That way, the game doesn’t think I’m standing still ready for the excercise.Remove the leg strap during static stretchingR
1ヶ月前
記事のアイキャッチ画像
Notes from April 2025
Evan Hahn's blog
A roundup of my notes from April. I’ve done this for the last few months:MarchFebruaryJanuaryThings I publishedI published a small UI tip about rounding percentages. In short, I don’t think you should show “100%” to the user unless it’s truly done, or “0%” unless it truly hasn’t started. Though this is a bit of a lie, I think it’s clearer to users.I posted clippings from Life in Code: A Personal History of Technology, a book of essays by Ellen Ullman. The book criticizes Silicon Valley (where I was born and raised!) and the modern tech scene. Yet Ullman seems to retain hope that these tools can be part of a better world. Perhaps I’m projecting, because that’s basically how I feel.I read the Economist’s style guide book and published my main takeaways. I think my writing is better after reading!Not something I published, but I was featured on DWeb’s social media and they chose a truly dreadful photo of me. Also, an old post of mine was featured on Remember The Milk’s blog.Things I wrote
1ヶ月前
記事のアイキャッチ画像
UI tip: maybe don't round percentages to 0% or 100%
Evan Hahn's blog
In short: maybe don’t round to 0% or 100% in your UI.I am not a UI expert. But I sometimes build user interfaces, and I sometimes want to render a percentage to the user. For example, something like “you’ve downloaded 45% of this file”.In my experience, it’s often better to round this number but avoid rounding to 0% or 100%.Rounding to 0% is bad because the user may think there’s been no progress. Even the smallest nonzero ratio, like 0.00001%, should render as 1%.Rounding to 100% is bad because the user may think things are done when they aren’t, and it’s better to show 99%. Ratios like 99.9% should still render as 99%, even if they technically round to 100%.For example, in your UI:Ratio (out of 1) Rendered 0 0% 0.00001 1% 0.01 1% 0.02 2% 0.99 99% 0.99999 99% 1 100% Here’s some Python code that demonstrates the algorithm I like to use:def render_ratio(ratio): if ratio <= 0: return "0%" if ratio >= 1: return "100%" if ratio <= 0.01: return "1%" if ratio >= 0.99: return "99%" return f"{
2ヶ月前
記事のアイキャッチ画像
Takeaways from The Economist's style guide book
Evan Hahn's blog
I’ve been trying to improve my writing so I read Writing with Style, the Economist’s style guide book.Here were my main takeaways:Use short sentences. They’re more memorable. They’re easier to read. They’re generally easier to write.Colons are for setup and delivery. They describe them as “dramatic”.One thought per paragraph. The paragraph is a “unit of thought”, according to this book and to H.W. Fowler. Sometimes, you have a one-sentence paragraph because the thought fits into a single sentence.Prefer simpler terms. Use “get” instead of “obtain”, “make” instead of “manufacture”, or “give up” instead of “relinquish”. Ask if you ever use the word when talking to friends. And don’t soften difficult topics: “a poor person has no more money, opportunity or dignity when described as ‘deprived’, ‘disadvantaged’ or ‘underprivileged’.”The right word can eliminate others. More specific words let you “dispense with adjectives and adverbs entirely. Consider the difference between ‘walk’ and ‘str
2ヶ月前
記事のアイキャッチ画像
Notes from "Life in Code: A Personal History of Technology"
Evan Hahn's blog
Life in Code: A Personal History of Technologyis a book of essays by Ellen Ullman.In the book, Ullman laments the bad parts of computers and the internet. Thesesystems eroded privacy, deepened income inequality, and enabled the rise ofmodern fascism. And they were built by a tiny subset of people—young men, mostlywhite and Asian, mostly wealthy—to the exclusion of almost everyone else.Despite all this, she maintains a hopeful fascination with technology. Perhapshumanity can use these tools as part of a better world.I share this sentiment, I think.Many of the stories are old by Silicon Valley standards, but they feelprescient. The book is filled with ideas that could be written today, if youmodernized a few incidental details.These are my notes and quotes from the book.“Outside of Time” (1994)Ullman on the idea that low-level development is more respected: “If you wantmoney and prestige, you need to write code that only machines or otherprogrammers understand.” Oh, and these prestigious
2ヶ月前
記事のアイキャッチ画像
Notes from March 2025
Evan Hahn's blog
Here’s a little roundup of things I’ve done in March. Also see my entries from February and January.Words I wrote in MarchI published a few blog posts this month:“Why ‘alias’ is my last resort for aliases” explains why I prefer defining scripts over shell aliases. I’ve been doing this for years and finally wrote about it.Response to this post, at least on Lobsters and Hacker News, was mixed. It was on the front page of Lobsters for awhile, but only briefly peeked into the bottom of the HN front page. Some people agreed with my idea and some did not.I also learned a few things about aliases from comments and emails, and have a few edits to my dotfiles I’d like to make.“Filling in the gaps of the internet” describes a philosophy of mine: if I ask a question, can’t easily find the answer, and then eventually find the answer, it’s my duty to publish something. I’ve done this many times on my blog. Some of those posts have gone nowhere, but others are very popular, and others have even been
2ヶ月前