HNHacker News
TopNewBestAskShowJobs

OskarS

8,399 karma · joined September 4, 2016

submissionscomments
OskarS··on Prefer the British Style of Quotation Mark Punctuation over the American
This is the kind of thing that really annoy programmers (because in programming languages, you can never omit things like this), but everyone else is perfectly fine with.

As a programmer though, it certainly annoys me!

OskarS··on Username ending with MIME type format is not allowed
> Staff member made a change to disallow usernames ending with `Mime::EXTENSION_LOOKUP.keys`

This is a hell of a thing to commit and pass code review in 2021 on a project like GitLab. I understand that the staff member was fixing a security issue and was probably not thinking deeply about the ramifications, but even so. How many "Falsehoods programmers believe about names" articles do we need?

OskarS··on Resource efficient Thread Pools with Zig
Yeah, it's a true point that "lock-free" != "fast". If contention is very low, the simple version using mutexes often perform better.
OskarS··on Resource efficient Thread Pools with Zig
”Lock free” has a very precise meaning in computer science, and it’s this: ”given some number of threads of execution, an algorithm is lock free if in some finite number of steps, at least one thread is guaranteed to make forward progress”. When using mutexes, this is not guaranteed under any amount contention: the scheduler is perfectly free to preempt a thread holding a lock, which means no threads make progress.

However, if you use a CAS loop (like this code does) to update some value (i.e. a while loop that repeatedly tries to execute a compare-and-swap), that loop will only fail to make progress if some other thread DID make progress. This means that such an algorithm is in fact lock-free: if thread X didn’t progress, it is necessarily because some other thread did. In addition, a scheduler preempting a thread at any point will not stop other threads making progress.

Whether an algorithm is lock free or not is not a matter of opinion, it is a mathematical statement. The fact that it annoys you is… weird.

OskarS··on M1 Icestorm cores can still perform well
Yeah, that makes a ton of sense. Cache misses would be less of a factor in the highly optimized assembly case.
OskarS··on M1 Icestorm cores can still perform well
It's generally true. Both Rust and C++ (and Swift to a smaller extent) are both all about the "zero cost abstractions", but they usually aren't. It's hard to beat the C-style for-loop: they map really closely to the underlying hardware, and modern compilers are starting to become really good at auto-vectorizing them.
OskarS··on M1 Icestorm cores can still perform well
> Highly efficient assembly showed the least performance drop whereas complex "idiomatic" Swift code showed the greatest performance drop.

I wonder what this means. The efficient assembly probably has fewer instructions that use vector instruction and floating point calculations more, while the "idiomatic" Swift probably has just a larger number of instructions that aren't doing heavy calculation. Does that imply then that the high performance cores does much deeper pipelining, but the the number floating point units or whatever is probably pretty similar across both types?

OskarS··on All you need is call/cc (2013)
> I think an even more interesting perspective is that they aren't the same thing, but they can be implemented in terms of each other.

I don’t know, I think that it’s perfectly reasonable even from an engineering/computer science perspective to say that they are literally the same thing, just viewed from two different perspectives.

After all, what is an object? It’s some code, with bundled data. What is a closure? It’s some code… with some bundled data. I think it’s fair to say that this is a “is it a vase or two faces?” situation. You’re looking at the same image, just seeing it from different perspectives.

OskarS··on Life Before Unicode
> I don't recall them before Unicode. I do recall "dry clean only" on the tags, etc.

These icons are far older than unicode, and in fact is not in unicode at the moment. There's a proposal to add them, but I don't believe it's passed yet. The standardized icons themselves date from the 1970s, though non-standard laundry symbols are much older than that.

Design use of icons over text has nothing to do with Unicode, it's a natural part of human expression. Icons are everywhere, from traffic signs to laundry symbols to buttons on computers to ramblings signs. I think your reading of the typographical history here is simply wrong, neither Apple nor Unicode is responsible for the "iconiziation" of communication. We've always used icons for communication, and we always will.

If your issue is with Emoji, then you should make that case instead. Personally, i think it's great that if I send an emoji from an iPhone to an Android phone (or from/to essentially any device), you get a consistent symbol, instead of being locked in to whatever your manufacturer was using (the fact that this kind of lock-in was occurring was the original motivation for adding emoji to Unicode).

Btw, laundry symbols are a perfect demonstration for another wonderful feature of using icons: they're cross language. You can put one tag on a piece of clothing and sell it anywhere in the world. Not everyone speaks English.

OskarS··on Life Before Unicode
Yeah, in my opinion this is by far the biggest one. The rest of list are either non-issues, or they're annoying but you can deal with them (and there's often arguments on both sides).

Han unification, on the other hand, is a disaster for Unicode. The fact that Unicode can't comfortably mix Chinese and Japanese language characters is a disaster for an encoding like Unicode that's supposed to cover the whole world.

