HNHacker News
TopNewBestAskShowJobs

OskarS

8,392 karma · joined September 4, 2016

submissionscomments
OskarS··on Solving a wooden puzzle using Haskell
Indeed it is, and Donald Knuth spends a substantial part of the latest volume (4B) of The Art of Computer Programming on solving exact cover problems like this using Dancing Links! He presented an earlier version of the algorithm in this legendary article [1], but as good as that article is, the book is even better (and the algorithm improved!). It also has tons of exercises like this. Cannot recommend it highly enough.

[1]: https://arxiv.org/abs/cs/0011047

OskarS··on IG Nobel Prize Winners 2025
I was curious about this study as well, both because the idea seems genius and wildly unsafe. I mean, I know teflon is inert, but really safe for consumption in quantities required for satiation? I googled the paper's title, and here it is: https://pubmed.ncbi.nlm.nih.gov/26810925/

The answer is that it's a study in rats, seemingly (from the abstract) a very successful one. Probably a bad idea to introduce that amount of "forever chemicals" into the environment, but the central idea seems pretty sound.

OskarS··on Pnpm has a new setting to stave off supply chain attacks
I have a question: when I’ve seen people discussing this setting, people talk about using like ”3 days” or ”7 days” as the timeout, which seems insanely short to me for production use. As a C++ developer, I would be hesitant to use any dependency in the first six months of release in production, unless there’s some critical CVE or something (then again, we make client side applications with essentially no networking, so security isn’t as critical for us, stability is much more important).

Does the JS ecosystem really move so fast that you can’t wait a month or two before updating your packages?

OskarS··on How to self-host a web font from Google Fonts
I must say, this is a little bit like complaining that Google supplied a PNG when you wanted a JPG. Like, the original file is the TTF/OTF, that's the raw material and what you would use in an OS or an application. And it works fine in CSS as well. Just convert it to a WOFF2 if you really want to, it's not hard.
OskarS··on How to self-host a web font from Google Fonts
I'm a very dedicated anti-Google person who's trying to move everything I can off of any kind of Google service, so I very much understand the desire to self-host. But I find it hard to find fault with Google here. "If you don't want to worry about hosting, here's a one-liner you can add to CSS that hosts it off our servers. If you want to do something else, here are the raw font files as a single click download, do whatever you like!". That seems perfectly reasonable to me, and it's a great service to improve typography on the web.
OskarS··on How to self-host a web font from Google Fonts
Google Fonts lets you just download the font, right? So what's the problem with self-hosting them? They're not encrypted or anything. Like, I'm not sure what else you would want Google to do.
OskarS··on FakeIt: C++ Mocking Made Easy
I can’t remember ever seeing a bigger red flag on a C++ library than this. Even leaving aside the implications of UB (where I agree with you), does this mean I can’t run my test suite in release mode? What if it’s slow to run? What if there’s a bug that only happens in optimized builds?

That’s gonna be a big no from me, dawg.

OskarS··on Hashed sorting is typically faster than hash tables
If the person who taught you big-O notation didn't point out that for all practical values of N, log(N) is tiny, then they did you a disservice. It is indeed "practically constant" in that sense.

However, when someone says an operation is O(1) vs O(log N), it still tells you something important. Very broadly speaking (tons of caveats depending on problem domain, of course) O(log N) usually implies some kind of tree traversal, while O(1) implies a very simple operation or lookup. And with tree traversal, you're chasing pointers all over memory, making your cache hate you.

So, like, if you have a binary tree with 65000 elements in it, we're talking a height of 15 or 16, something like that. That's not that much, but it is 15 or 16 pointers you're chasing, possibly cache-missing on a significant amount of them. Versus a hash-table lookup, where you do a single hash + one or two pointer dereferences. If this is in a hot path, you're going to notice a difference.

Again, lots of caveats, this article provides a good exception. In this case, the sorting has much more beneficial cache behavior than the hash table, which makes sense. But in general, log(N) hints at some kind of tree, and that's not always what you want.

But yes, don't be afraid of log(N). log(N) is tiny, and log(N) operations are very fast. log(N) is your friend.

