HNHacker News
TopNewBestAskShowJobs

OskarS

8,399 karma · joined September 4, 2016

submissionscomments
OskarS··on CrowdStrike Update: Windows Bluescreen and Boot Loops
Please tell me you've ended the contract with CrowdStrike after this?
OskarS··on CrowdStrike Update: Windows Bluescreen and Boot Loops
Can you say with a straight face that if you were designing a system that had extremely high requirements of reliability that you would choose Windows over Linux? Like, all other things being equal? I'm sorry, but that would be an insane choice.
OskarS··on Compile-time JSON deserialization in C++
It's not just that. If ALL that was in the header was the function prototype, that adds basically nothing to the compile time. The problem is when you have significant codegen and parsing in headers, like you do with templates and class definitions and stuff like that.

Like, most C projects import enormous headers with gazillions of function prototypes without having a particularly measurable impact on compile times (compile times in C is quite good, in fact!)

OskarS··on Show HN: Dut – a fast Linux disk usage calculator
Good tip! Yeah, the `sort -rh` is what makes it sing, it's such a cool feature of coreutils that `sort` knows how to sort human-readable output from `du` or `df`
OskarS··on Show HN: Dut – a fast Linux disk usage calculator
I've used graphical tools very similar to this, and I always come back to this:

   du -h | sort -rh | less
(might have to sudo that du depending on current folder. on macos, use gsort)

You just immediately see exactly what you need to delete, and you can so quickly scan the list. I'm not a terminal die-hard "use it for everything" kinda guy, I like GUIs for lots of stuff. But when it comes to "what's taking up all my space?" this is honestly the best solution I've found.