OskarS··on Rolling hash; Rabin-Karp string search
The fact that C strings are presented in this format is totally irrelevant for the discussion of string search algorithms. They all have to know the length. Strings in most languages are not in that format, and it is an entirely reasonable assumption that the length is a known quantity.

If you wanna be annoying about this, just imagine he's implementing `strnstr` instead of `strstr`.

OskarS··on Rolling hash; Rabin-Karp string search
Fair enough, but the strlen is not part of the search algorithm, it’s just figuring out the input. It could easily be an argument, but that would complicate the test code below.
OskarS··on C++20 Concepts: The Definitive Guide
As other users mentioned, the most relevant part is when you divide by 0, you get different infinities depending on if you're dividing by +0.0 or -0.0. But even beyond that: the binary representation of floating point numbers [1] necessarily means that there are two values for zero with distinct bit patterns.

Floating point numbers have a dedicated sign bit that specifies the sign, which means that you can flip the sign of any floating point number and get a float with a different bit pattern (and opposite sign). That means that you get necessarily get both +0.0 and -0.0, and they have different internal representation in bits.

This is one of the major advantages of two's complement notation for representing integers: it doesn't have a dedicated sign bit in the same way, so you only get one representation for 0. You can still check the sign by looking at the top bit, but if you flip it for the number 0, you don't get -0 (which doesn't really exist), you get -128 (for 8 bit signed integers).

[1]: https://en.wikipedia.org/wiki/Double-precision_floating-poin...

OskarS··on Strict Tables – Column type constraints in SQLite - Draft
If you used SQLite like the grandparent described (adding check constraints to the CREATE TABLE statement), it would error out when running the statement with the incorrectly bound types. The proposal here is basically to (if you opt in to it) automate that process so it just happens automatically.

I have no idea how the postgres C API looks, but the SQLite API has different functions for binding different kinds of data types to prepared statements, like `sqlite3_bind_int` for ints, `sqlite3_bind_blob` for binary blobs, `sqlite3_bind_text` for strings, and so forth. So SQLite "knows" the source type you're binding.

OskarS··on On the link between great thinking and obsessive walking
> With everything in the news about reproducibility and doctored data, this seems too staggering to believe. Has this study been tried again?

Yep, totally! I'm a firm believer in the power of walking to increase thoughts, but whenever I read about studies like this a big red beeping alarm goes of in my brain that goes "replication crisis! replication crisis!"

OskarS··on Strict Tables – Column type constraints in SQLite - Draft
Say you’re using the C API (not really relevant which language, any statically typed language would work) and had the line

    sqlite3_bind_int(stmt, 3, 45);
to bind the value 45 to the third item in whatever INSERT/UPDATE statement you’re doing. But that was actually wrong: the third item is supposed to be a string, you meant to bind the int to item 4.

A strictly typed database would error out here, a dynamically typed one will just assign the int to the string column, potentially corrupting data.

This is exactly equivalent to messing up types for variables in a dynamically typed language, all pros and cons of typechecking apply equally for SQL. The fact that the host language C is statically typed is irrelevant.

OskarS··on Gitfs: Version Controlled File System
Clicking the link, I was kinda hoping it was some version of VFS for Git, but for operating systems other than Windows. Kinda bummed that it wasn't, this seems kinda pointless. Microsoft is (allegedly) working on macOS and Linux drivers for that thing, but it's been a while now. I hope it's going to become an actual thing one day, it's such a cool idea.
OskarS··on Intel C/C++ compilers complete adoption of LLVM
I'm not sure I love this. I mean, LLVM is awesome and everthing, but software monocultures are pretty bad. It's not like the situation is dire yet (given that there are also GCC and MSVC), but you can imagine a situation in a couple of years when Microsoft goes "yeah, we're also gonna go with LLVM now" and also GCC starting to fade away. It's a bit concerning.

Also: if icc is going to go with LLVM as a backend, then what is the point of using icc at all? Why not just use clang?

OskarS··on Summary of the semantics of inline in C and C++
Ah, good point, I missed that my version became a tail call, good catch. Still, a C function call is pushing a couple of values onto the stack then performing an unconditional jump, so it's not much worse.

That site is indeed very neat! It just uses Google Benchmark in the background, but it's excellent for these kinds of discussions (and lovely to have it link directly to godbolt if you want). It's a shame that it doesn't give you the actual latency numbers like regular Google Benchmark, but I suppose that is to be expected when you're running in server VMs, those numbers aren't necessarily meaningful.

OskarS··on Summary of the semantics of inline in C and C++
> Doing a function call is quite expensive!

Doing a function call in C/C++ is not expensive. I wish people would stop saying this, it's just not true, it's one of the most annoying myths in programming. A C function call is on the order of a tiny number of nanoseconds. Here's a benchmark to compare [1]. It's an infinitesimal amount, and it is absolutely swamped by something like a cache miss. If you eliminate one cache miss but add 50 function calls, that's probably a net benefit.

