8,399 karma · joined September 4, 2016
It’s not going to happen, but the only solution is to just stop developing it.
for (const auto &thing: collection) {
counts[thing]++;
}
Works nicely, you don't have to check if it's already there before ++ing it. As long as you know that's what operator[] does, it comes in handy more than I would've expected. for (const auto item: vec) { ... }
`item` is not a compile-time constant. It's different every run of the loop. const int x = f(); // this is always get evaluated at compile time, (or if it can't, then fail to compile)
That's very silly. You're saying this should fail to compile? void foo(int x) {
const int y = bar(x);
}
There's no way the compiler can run that, because it doesn't know what x is (indeed, it would have a different value every time you run the function with a new argument). So your proposal would ditch const completely except in the constexpr case, everything runtime would have to be mutable.So you respond "well, I didn't mean THAT kind of const, you should have a different word for compile-time constants and run-time non-mutability!" Congratulations, you just invented constexpr.
There are many bad things about C++, but constexpr ain't one of them.
I agree, they should have made it a language/syntax feature. However: if you wanna do a sum type, it does do that. I'd rather have that than nothing.
Fair enough, I haven't looked into spaced repetition deeply.
I just always got this weird vibe from people talking about it, like they think memorizing all the world capitals was a way to improve your intelligence. It's not.
Same thing with, like, "memory palace" stuff: being able to memorize a deck of cards is probably fun, and it's a nice parlor trick, but it will not help you solve real-world problems, analyze situations, make discoveries or be a better engineer. The way to do that is to just read books, study, work hard in your chosen field and keep up with the latest developments. That is the only way anyone has ever gotten good at anything.
Spaced repetition always seemed like those schemes to get you fit or slim in 30 days that never work. There is exactly one way to get physically healthy, and it's super-unfun: diet and exercise. Same thing with your mind, you have to exercise it and feed it appropriately for months and years. Spend the time you would spend on spaced repetition reading books or watching lectures and doing exercises instead.
Returning a copy isn't great (memory allocation!), the API should probably be something like:
int getenv(const char *varName, char *buf, size_t bufSize, size_t *varSize);
Where the caller manages the buffer and getenv writes into it (so it can e.g. be stack or statically allocated), the third argument is the size of the caller-managed buffer, then the last variable is an "out parameter" that returns the "true" length of the environment variable. Then afterwards, you can check if `*varSize > bufSize`, and if so, you need to make your buffer larger. The return value is an error code.Doing it like this, you can easily implement the "return a malloced copy" if you want to, but it also gives you the option to avoid allocation entirely. This is important for e.g. embedded or real-time applications, or anything that just likes to avoid `malloc()/free()`.
std::this_thread::sleep_for(10ms); // sleep for 10 milliseconds
std::this_thread::sleep_for(1s); // sleep for one second
std::this_thread::sleep_for(50); // does not work, unit is required by type system
That's such a cool way to do it: instead of forcing you to specify the exact unit in the signature (milliseconds or seconds), you just say that it's a time duration of some kind, and let the user of the API pick the unit. Very neat!Like, the parts of Tintin that capture the imagination, the world travel, the realistic depiction of different cultures, the great adventure stories, all of that starts with Blue Lotus.
When people criticize Tintin for being racist, what they're really criticizing are those early stories. In the later stories, the ones that everyone falls in love with, Hergé went to enormous trouble to depict cultures accurately, gathering huge amounts of references to depict everything accurately (you see that in this article, with the image from Blue Lotus). In these stories, almost without exception, Tintin is the champion of colonized and oppressed peoples, and the stories hold up extremely well.
The first story (Tintin in the Land of the Soviets, a real stinker, this is before Tintin became Tintin) was published in 1930, in Le Petit Vingtième which was the children's edition of the newspaper Le Vingtième Siècle. The newspaper presumably had copyright to the character, but it was shut down in 1940 by the Nazis. After that, Tintin was published in Le Soir (still exists), but I have no idea how the rights transferred. From 1950 onwards, it was published by Hergé's own company.
And you can tell if someone has potential. Like, a good manager needs to be a good communicator, well-organized and a good leader. These are skills you can notice if a person has before promoting them. Similarly going further up the hierarchy.
I don't think it's unavoidable at all, this is exactly the kind of problems CRDTs solve beautifully. If you model your chatting as a CRDT (basically, each message has a Lamport timestamp on it, and you have some sensible way to resolve ties deterministically), then assuming all peers have gotten all messages, the ordering should be perfectly consistent. What may happen is that you type a message, press "enter", and then some message might pop up before that when everyone finally sync, but I think that is acceptible UX, I see version of this in things like Slack and Discord frequently.
All peers having the same message order assuming they all have received the same messages is absolutely required for a chat application in 2024, distributed or not.
Just find some name that conjures some pretty image like ”GNU Constellation” or whatever and be done with it.
One interesting thing: the sieve array does not have static bounds, the size of it is an argument. Presumably that means it’s stack-allocated dynamically a la ”alloca” (I doubt it’s heap-allocated, given there’s no freeing of it). C didn’t get that feature until C99 and adding it has been almost universally been seen as a mistake.
I imagine that’s an example of one of the many, many things that makes Algol-68 a pain to implement. Does make it easier for the developer though.
But you can do that so easily as well! Like, take this YAML (substitute equivalent JSON or TOML, specific configuration language is irrelevant):
options:
someOption: 14
nested:
foo: "some string"
bar: true
I don't see how that's so much easier than this version in Lua: options = {
someOption = 14,
nested = {
foo = "some string",
bar = true
}
}
And when you do need to get a bit more complex, you have the the tools to manage that complexity. Like, if you have a bunch of very similar things (say, job definitions in CI/CD), you want a way to not repeat yourself so you only have to edit that once, YAML has a tool for that, "anchors" [1]. But it's obscure and a bit hard to use. In a real programming language, it's trivial: just stick the repetitive parts in a variable and use that. Or define a simple function in case most of the stuff is repeated, but some is not, so you can do foo = generateRepetativeConfig('specificOption')
Or maybe you can just do that with a simple for-loop. And if you want to do something like a string substitution, you have a whole dang language with the tools you need to do it.Dhall and languages like that are a big improvement, but really, I just want a normal programming language. We have decades of experience now with managing complexity in computer systems, and programming languages have evolved robust systems for handling that.
I agree that sandboxing and security can be a real concern for some of this stuff, in which case Starlark is perfect, though you can sandbox languages like Lua or various Lisps as well.
[1]: https://support.atlassian.com/bitbucket-cloud/docs/yaml-anch...