OskarS··on The elegance of movement in Silksong
Corrected, thanks.
OskarS··on The elegance of movement in Silksong
I mean, fair enough I guess, but there's a lot of games on that list. I don't think you would go around saying "LittleBigPlanet is widely regarded as one of the best of all time" just because it appears in that article. A lot of publications has done click-baity "top 100 games of all time".
OskarS··on The elegance of movement in Silksong
> It's the sequel to a game (Hollow Knight) which is widely regarded as one of the best of all time.

I would say this is overstating it a bit. Hollow Knight was critically lauded, grew an intense fan-base, and often considered one of the best in its genre (the awkwardly named group of "metroidvanias"), but it's a bit much to say that it has the reputation of "one of the best of all time". It's not, like, Tetris or Super Mario World.

Also, and this is just my personal opinion, but I'm about a dozen hours into it, and so far I haven't found it THAT much harder than the original. Maybe it's because I've played Hollow Knight and gotten used to the controls by now, but I remember struggling a lot with lots of parts of Hollow Knight, about as much as I'm struggling with Silksong. Enough people have been saying it so I suspect I might just be misremembering.

Excellent game in general, by the way, really enjoying Silksong so far.

OskarS··on RFC 3339 vs. ISO 8601
> No, I think it's very important to understand that local times in the future do not identify a point in time and that local times are not necessarily tied to any particular location.

I mean, they sometimes do. You might want to wake up at 7.00 AM in the morning regardless of what timezone you’re in, but if I ask Siri what time sunrise is tomorrow (very relevant for setting my alarm!) she better give it to me in local time taking time zones into account.

Another example: I’ve added all the F1 races and qualifications this year to my calendar (I’m a big fan) so I can easily check that the Italian Grand Prix at Monza starts today at 3.00 PM my local time. If I travel to another timezone, my calendar better adjust, or else I’ll miss the races.

OskarS··on Oldest recorded transaction
There's always a sliding scale between "proto-writing" and fully developed writing systems, but just using symbols phonetically instead of semantically happens much faster than that. The very archaic forms of proto-cuneiform is from about 3400 BCE (though things like clay tokens are much older). It, like virtually all writing systems in the world, developed into a true writing system by use of the "rebus principle", where symbols came to acquire different meanings based on phonetics in the same way as in a rebus. Like, in English, if you had a symbol for "female sheep" (a "ewe"), you could start to use it to signify the word "you", even though there's no semantic connection.

The earliest evidence for this in cuneiform is from around 3200-3000 BCE. There is a famous tablet where the symbol for "reed" is used to represent the word "reimburse", because they're both pronounced like gi. By a few hundred years later, cuneiform was a fully fledged phonetic writing system.