The only sense in which function calls in C are "expensive" is during compilation: if a compiler can inline a function call, it can potentially do tons of new optimizations that it couldn't do before, and that can yield a huge improvment in performance. But the function call ITSELF is almost never the problem.

[1]: https://quick-bench.com/q/2q8ch4HmQSpsSdrwd082NpV3KeI

OskarS··on So you want to write a GUI framework
The article deals with this in a later section and has an interesting discussion about the tradeoffs. Note that you don't have to ship Chromium with every app, you can also go use web rendering engines supplied by the platforms.
OskarS··on echo 'I wrote a Bash book' >> /dev/world
Just be careful to quote filename variables. Don't write this:

    cp $FILENAME $TARGET
Write this:

    cp "$FILENAME" "$TARGET"
It's a bit annoying, but it's not that bad, and certainly not unmaintainable.
OskarS··on Libraries can start processes too
I see that point, but it was pretty jarring reading this Elixir article as a curious outsider that they had to make these kinds of very advanced contortions to do something so simple in such a non-performant way. It’s something that is only impressive if you were already totally sold in on the BEAM way of doing things, but looks insane to any C/C++/Rust/Java/whatever developer.
OskarS··on Libraries can start processes too
I think Erlang and Elixir are incredible, and this particular feature of libraries starting BEAM processes seems cool in the abstract. However, this PARTICULAR task, Erlang/Elixir might be the worst possible language you could choose:

> The Elixir approach to shared mutable state is wrapping it in a process. In this case, I needed a counter and the easiest way to implement it is to use an Agent which is a kind of process designed to handle simple state. In this case, the get_and_update function allows me to return the counter and increment it as an atomic operation.

This is literally just an atomic counter. It’s a single CPU instruction that is guaranteed to be safe. I don’t care how lightweight a BEAM process is, it’s not faster than updating an atomic counter. Doing it this way is also absurdly more complicated than using, say, a std::atomic in C++ (or the equivalent type in other languages).

Again, I think Elixir is cool, but if you want to show off how cool it is, maybe don’t use an example that is incredibly much slower and more complicated than it should be. It’s not a great look for Elixir.

OskarS··on strcpy: A niche function you don't need
And the first argument to printf (the format), what kind of string is that? And what kind of string does sprintf() produce?
OskarS··on Who Owns My Name?
I haven’t seen the movie so I have no idea, but I can’t but quote from the article itself:

“..is the character based on me actually innocent?

Turns out, she asked the killer to help her get rid of her roommate. She didn’t mean for him to kill her, but her request indirectly led to the murder. How do you think that impacts my reputation? I continue to be accused of “knowing something I’m not revealing,” of “having been involved somehow, even if I didn’t plunge the knife.” So Tom McCarthy’s fictionalized version of me is just the tabloid conspiracy guilter version of me.”

OskarS··on Who Owns My Name?
It’s a really powerful article, and it’s hard to argue with any of it. What a nightmare it must be to have what happened to Amanda Knox happen to you. A totally innocent person, who was not only imprisoned for years for a crime she had nothing to do with, but also had her name dragged in the mud by the global press for years. To such an extent that most casual observers still think she had something to do with the crime.

It’s clear that the filmmakers have no legal obligation to Knox (and she acknowledges as much in the article), but I think it is equally clear that they have a moral obligation to not slander her using a thinly veiled fictional character.

It’s a shame too, because the real “Amanda Knox saga” would make for a much more interesting movie: what is it like to have your roomate murdered, your life destroyed, and your identity robbed from you by the global tabloid press? That’s the real Amanda Knox story.

OskarS··on How JavaScript works: an overview of the engine, the runtime, and the call stack
It’s also, like, trivial: as far as I can tell, this is just a very basic description of how a call stack works mixed in with advertising calls to action.
OskarS··on Faster sorted array unions by reducing branches
The whole point of the article is that the optimizer in GCC did not do this.
OskarS··on Faster sorted array unions by reducing branches
Nice article! This sort of code is not just used in databases, it's also obviously the "merge" step in mergesort.

The fact that you have to "lure" the compiler into making the hot loop branchless is a little bit weird: you'd think there would be a compiler intrinsic or something which was like `cond_val(condition, val1, val2)` which worked something like `condition ? val1 : val2` but was guaranteed (or close to it) to be free of branches. Shaders have something like that with the `step()` function, seems like a useful thing for this kind of high-performance code.

I mean, obviously you could always write this yourself with inline assembly (or using SSE2 intrinsics or whatever), but that would only work on some platforms and might mess with compiler optimizations, so that seems less optimal.

← PreviousPage 17 of 34Next →