Chill the fuck out.
8,392 karma · joined September 4, 2016
Chill the fuck out.
But yeah. Contiguous dynamic arrays and hash tables, those are usually what you want.
[1]: https://en.wikipedia.org/wiki/Endurance_running_hypothesis
The other option is as you mention polling using a timer, but I don't see how that's better, I'd rather move the work off of the event loop to a thread. And you then have to do the "latency vs. CPU time" tradeoff dance, trying to judge how often to poll vs. how much latency you're willing to accept.
Second: the objection isn't necessarily just that Verdana is free, it's that it's not a very good-looking font. Certainly in most people's opinion, it's nothing like as cool as Futura. IKEA, a massive multi-national company and an iconic brand, can and should do better. They say they did this to "align print and web", presumably meaning they wanted to use a font that was guaranteed to work in all browsers, but that's such a shame for print, really sacrificing great typography on the altar of browser support.
Third: font design is an art and a craft just like graphic design, photography, furniture design, script-writing, music production, whatever. There are certainly people who think literally everything should be free (as in "every Hollywood release should be Creative Commons"), but that's a rather extreme position. If you think it's a good thing that IKEA pays graphic designers to design their catalog, and furniture designers to design their furniture, you should think it's a good thing that IKEA pays typographers for their typeface design.
There are certainly issues with licensing in the world of typeface design (the emerging Monotype monopoly is really disturbing, for instance), but expecting giant companies to pay for good typography instead of using bad free typography is not some "anti-free software" stance.
Especially if you’re on the older side, it sounds like an absolutely wonderful way to spend your time. Assuming the post office doesn’t try to ruin your life afterwards.
I love it when libraries like this do that. z3 in python is similar, you just build your constraints using normal syntax and it all just works. Great use of operator overloading.
But yes, fair point: they can be stack or statically allocated as well.
You also have to heap allocate your userData, which is something std::function<> avoids (in all standard implementations) if it’s small enough (this is why the sizeof() of std::function is larger than 16 bytes, so that it can optionally store the data inline, similar to the small string optimization). The cost of that heap allocation is not insignificant.
If I were doing this, I might just go the full C route and just use function pointers and an extra ”userData” argument. This seems like an awkward ”middle ground” between C and C++.
The one thing the author's solution does which this solution (and lambdas) does not is type erasure: if you want to pass that closure around, you have to use templates, and you can't store different lambdas in the same data structure even if they have the same signature.
You could solve that in your case by making `void operator()` virtual and inheriting (though that means you have to heap-allocate all your lambdas), or use `std::function<>`, which is a generic solution to this problem (which may or may not allocate, if the lambda is small enough, it's usually optimized to be stored inline).
I get where the author is coming from, but this seems very much like an inferior solution to just using `std::function<>`.
I have no problem with the UI. It's snappy, clean, doesn't have a bunch of cruft, it's easy to find results, etc. It feels like Google of yore.
Same thing with the search results, I find them really excellent. In my experience, there's much less SEO spam. If you search for a programming language function, you get links to the proper documentation, not some trash "geeksforgeeks" site or whatever. I can't remember if I've ever had to go past page one.
Obviously YMMV on that, it's entirely possible it's different depending on what you're searching for. But I'm very happy paying for Kagi, and will continue to do so.
As a developer, it’s super-annoying that Apple is so aggressive in deprecation stuff, it forces us to frequently spend a bunch of extra time and energy updating our stuff to make sure it’s compatible woth latest macOS.
As a user though, this means that the experience of actually using a mac feels fresh and modern, and there’s a unity in design language that isn’t available anywhere else. It doesn’t take much digging in Windows settings to find windows that feel straight out of Windows 98, because Microsoft is so terrified of breaking things. macOS just feels better because of Apple’s aggressive deprecation policies, and I very much prefer it.
I have a reasonably simple personal economy and it takes me all of five minutes to file my taxes in Sweden. My parents have a much more complicated setup (small private business, own a couple of properties, several deductions, etc.) and it basically is pretty straight-forward for them as well, certainly they don't need an accountant.
TurboTax, Intuit and anti-tax Republicans has really fucked with the US expectation of how complicated taxes needs to be.
EDIT: just saw your example and checked cppreference, it says the return value "Iterator following the last removed element" for std::unordered_map. So i think you need to add an `it--` after your erase, otherwise it will "skip over" the next element. Right?
Also just read this little nugget on cppreference for unordered_map::erase:
> Removes specified elements from the container.The order of the remaining elements is preserved. (This makes it possible to erase individual elements while iterating through the container.)
This seems like a crazy guarantee to put in the standard, it must really limit the kinds of hash tables you can make that matches the unordered_map interface.
For unordered_map (and every hash table in the known universe) erasing anything invalidates all iterators, so you can't iterate while erasing. For std::map, you can if you're very, very careful (erasing invalidates the iterator you're currently on, but if you cache the next iterator, THEN erase the current one, it'll probably work, but be very fiddly). Most languages forbid this entirely: e.g. Rust's ownership model doesn't allow it, Python throws an exception, etc. It's just a very bad idea in general.
One note on API design: I think it's a FANTASTIC idea to have default `rand()` functions available, since very often, you don't really care about the generator and you're just like "just give me a random number, i don't care how". But if you do, you shouldn't have a `seed()` function, because that means you can then never upgrade it without breaking your API contract. It should always be seeded with entropy. This is why glibc's `rand()` is still using an LCG from the late neolithic, they can't ever update it without breaking a gazillion applications and tests. This is the classic example of "Hyrum's law". Doing this also helps with thread-safety: you can just make the seed/state thread-local and then it just works.
Basically, if you want the ability to seed your PRNG, you also need to specify the generator explicitly. The global one is for convenience only, and there should be no ability in the API to seed it.
EDIT: btw, this is a really nice thing about C++, doing this is dead easy:
int rand() {
thread_local generator my_generator { seed_with_entropy() };
return my_generator.rand();
} // erase
map.erase(2);
// iterate
for (auto &[k,v]: map) {
// do stuff
}
godbolt: https://godbolt.org/z/o8f6zhqxq Executions of atomic functions that are either defined to be lock-free
(33.5.10) or indicated as lock-free (33.5.5) are lock-free executions.
When one or more lock-free executions run concurrently, at least one should
complete.
[Note 3 : It is difficult for some implementations to provide absolute
guarantees to this effect, since repeated and particularly inopportune
interference from other threads could prevent forward progress, e.g., by
repeatedly stealing a cache line for unrelated purposes between load-locked
and store-conditional instructions. For implementations that follow this
recommendation and ensure that such effects cannot indefinitely delay progress
under expected operating conditions, such anomalies can therefore safely be
ignored by programmers. Outside this document, this property is sometimes
termed lock-free. — end note]
I'm guessing that note is for platforms like you mention, where the underlying ISA makes this (more or less) impossible. I would assume in the modern versions of these ISAs though, essentially everything in std::atomic is wait-free, in practice.[1] https://open-std.org/jtc1/sc22/wg21/docs/papers/2023/n4950.p...
Sort-of, but that's not quite right: if you imagine it as "taking a mutex on the memory", there's a possibility of starvation. Imagine two threads repeatedly "locking" the memory location to update it. With a mutex, it's possible that one of them get starved, never getting to update the location, stalling indefinitely.
At least x86 (and I'm sure ARM and RISC-V as well) make a much stronger progress guarantee than a mutex would: the operation is effectively wait-free. All threads are guaranteed to make progress in some finite amount of time, no one will be starved. At least, that's my understanding from reading much smarter people talking about the cache synchronization protocols of modern ISAs.
Given that, I think a better mental model is roughly something like the article describes: the operation might be slower under high contention, but not "blocking" slow, it is guaranteed to finish in a finite amount of time and atomically ("in one combined operation").
I agree though: biggest reason is probably the C API. Lua's is so simple to embed and to integrate with your code-base compared to Python. The language is also optimized for "quick compiling", and it's also very lightweight.
These days, however, one might argue that you gain so much from embedding either Python or JavaScript, it might be worth the extra pain on the C/C++ side.
It really is a very good point.
I personally approaches stashes as undoable "clean up", and I never have anything really important that I want to save there. If I do have something like that, I just commit with a "WIP <some-descriptive-string>" message and don't push it, then a "git reset --mixed HEAD^" when I want to get back to it.
However, just FYI: you can "grep" your stashes really easily if you want to. just "git stash list -p" gives you the diffs for all the stashes, by default in "less" where you can search them, but you can pipe it to grep if you want. I somewhat frequently do that with "git log", if I want to know "when did this variable change?" or whatever, just "git log -p" to get the log with diffs in less, then search for whatever it was with a slash.