OskarS··on Melvyn Bragg steps down from presenting In Our Time
It's not just you, that does grate on me sometimes as well. I get that he needs to move the show on, but I often feel like the guest is trying to make quite an important point when he interrupts. Still love it, though.
OskarS··on Melvyn Bragg steps down from presenting In Our Time
As I've listened to more and more of it, I start to gravitate not to particular topics, but to particular experts. There are many guests who are regulars when topics in their field come up, and the good ones make any topic in that field interesting. For instance, if there's an episode about religious history and Martin Palmer is on it, it's bound to be a banger (listened to one on Augustine's Confessions recently, for instance, and it was great). Same with Ancient Greece and Paul Cartledge and Angie Hobbs. If I'm looking for something to listen to, I just put one of those three into the search field of my podcast player, and I'm never disappointed.
OskarS··on Melvyn Bragg steps down from presenting In Our Time
Yes, that one was the first I thought of as well.
OskarS··on Melvyn Bragg steps down from presenting In Our Time
The thing that makes it work (aside from Melvyn's excellent hosting) is that they have an unspoken but fundamental assumption about the audience, which is that the listeners are intelligent. Like, it's ok to have nuance, to dig deep into topics, it's even ok for listeners not to follow every point precisely. But the listeners are smart people that appreciate hearing from people who know what they're talking about.

That's a very rare assumption in modern media, when most mainstream things seemed to be aimed at some sort of lowest common denominator.

OskarS··on Melvyn Bragg steps down from presenting In Our Time
If you want to add to that list, check out Only Connect on the BBC. Best quiz show for smart people in the world.
OskarS··on That boolean should probably be something else
I don’t remember exactly where I read this, but I think it was some internet forum of some kind. It makes sense that whoever wrote it got it from there. Never read it myself.
OskarS··on That boolean should probably be something else
You're correct in principle, but I'm saying that "in practice", boolean arguments are usually feature flag that changes the behavior of the function in some way instead of being some pure value. And that can be really problematic, not least for testing where you now aren't testing a single function, you're testing a combinatorial explosions worth of functions with different feature flags.

Basically, if you have a function takes a boolean in your API, just have two functions instead with descriptive names.

OskarS··on That boolean should probably be something else
Lua doesn't directly support keyword arguments, but you can simulate it using tables:

    serialize(someObject, { prettyPrint = true })
And indeed that is a big improvement (and commonly done), but it doesn't solve all problems. Say you have X flags, then there's 2^X different configurations you have to check and test and so forth. In reality, all 2^X configurations will not be used, only a tiny fraction will be. In addition, some configurations will simply not be legal (i.e. if flag A is true, then flag B must be as well), and then you have a "make illegal states unrepresentable" situation.

If the tiny fraction is small enough, just write different functions for it ("serialize()" and "prettyPrint()"). If it's not feasible to do it, have a good long think about the API design and if you can refactor it nicely. If the number of combinations is enormous, something like the "builder pattern" is probably a good idea.

It's a hard problem to solve, because there's all sorts of programming principles in tension here ("don't repeat yourself", "make illegal states unrepresentable", "feature flags are bad") and in your way of solving a practical problem. It's interesting to study how popular libraries do this. libcurl is a good example, which has a GAZILLION options for how to do a request, and you do it "statefully" by setting options [1]. libcairo for drawing vector graphics is another interesting example, where you really do have a combinatorial explosion of different shapes, strokes, caps, paths and fills [2]. They also do it statefully.

[1]: https://curl.se/libcurl/c/curl_easy_setopt.html

[2]: https://cairographics.org/manual/cairo-cairo-t.html

OskarS··on That boolean should probably be something else
A piece of advice I read somewhere early in my career was "a boolean should almost never be an argument to a function". I didn't understand what the problem was at the time, but then years later I started at a company with a large Lua code-base (mostly written by one-two developers) and there were many lines of code that looked like this:

   serialize(someObject, true, false, nil, true)
What does those extra arguments do? Who knows, it's impossible without looking at the function definition.

Basically, what had happened was that the developer had written a function ("serialize()", in this example) and then later discovered that they wanted slightly different behaviour in some cases (maybe pretty printed or something). Since Lua allows you to change arity of a function without changing call-sites (missing arguments are just nil), they had just added a flag as an argument. And then another flag. And then another.

I now believe very strongly that you should virtually never have a boolean as an argument to a function. There are exceptions, but not many.

OskarS··on The Therac-25 Incident (2021)
I agree, that is very true, Therac-25 was incompetence, Post Office was incompetence with a heavy dose of malice. This aspect just steuck me as similar, the unquestioning belief in the infallibility of software.
OskarS··on The Therac-25 Incident (2021)
It's interesting to compare this with the Post Office Scandal in the UK. Very different incidents, but reading this, there is arguably a root assumption in both cases that people made, which is that "the software can't be wrong". For developers, this is a hilariously silly thing, but for non-developers looking at it from the outside, they don't have the capability or training to understand that software can be this fragile. And they look at a situation like the post office scandal and think "Either this piece of software we paid millions for and was developed by a bunch of highly trained engineers is wrong, or these people are just ripping us off". Same thing with Therac-25, this software had worked on previous models and the rest of the company just had this unspoken assumption that it simply wasn't possible that there was anything wrong with it, so testing it specifically wasn't needed.
OskarS··on Google will allow only apps from verified developers to be installed on Android
As a single developer, you have very little weight against Google. The same is true of a single developer in the US.

What does have weight is the European Union, which Croatia is a member of. If the EU parliament makes a law that Google is not allowed to have these kinds of rules and do business in the EU, then Google will listen. Given the horrible state of the US government, the EU is just about the only force left in the world able and willing to stand up against these tech giants in a way that forces them to pay attention and act responsibly.

OskarS··on Dynamically patch a Python function's source code at runtime
Several! You're correct that Lisps is the most famous, and there's also languages like Erlang that have this as a core functionality. But it's also used in things like game engines for C/C++. You do have your "updateAndRenderFrame()" function in a dynamic library, having it take a pointer to the full game state as an argument. When you want to reload, you recompile your dynamic library, and the main loop can swap out the implementation, and the game keeps running with the new code. I don't see a reason why you couldn't do this in Rust, though I imagine it's trickier.
OskarS··on Code review can be better
I don't know about "shouldn't", I think it's fine if they do. But I basically agree, at some fundamental level, you have to have some trust in your coworkers. If someone says "This fixes X", and they haven't even tried running it or testing it, they shouldn't be your coworker. The purpose of code reviews shouldn't be "is this person honest?" or "is this person totally incompetent?". If they're not, it's a much bigger issue, one that shouldn't be dealt with through code reviews.

Very different situation if it's open source or an external contribution, of course.

OskarS··on Undefined Behavior in C and C++ (2024)
> For example the reason why 2s complement took so long is because of some machine that ran C that still existed that was 1s complement.

You're misunderstanding me: as of C++20, there is no other representation in C++ for signed integers other than two's complement (no signed ones' complement, no signed magnitude, nothing else), but signed overflow is still UB. It's not because of obscure machines or hardware, such hardware is not relevant for C++20 and later. The reason for it is performance. From the accepted paper [1]:

> The following polls were taken, and corresponding modifications made to the paper. The main change between [P0907r0] and the subsequent revision is to maintain undefined behavior when signed integer overflow occurs, instead of defining wrapping behavior. This direction was motivated by:

> * Performance concerns, whereby defining the behavior prevents optimizers from assuming that overflow never occurs

You may disagree, you may think they're wrong, but their motivation is performance, that's why this is UB. It's right there in black and white. This was C++, not C, but it's not at all unthinkable that the C standard will also mandate two's complement at some point, and if they do, they almost certainly keep signed overflow undefined for exactly the same reason.

It's not hard to write code that optimizes much better when you use signed loop variables. One of my favorite examples is this function [2] to turn a 3D mesh inside out by flipping the edges of each triangle in a triangle mesh. The godbolt link has two versions of the same function, one with a signed loop variable, one with an unsigned one. The signed one auto-vectorizes and optimizes much better because it can assume that the loop variable never overflows (this version is C++, it's trivial to rewrite it in C and get the same results).

This is why signed overflow is UB.

[1]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p09...

[2]: https://godbolt.org/z/a1P5Y17fn

OskarS··on Undefined Behavior in C and C++ (2024)
You do need some way to overflow properly, because sometimes that is what you want. A common example would be PRNGs, which frequently rely on overflow (the classic LCG, for instance). You could argue that should just be a library function or something (e.g. `add_with_overflow`), though that's more C++ than C.

You are absolutely, 100% correct though: I've never seen a case where accidental overflow doesn't start causing bugs anyway. Like, the Pac-Man kill screen is caused by a byte overflowing (it happens on level 256), and the game goes insane. Pac-Man was written in assembly where overflow is defined behavior, but that doesn't matter at all, the game is still broken. If signed overflow is essentially always a bug anyway, why not make it UB and optimize around it? Especially since it is super-valuable in being able to unroll loops.

People always bring up signed integer overflow as an argument for why UB is scary, and it always seemed like such a bad argument to me. Like, I can understand why people think UB has gone too far in C/C++, but signed overflow is such a bad example. It's one of the most sensible bits of UB in the entire standard, IMHO.

OskarS··on Undefined Behavior in C and C++ (2024)
No, it's absolutely because of optimization. For instance, C++20 defined signed integer representation as having two's complement, but signed integer overflow is still undefined behaviour. The reason is that if you compile with flags that make it defined, you lose a few percentage points of performance (primarily from preventing loop unrolling and auto-vectorization).

Same thing with e.g. strict aliasing or the various UB that exists in the standard library. For instance, it's UB to pass a null pointer to strlen. Of course, you can make that perfectly defined by adding an `if` to strlen that just returns 0. But then you're adding a branch to every strlen, and C is simply not willing to do that for performance reasons, so they say "this is UB" instead.

Pretty much instance of UB in standard C or C++ is because making it defined would either hamper the optimizer, or it would make standard library functions slower. They don't just make things UB for fun.

← PreviousPage 4 of 34Next →