OskarS··on Compile-time JSON deserialization in C++
There is another scenario where this is an issue: if this code ends up in a header which is included in a lot of places. You might say "that's dumb, don't do that", but there is a real tendency in C++ for things to migrate into headers (because they're templates, because you want them to be aggressively inlined, for convenience, whatever), and then headers get included into other headers, then without knowing it you suddenly have disastrous compile times.

Like, for this particular example, you might start out with a header that looks like:

    SomeData get_data_from_json(std::string_view json);
with nothing else in it, everything else in a .cpp file.

Then somebody comes around and says "we'd like to reuse the parsing logic to get SomeOtherData as well" and your nice, one-line header becomes

    template<typename Ret>
    Ret get_data_from_json(std::string_view json) {
        // .. a gazillion lines of template-heavy code
    }
which ends up without someone noticing it in "CommonUtils.hpp", and now your compiler wants to curl up in a ball and cry every time you build.

It takes more discipline than you think across a team to prevent this from happening, mostly because a lot of people don't take "this takes too long to compile" as a serious complaint if it involves any kind of other trade-off.

OskarS··on PostgreSQL and UUID as Primary Key
This is a very weird thread: half the people are arguing that having these timestamps is not a realistic security problem at all, and the other half is arguing that any fix to it has to have Fort Knox level security policies.

It seems to me: the actual value of knowing these ids/timestamps to a hacker is tiny, but it's not nothing (German tank problem and all that). Like, if a hacker was able to decode the timestamps, it's not ideal, but it's not like a catastrophe either (especially given that half the people in this thread thinks it has no security value at all). Given that threat model, a simple scheme like I suggested seems fine to me.

OskarS··on PostgreSQL and UUID as Primary Key
You store the key in the database, right? Like, if the database leaks, it doesn’t matter if your ids are sequeneced or unsequenced, because all data has leaked anyway. The key leaking doesn’t seem like a realistic security issue.
OskarS··on PostgreSQL and UUID as Primary Key
Can I ask (as a humble application developer, not a backend/database person), if the two requirements are:

1. The UUIDs should be ordered internally, for B-tree performance

2. The UUIDs should not be ordered externally, for security reasons

Why not use encryption? The unencrypted ID is a sequential id, but as soon as it leaves the database, it's always encrypted. Like, when getting it out:

    SELECT encrypt(id) FROM table WHERE something = whatever;
and when putting stuff in:

    UPDATE table SET something = whatever WHERE id = decrypt(<encrypted-key>)
Seems like the best of both worlds, and you don't need to store separate things.
OskarS··on Starlark Language
Ah, fair enough. I've only tested the Rust version.

Yeah, important to note, in practice it is always finite, since if you try to do anything "real" using this trick, you blow the stack immediately. This was mostly just a fun fact about how easy it is for Turing-completeness to sneak in. I seem to remember reading something about how Algol-60 was similar, they intended it not to allow recursive procedures, but permitted function pointers (or something) and you could do a similar thing.

OskarS··on Starlark Language
It actually is, because it allows functions as first class objects. That means you can use the fixed-point combinators from lambda calculus (which doesn't have direct recursion either). For instance, the Omega combinator (sort-of):

    $> def f(g): g(g)
    $> f(f)
    Traceback (most recent call last):
      * expression:1, in <module>
          f(f)
      * expression:1, in f
          def f(g): g(g)
      * expression:1, in f
          def f(g): g(g)
      * expression:1, in f
          def f(g): g(g)
      <many stack frames omitted>
      * expression:1, in f
          def f(g): g(g)
    error: Starlark call stack overflow
     --> expression:1:11
      |
    1 | def f(g): g(g)
      |           ^^^^
      |
Infinite recursion, fun!

(this is the starlark-rust repl, which is the only one I have currently installed)

You could easily implement the Y combinator like this, and boom, Turing completeness.

In practice, it doesn't matter, because the way they've been implemented is with limited enough stack space that it's not really relevant. But arguably, that is an implementation detail, and you could implement Starlark with either TCO or growable stacks or whatever. Just like normal Turing complete languages doesn't have infinite memory, Starlark doesn't have infinite stack space. I would strongly argue that the language itself is very much Turing complete.

OskarS··on Leveraging Zig's Allocators
I will admit that I really miss the "value semantics" thing that RAII gives you when working in Zig. A good example is collections, like hash tables or whatever: ownership is super clear in C++/Rust. When the hash tables goes away, all the contained values goes away, because the table owns its contents. When you assign a key/value, you don't have to consider what happens to the old key/value (if there was one), RAII just takes care of it. A type that manages a resource has value semantics just like "primitive" types, you don't have to worry.

Not so in Zig: whenever you deal with collections where either the keys or values manages a resource (i.e. does not have value semantics), you have to be incredibly careful, because you have to consider lifetimes of the HashMap and the keys/values separately. A function like HashMap.put is sort of terrifying for this reason, very easy to create a memory leak.

I get why Zig does it though, and I don't think adding C++/Rust style value semantics into the language is a good idea. But it certainly sometimes makes it more challenging to work in.

OskarS··on Start presentations on the second slide
It's very true. When watching programming talks on YouTube, I often hover the mouse over the time bar to find the first preview which looks like the slide has syntax highlighted code on it. I'm here for the cool coding stuff, not the preamble!
OskarS··on Canada imposes 5% tax on streaming to fund local news, diverse content
Personally, I think this is a great policy! Local news is incredibly important to the health of a democracy (somebody needs to show up at those city council meetings and report on them, and national media wont do it), but it's doing quite poorly in the modern media landscape. I do not think it is at all a problem to support it like this, and a tax on streaming seems like a great way to do it.

If you are hesitant about the concept of subsidizing local press or media companies in general, it's absolutely nothing new: Sweden has been doing this for more than 50 years, and (in my opinion) it's largely been extremely beneficial to the media environment.

OskarS··on iTerm 3.5.1 removes automatic OpenAI integration, requires opt-in
Totally! People in these kinds of environments have no leg to stand on criticizing a free and open source project. If you don't like it, don't use it, but CERTAINLY do not demand of the developers that they honor your requests when you don't contribute to development.
OskarS··on Discussion on why SQLite is gaining popularity [audio]
It's very easy to design a schema that breaks up blobs into chunks. SQLite is excellent for memory constrained environments, with even mathematical proofs of maximum memory usage: https://www.sqlite.org/malloc.html
OskarS··on Discussion on why SQLite is gaining popularity [audio]
The killer feature for me with SQLite is as an application file format: https://sqlite.org/appfileformat.html

It has SO MANY advantages over every other solution. It can do the "just a bundle of files" thing, but it can also do all this rich data as well. And unlike most "just a bundle of files" formats, it's incrementally updatable, it's so good. We're using this in production right now and couldn't be happier with it, wouldn't dream of using anything else at this point.

One notable application that uses SQLite for this is Audacity: all the stuff you record is streamed into a SQLite database (the project file). This is a huge reason why Audacity is so good for recording long sessions, and why it's so resilient against crashes and failures.

OskarS··on Use context-free grammars instead of parser combinators and PEG
I’ve never touched a PEG parser in my life and parsing isn’t super my thing in general, but: a recursive descent parser could parse this just fine (not left recursive), correct? But it would have to backtrack after trying rule 1 five times, and switch to rule 2 when it backtracks to the third layer of recursion?

PEGs can’t do this kind of backtracking, is that the reason?

OskarS··on After Furiosa flops, Hollywood could be facing a biblically disastrous summer
Go see Furiosa! It's not quite as incredible as Fury Road, but it's pretty darn great, and it's the exact kind of movie you should see in the cinema. Feeling the rumble in the chair from the sound system while watching is honestly thrilling.

I realize we all have excellent TVs and sound systems at home now, but the cinema is still worth it, and especially for movies like Furiosa that were just made to be experienced in one. Watching at home is definitely a much lesser experience.

OskarS··on Tail Recursion Elimination (2009)
> In the above example, do you agree that any tail call elimination would result in the wrong evaluation of `g(5) = 0` instead of the correct `g(5) = 4`?

No, I very much do not agree: it is still a tail call, and can use tail call optimization. When it calls f(x-1), regardless of whether f has been reassigned or not, you have to resolve what f is, because it COULD have been reassigned. The Python interpreter has to do this regardless, the fact that it's recursive is irrelevant.

You do that, and you get the function value you need to call (it could be the original value assigned to f, it could be the new value, it doesn't matter). At that point, nothing that is remaining on the stack frame except the arguments and return address is needed anymore, so you can reuse it for the the call to f(x-1). That is what tail call elimination is.

I'll grant that it's entirely possible that I've misunderstood this whole thing and that Guido is correct (he's a much smarter fella than me), but if so, I have no idea why I'm wrong.

> And your understanding of why python doesn't permit TCE is because functions are globally scoped with indefinite extent?

No, not at all, that was just a side note about why you were wrong to say it violated lexical scoping (it doesn't). My understanding of why Guido didn't do this is because he didn't think tail call elimination is a very useful feature for Python, and it destroys stack traces. Both of which I agree with. I just don't buy the other technical reason.

OskarS··on Show HN: Sum (algebraic) types for C in one 100 line header
I'm not totally 100% on this, but:

valueless_by_exception happens when the move assignment operator throws (which should never happen in good C++, but is not disallowed by the language). That means, the variant used to hold value X, we were moving value Y into it, but the move assignment operator failed. What is now the state of the variant? It's not X, since we started running the move constructor, which could have started destroying the old value before throwing. But it's not Y either, because the constructor didn't finish. So what's the value that's being held? The answer is that there is no valid value.

How could this be fixed using allocation? Well, if you assume that std::variant allocated, it could be implemented in such a way that the std::variant just held a pointer to a heap area which stored the actual contents of the value. When you move assign, you construct a new element on the heap and move into that.

If the move assignment completes successfully, you swap the old value pointer for the new one and destroy the old value. But if move assignment/construction fails, you just retain the old pointer: nothing has been destroyed, and the variant still holds a valid value. This is very similar to the "strong exception guarantee" for std::vector, which is violated if the move assignment operator for the value throws.

This is one of many reasons why the move constructor/assignment operator should always be noexcept: there's no reason why it should ever throw, and it violates a bunch of these kinds of guarantees.

I think, anyway. I would be happy to be corrected if I got this wrong.

OskarS··on Tail Recursion Elimination (2009)
I find that argument very unpersuasive: the optimization is tail CALL elimination, not tail RECURSION elimination, and the call to f(x-1) is certainly a tail call. I see no reason you couldn't optimize away that stack frame. "Tail recursion" is a technique in functional programming, that depends crucially on tail call elimination, but the tail call itself absolutely does not have to be recursive (it just has to be in tail position), it's just that it happens to be so in a tail recursive algorithm.

Incidentally: I don't believe that is a violation of lexical scoping. f is scoped globally, inside itself f is not defined, so f(x-1) refers to the globally scoped f. When it's reassigned, you reassign the global f. Nothing here violates lexical scoping, since f is never scoped anywhere other than globally (note that the blog post never claims it is, either)

I don't disagree with Guido's larger point, though, Python probably shouldn't use TCO. The debugging/stack trace point is very true, and also it's just not Pythonic to write algorithms TCO style. You just don't need to, in Python.

OskarS··on Why did Tom Lehrer swap fame for obscurity?
It's a good question, I'm not sure. I do think it's clearer what's going on, and the steps are more obvious. Like, there's a joke in the song about what to do with the carry, if you add it to subtrahend digit or remove it from the minuend digit ("if you're over 35 and went to public school...") which to me indicates that it's rather arbitrary and "learn algorithm by rote". Like, the "borrowing" thing just much better describes what is actually happening, rather than having to memorize a subtraction table and then have arbitrary rules about how to proceed with the carry.

But who knows, I wasn't taught the other system, maybe it's equally obvious. I do think it's indicative that the "borrowing" system is nowadays much more common (that's how I learned it in Sweden in the 90s), which probably indicates that it does have some pedagogic value. I don't think for a second either way is "more efficient" than the other: once you get the hang of the borrowing system, you do it very fast.

OskarS··on Why did Tom Lehrer swap fame for obscurity?
> But I already pointed out that the steps aren't different. They're the same style. Whether you use the term "carry" or "borrow" makes no difference to anyone.

Obviously, it does. Like, that's what the song is about. You're not just disagreeing with the other commenters, you're disagreeing with the concept of the song itself.

It's a different way of doing it, even if the underlying principle is the same. This stuff matters a lot in pedagogy, even if there's no difference in the underlying mathematics. I could say this: "you subtract two decimal numbers a_n a_n-1 ... a_1 and b_n b_n-1 ... b1 by successively calculating c_n = a_n - b_n - K_n-1 if a_n >= b_n, where K_n is the carry from the nth digit, or c_n = a_n - b_n + 10 - K_n-1 if a_n < b_n, and you set K_n to 1" or whatever. That's the same method, but it's a TERRIBLE way to teach a child how to do subtraction.

OskarS··on Why did Tom Lehrer swap fame for obscurity?
Yeah, ultimately it's the same algorithm, it's just a question of what are the details of the procedure, which makes it confusing if you've learned one way and not the other. The whole point of the song is that Lehrer thinks this is a new, less good way of doing subtraction.

Look at this video if you haven't already:

https://www.youtube.com/watch?v=UIKGV2cTgqA

The first way he does it seems INCREDIBLY confusing to people who learned arithmetic in the last 30 or so years (the sentence "8 from 4 is 6" is nonsensical to most such people), but the "modern" way he's mocking is perfectly understandable.

I think the song is very funny and charming, but I do think this is a rare case where Lehrer is just wrong, the "borrowing" style is a much better and clearer way to explain subtraction. It is just as fast, and it gives you a much better intuition about what's actually happening, instead of just learning the steps by rote.

OskarS··on Why not just do simple C++ RAII in C?
I would say there are two more esoteric options: "no memory allocation at all outside of the program stack" (like... i dunno... lambda calculus?) and fancy-pants computer sciency things like linear types. No sane language does either of those, though.
OskarS··on Why not just do simple C++ RAII in C?
You can do it in C for sure, but "culturally" in C, there's a stateless global allocator called "malloc", which is not the case in Zig. For instance, if you have a library libsomething in C, it will at most (probably) have something like this:

    #ifndef LIB_MALLOC
    #define LIB_MALLOC malloc
    #end
if it allows you to customize allocation strategy at all, which is not a given.

But this only allows you at compile time to provide your own stateless global allocator. This is very different in Zig, which has a very strong culture of "if something needs to allocate memory, you pass it a stateful, dynamically dispatched allocator as an argument". You COULD do that in C, but virtually nobody does.

OskarS··on Why not just do simple C++ RAII in C?
It absolutely does not. A C++ structure is a much richer object: it can have custom copying, moving and assignment behaviours, it can have vtables, it has RAII, etc. That's the whole point about the "object model" in the article: C++ has it, C does not.

What I think you're trying to say is "a POD structure with no custom behavior is essentially identical in C and C++". That is mostly true, though if the struct contains a union, C++ has stricter UB rules (there might be other differences as well, but that's the one I can think of at the moment).

OskarS··on Algebraic Data Types for C99
Of course the syntax sugar is a good thing if it makes it easier to write the code, but if the question is about "expressive power of the type system", it's not really relevant: Zig's type system can properly express a sum type. In addition: pattern matching is orthogonal to ADT, you can have pattern matching in both languages with and without algebraic types. Neither one implies the other.
OskarS··on How to Use JSON Path
Raku does a version of that as well, it's sick.
← PreviousPage 9 of 34Next →