HNHacker News
TopNewBestAskShowJobs

asa400

1,194 karma · joined April 10, 2013

submissionscomments
asa400··on A million ways to die from a data race in Go
Sorry, this is going to be a slightly longer reply since this is a really interesting question to ask!

Elixir (and anything that runs on the BEAM) takes an entirely different perspective on concurrency than almost everything else out there. It still has concurrency gotchas, but at worst they result in logic bugs, not violations of the memory model.

Stuff like:

  - forgetting to update a state return value in a genserver
  - reusing an old conn value and/or not using the latest conn value in Plug/Phoenix
  - in ETS, making the assumption nothing else writes to your key after doing a read (I wrote a library to do this safely with compare-and-swap: https://github.com/ckampfe/cas)
  - same as the ETS example, but in a process: but doing a write after doing a read and assuming nothing else has altered the process state in the interim
  - leaking processes (and things like sockets/ports), either by not supervising them, monitoring them, or forgetting to shut them down, etc. This can lead to things like OOMs, etc.
  - deadlocking processes by getting them into a state where they each expect a reply from the other process (OTP timeouts fix this, try to always use OTP)
  - logical race conditions in a genserver init callback, where the process performs some action in the init that cannot complete until the init has returned, but the init has not returned yet, so you end up with a race or an invalid state
  - your classic resource exhaustion issues, where you have a ton of processes attempting to use some resource and that resource not being designed to be accessed by 1,000,000 things concurrently
  - OOMing the VM by overfilling the mailbox of a process that can't process messages fast enough
Elixir doesn't really have locks in the same sense as a C-like language, so you don't really have lock lifetime issues, and Elixir datastructures cannot be modified at all (you can only return new, updated instances of them) so you can't modify them concurrently. Elixir has closures that can capture values from their environment, but since all values in Elixir are immutable, the closure can't modify values that it closes over.

Elixir really is designed for this stuff down to its core, and (in my opinion) it's evident how much better Elixir's design is for this problem space than Go's is if you spend an hour with each. The tradeoff Elixir makes is that Elixir isn't really what I'd call a general purpose language. It's not amazing for CLIs, not amazing for number crunching code, not amazing for throughput-bound problems. But it is a tremendous fit for the stuff most of us are doing: web services, job pipelines, etc. Basically anything where the primary interface is a network boundary.

Edited for formatting.

asa400··on Cloudflare outage on November 18, 2025 post mortem
Thank you for saying it. I’m getting exasperated at how many people in the comments are making some variant of the “lazy programmer wrote code that took a shortcut” argument.

Complex system failures are not monocausal! Complex systems are in a continuous state of partial failure!

asa400··on Cloudflare outage on November 18, 2025 post mortem
Continuing only makes sense for cases you know you can handle.

_In theory_ they could have used the old config, but maybe there are reasons that’s not possible in Cloudflare’s setup. Whether or not that’s an invariant violation or just an error that can be handled and recovered from is a matter of opinion in system design.

And crashing on an invariant violation is exactly the right thing to do rather than proceed in an undefined state.

asa400··on Cloudflare outage on November 18, 2025 post mortem
> It seems like it was caught too deep in the system.

Agreed, that's also my takeaway.

I don't see the problem being "lazy programmers shouldn't have called .unwrap()". That's reductive. This is a complex system and complex system failures aren't monocausal.

The function in question could have returned a smarter error rather than panicking, but what then? An invariant was violated, and maybe this system, at this layer, isn't equipped to take any reasonable action in response to that invariant violation and dying _is_ the correct thing to do.

But maybe it could take smarter action. Maybe it could be restarted into a known good state. Maybe this service could be supervised by another system that would have propagated its failure back to the source of the problem, alerting operators that a file was being generated in such a way that violated consumer invariants. Basically, I'm describing a more Erlang model of failure.

Regardless, a system like this should be able to tolerate (or at least correctly propagate) a panic in response to an invariant violation.

asa400··on Go's Sweet 16
> The nice thing about Go is that you can learn "all of it" in a reasonable amount of time

This always feels like one of those “taste” things that some programmers tend to like on a personal level but has almost no evidence that it leads to more real-world success vs any other language.

Like, people get real work done every day at scale with C# and C++. And Java, and Ruby, and Rust, and JavaScript. And every other language that programmers castigate as being huge and bloated.

I’m not saying it’s wrong to have a preference for smaller languages, I just haven’t seen anything in my career to indicate that smaller languages outperform when it comes to faster delivery or less bugs.

As an aside, I’d even go so far as to say that the main problem with C++ is not that it has so many features in number, but that its features interact with each other in unpredictable ways. Said another way, it’s not the number of nodes in the graph, but the number of edges and the manner of those edges.

asa400··on .NET 10
> ...languages that compile down to an ELF are pretty much a requirement once your deployments are over the 10k containers mark.

Why?

asa400··on Collaboration sucks
People think management sucks at hiring good talent (which is sometimes true, but I have worked with some truly incredible people), but one of the most consistent and costly mistakes I’ve observed over my career has been management's poor ability to identify and fire nuisance employees.

I don’t mean people who “aren't rockstars” or people for whom some things take too long, or people who get things wrong occasionally (we all do).

I mean people who, like you describe, systemically undermine the rest of the team’s work.

I’ve been on teams where a single person managed to derail an entire team’s delivery for the better part of a year, despite the rest of the team screaming at management that this person was taking huge shortcuts, trying to undermine other people’s designs in bad faith, bypassing agreed-upon practices and rules and then lying about it, pushing stuff to production without understanding it, etc.

Management continued to deflect and defer until the team lead and another senior engineer ragequit over management’s inaction and we missed multiple deadlines at which point they started to realize we weren’t just making this up for fun.

asa400··on Zig and the design choices within
Same! I feel like I'm on crazy pills. Multiple folks in this thread are saying stuff like, "yeah, Rust, cool, but it has zero use". How are Linux, Microsoft, AWS, Cloudflare, Firefox, Python's `cryptography`, etc., not real use?

Rust is targeted at strategically important systems (proxies, databases, OSs, VMs, hypervisors, high-throughput servers, cryptography, browsers) and by any measure is making significant inroads into those kinds of systems in real industrial applications, and I'm to believe that Rust adoption is languishing? Am I going insane?

asa400··on How I fell in love with Erlang
Thank you for this post and I'll add a note for people who are seeing this and are maybe discouraged about learning Erlang/OTP/Elixir.

I generally agree with you that learning Erlang stuff can be daunting.

I will say that many things worth doing are not easy! Erlang and the whole OTP way of thinking is tough to learn in part because it is genuinely different enough from everything else that is out there that one's odds of being familiar with its conceptual underpinnings are low.

If you have trouble learning Erlang (and OTP specifically) it's not because you're dumb, it's because Erlang is different.

Learning Erlang is not like learning any other dynamic language you've learned. Learning Erlang is closer to learning a bespoke operating system designed to build reliable low-latency long-running systems. It's a larger conceptual lift than going from one dynamic OOP language to another dynamic OOP language.

asa400··on Zig and the design choices within
> ... and the same could be said about Rust, only with Rust we can already see that it suffers from relatively low adoption at a relatively advanced age.

What are we measuring? Lines of code? Number of programmers employed? Number of new applications started?

Rust is in: Linux, Windows, Azure, all over AWS, Amazon's Prime video, Cloudflare's proxy, Firefox, Python's `cryptography` package, Zed editor. This is just the sample I know of.

Is this low adoption?

asa400··on Ruby already solved my problem
> The Elixir equivalent, likely a series of pipes, would be just as easy to follow but substantially more to read, more symbols to parse etc.

Huh?

  [major, minor, patch] =
    version_string
    |> String.split(".")
    |> Enum.map(&String.to_integer/1)
I don't know that I'd call this "substantially more" of anything.
asa400··on Ruby already solved my problem
Same! I had a job at a shop with a monolithic Rails app where I had so much trouble understanding the codebase I almost quit the industry entirely.

Maybe I am just stupid when it comes to reading Ruby/Rails or maybe that codebase was uniquely awful, but it was ~impossible to figure out where things were defined or how data moved through the system. A huge ball of mutable state that was defined at runtime.

When people say "I love writing Ruby" what I hear is "I love writing greenfield Ruby". Everybody loves writing greenfield code! The difference between greenfield and brownfield Ruby is stark, in my experience.

And to be clear I do not hate Ruby. It got me into the industry, it taught me a lot, it just optimizes for a set of values that I don't happen to share anymore, which is fine.

asa400··on Why we migrated from Python to Node.js
There are quite a few Elixir shops that are willing to hire people who don't have a ton of experience with Elixir but have experience building and understanding systems generally.

So my advice is, try to bolster your story that you can design and build systems (regardless of language), learn what is needed to get the job done, and _communicate_ your knowledge of those systems to people. Good teams will recognize this regardless of prior specific tech.

Source: I've been on hiring panels at multiple companies that used Elixir extensively and the factors that led to us making offers to candidates were rarely their preexisting Elixir experience.

asa400··on AI's Dial-Up Era
We ignore the fallacies of distributed computing at our peril: https://en.wikipedia.org/wiki/Fallacies_of_distributed_compu...
asa400··on Why we migrated from Python to Node.js
Maybe for you! That's your call. I'm also interested in my career.

I've had 3 Elixir jobs and 2 Rust jobs in the last 10 years. All were on real products, not vaporware. I learned a ton, worked with great people, and made real friends doing it.

Luck? Skill? Who knows. It's not impossible to work with the technology of your choice on problems you find interesting if you're a little intentional.

Nothing ever gets better if everybody just does what's already popular.

asa400··on Lisp: Notes on its Past and Future (1980)
You tell your editor to evaluate any arbitrary part of the source file you currently have open, and it does so in the context of your running application without stopping it.

Then you see the result in another pane of your editor.

It's pretty revelatory. You're molding your program while it's running.

asa400··on Why we migrated from Python to Node.js
Folks, if you have problems doing async work, and most of your intense logic/algorithms is a network hop away (LLMs, etc.), do yourself a favor and write a spike in Elixir. Just give it a shot.

The whole environment is built for async from the ground up. Thousands and thousands of hours put into creating a runtime and language specifically to make async programming feasible. The runtime handles async IO for you with preemptive scheduling. Ability to look at any runtime state on a production instance. Lovely community. More libraries than you might expect. Excellent language in Elixir.

Give it a shot.

asa400··on Lisp: Notes on its Past and Future (1980)
> I do think it is perhaps unfortunate that Clojure is tied so heavily to the JVM, because I actually don't think it gains much from that ecosystem... but it's a product of the time it was first written.

When I was doing more Clojure, I loved that it was on the JVM because it meant I got to use every Java library under the sun. There are tons of battle tested Java libraries that didn't have to be rewritten in Clojure, and getting to use them for approximately zero financial and runtime cost was a HUGE benefit of Clojure compared to other niche FP languages.

asa400··on Lisp: Notes on its Past and Future (1980)
As someone who has gone deep into both functional programming (with Elixir, Clojure, and Scala) and also Rust, they solve the same problem in different ways with different tradeoffs.

The problem is that shared mutable state is incredibly hard to get correct, especially when concurrency enters the picture.

Elixir and Clojure sidestep the problem by making copying data so cheap that instead of sharing references to mutable data, you make all data immutable and copy it whenever you want to change it in some way. (Which is a classic technique: don’t like the problem? Solve a different problem that sidesteps the original problem in a creative way)

So you have a lot of functions of roughly the shape `f -> f` (return a new thing) instead of `f -> ()` (mutate a thing in place).

This possible at all by the clever use of some novel data immutable structures like HAMTs that are able to approximate the performance of traditional mutable data structures like hashmaps or arrays while presenting an immutable API.

As it turns out, this is a much easier programming model for most of us to get correct in practice (especially in the presence of concurrency) than sharing mutable state in an imperative programming language like C or Java or Python.

The tradeoff is that the immutable functional data structures actually do have a some performance overhead. In most domains it's not large enough to matter, but in some domains it is, and in those domains you really do need mutable state to eek out that last bit of performance.

Which is where Rust comes in.

In Rust's model, data can either mutable or shared, but not both at the same time. The Rust compiler computes the lifetimes of data throughout your program to ensure that this invariant is upheld, so mutable data is not shared, and shared data is not mutated.

The downside of this is that you have to internalize these rules and program to them. They can be tough to learn and tough to program with even after you have learned them, though it does get much easier with experience, I will say.

The upside of Rust's model is that you can have your cake and eat it too: you can keep the high performance ceiling of a true mutable data model while maintaining memory and resource safety.

In short, you can think of Clojure/Elixir as sidestepping the shared mutability problem at the cost of some runtime performance (though again in practice it is smaller than you would think), and Rust as tackling the shared mutability problem head on by transferring the cost of solving the problem to a more complicated compiler and a harder-to-learn programming model.

These are just my opinions having used both Rust and the immutable data functional programming stuff in anger. I'm not trying to present one as being better than the other, the key point is that they're both better than what came before.

asa400··on SQLite concurrency and why you should care about it
It’s a reasonable question!

In WAL mode, writers and readers don’t interfere with each other, so you can still do pure read queries in parallel.

Only one writer is allowed at a time no matter what, so writers queue up and you have to take the write lock at some point anyway.

In general, it’s hard to say without benchmarking your own application. This will get rid of SQLITE_BUSY errors firing immediately in the situation of read/write/upgrade-read-to-write scenario I described, however. You’d be retrying the transactions that fail from SQLITE_BUSY anyway, so that retrying is what you’d need to benchmark against.

It’s a subtle problem, but I’d rather queue up writes than have to write the code that retries failed transactions that shouldn’t really be failing.

asa400··on SQLite concurrency and why you should care about it
Ah, you're correct. I read too fast and missed that it was in-memory databases specifically!
asa400··on SQLite concurrency and why you should care about it
Are you running vacuums at all? auto_vacuum enabled at all?

https://sqlite.org/lang_vacuum.html

asa400··on SQLite concurrency and why you should care about it
SQLite is a truly remarkable piece of software that is a victim both of its own success and its unwavering commitment to backward compatibility. It has its quirks. There are definitely things we can learn from it.
asa400··on SQLite concurrency and why you should care about it
In SQLite, transactions by default start in “deferred” mode. This means they do not take a write lock until they attempt to perform a write.

You get SQLITE_BUSY when transaction #1 starts in read mode, transaction #2 starts in write mode, and then transaction #1 attempts to upgrade from read to write mode while transaction #2 still holds the write lock.

The fix is to set a busy_timeout and to begin any transaction that does a write (any write, even if it is not the first operation in the transaction) in “immediate” mode rather than “deferred” mode.

https://zeroclarkthirty.com/2024-10-19-sqlite-database-is-lo...

asa400··on Americans can't afford their cars any more and Wall Street is worried
Where in the text of their comment did they say that?

The sentence you quoted doesn't have anything to do with the point you claimed they're making.

And the GP is right: banks have to lend because the system is set up to use credit for investment, personal consumption, and to balance shocks. Doesn't take anyone being altruistic.

asa400··on Americans can't afford their cars any more and Wall Street is worried
Agreed. If you can find one.

I bought a new vehicle in 2023 after years of not owning a car. I was trying to buy used, but the delta between new and 1-3 year old used was so small it made no sense to go used. I was giving up a warranty for often times $500-$1500, total.

This is still true, and especially true for brands whose used vehicles command a price premium, like Toyota. Used values are still high relative to historical norms because a lot of the market that normally buys new vehicles is priced out of buying new, and some of that demand has been absorbed by the used market (some of it has dropped out of the market and/or deferred a purchase until later).

The idea of buying a relatively low miles 3-year old Toyota for materially less than a new one doesn't really exist, currently. Now, if you want to go for a 3 year old car with 150,000+ miles, sure, you can save some money, but that's a ton of miles per year. You're counting on the previous owner(s) being _really_ on top of their basic maintenance.

asa400··on Gleam OTP – Fault Tolerant Multicore Programs with Actors
OTP typically handles this with timeouts and then restarts when timeouts occur. Not to say it can't happen, but there are strategies.
asa400··on Elixir 1.19
Upvoting you because we should have clear answers for these concerns. To those in the community downvoting: we should take these kinds of posts as opportunities to improve.

Elixir and Erlang are dynamic compiled languages.

The actor model being built in to the runtime offers many benefits, all of which I cannot enumerate here, but prominent among them are the ability for the VM to preemptively schedule actors, and the fact that actors are independent in memory and cannot mess with the internal state of other actors.

The jump from Elixir to Erlang or vice versa is small.

The hardest (and most rewarding) part is learning OTP and the whole BEAM runtime system, which you can do with either language.

Erlang and Elixir are slightly different syntaxes for the same semantics, and if you know one you can learn to read and probably write the other in less than a day.

It isn’t like Clojure and Java where Clojure is significantly higher level than Java in many ways. Elixir adds a few things to Erlang but is otherwise the same programming model.

> I just don't know which niche applications Elixir targets and excels at.

Pretty much any application where concurrent IO and state management are the main problems. Web applications, proxies/brokers, long running network stuff, semi-embedded low power devices that are hard to physically access and must remain reliable for years at a time, that kind of thing.

I actually agree with you that the ecosystem and tooling and especially the value proposition are confusing, and the sales pitch over the years has often been poor.

The whole BEAM community would do well to speak more plainly about the concrete benefits for programmers and companies, and the existing successful applications rather than the theoretical beauty of the syntax or the actor model.

I hope this helps.

asa400··on Elixir 1.19
Anyone downvoting care to comment on why a benchmark of a feature in this release is downvote worthy?
asa400··on Elixir 1.19
Just a data point on the deps compilation, on a small Phoenix app with mostly stock Phoenix deps:

  MIX_OS_DEPS_COMPILE_PARTITION_COUNT=1 mix deps.compile  32.30s user 7.23s system 320% cpu 12.336 total

  MIX_OS_DEPS_COMPILE_PARTITION_COUNT=5 mix deps.compile  0.37s user 0.49s system 12% cpu 6.970 total

  MIX_OS_DEPS_COMPILE_PARTITION_COUNT=10 mix deps.compile  0.38s user 0.50s system 12% cpu 7.236 total
Machine is a Mac M1 Max, `rm -rf _build` in between each run.
← PreviousPage 5 of 10Next →