You could do a lot worse. If the type of i was an object, you could overload the negation operation to have side-effects for the third snippet, for example.
- 0 Posts
- 17 Comments
I don’t know what I was thinking.
But, if you borrow C’s semantics, you are allowed to “optimize” away side-effect-less loops, even if they would never terminate. But that would require the random method to be pure.
I feel like an idiot. Also, in the “Good” example, no underflow occurs. i goes from 0 to -10, and x is assigned to -i every loop.
It might still be possible to optimize away the random number example, if the random function were made a magic language item, but it would not be even remotely close to being worth the effort.
ferric_carcinization@lemmy.mlto
Programmer Humor@lemmy.ml•More code = more betterEnglish
18·8 days agoThe compiler should be able to optimize all of them to the same machine code.
- This is already good.
- Easily optimized by constant folding.
This one depends on the semantics of signed underflow, so it may not do what you want.The loop can only exit ifx==10, so as long as thenextInt()method doesn’t have side effects, the loop should be eliminated. But, again, language semantics can affect this.
Edit: Very wrong for 3 & 4, see replies.
ferric_carcinization@lemmy.mlto
Linux@lemmy.ml•Debian, encrypted boot, how to increase password attempts?English
3·4 months agoI meant the following:
- Find out the Debian package is too old
- Create Arch Live USB
- Boot Arch Live USB
- Copy GRUB config from the Debian install to the current Arch live system
- Install the up-to-date GRUB while in the Arch environment
The bootloader installer package is distro dependent, the bootloader the package installs isn’t. You can boot Debian no matter if the GRUB is installed from Debian stable, Debian Sid, Arch, Fedora or even FreeBSD. Otherwise, dual booting wouldn’t work.
Like I said, I’ve done that before, though with SystemD Boot instead of GRUB, which was a bit simpler due to how the bootloader is configured.
emerge --ask cake ... [ebuild N ] dev-dotnet/cake-5.0.0 USE="-debug"Huh. Seems like Gentoo really has a cake recipe.
ferric_carcinization@lemmy.mlto
Linux@lemmy.ml•Debian, encrypted boot, how to increase password attempts?English
41·4 months agoAs it’s a bootloader, it should make almost no difference which distribution was used to install it. (I’m not sure if Debian patches their GRUB.) I just used Arch as an example, as it is famous for being up to date. And, no matter where it’s installed from, if you’ve made changes to GRUB’s configuration, you’ll have to copy it over to the live distribution to keep your changes.
Yes, Debian Sid might be more familiar for Debian users, but that’s it.
Edit: You said “get the grub debs from Debian sid”, but installing Sid packages on non-Sid systems isn’t something that you should do.
ferric_carcinization@lemmy.mlto
Linux@lemmy.ml•Debian, encrypted boot, how to increase password attempts?English
52·4 months agoBut bootloaders are distro/OS agnostic. Why wait for Debian, when you could, for example, boot an Arch live ISO to install a newer GRUB?
I don’t use GRUB, but have done the same thing with SystemD Boot before. As GRUB’s configuration system is a bit more complex, you might have to mount your main install to get the correct config file.
ferric_carcinization@lemmy.mlto
Linux@lemmy.ml•[SOLVED] how come yt-dlp on a terminal returns bash: yt-dlp: command not found even though I installed it with wget? debian 13English
5·4 months agoUnlike Windows, on Linux you need to run
./<command>instead of just<command>for executables in you current directory.
ferric_carcinization@lemmy.mlto
Linux@lemmy.ml•Thought I'd Died & Linux Was the MessengerEnglish
211·4 months agoLemmy is not GPLv2, but AGPLv3.
So, the game would have to be (A)GPLv3. (The licenses are fairly interoperable. IIRC you can use AGPL components in GPL software if you abide by the terms of the AGPL.)
Viral licenses are nice and all, but they’re not without their drawbacks. I caught GPL recently (the slightly rarer Affero v3 strain) and now no DNA testing companies want me as a customer. I can no longer write MIT or BSD licensed code. Whenever I open a project, a LICENSE file appears within ~15 minutes of contact. I hope to recover soon.
It’s JS, so about 5, I think.
Edit: Looks like TypeScript, but the same applies.
ferric_carcinization@lemmy.mlto
Programmer Humor@lemmy.ml•You can take it from my cold dead pincersEnglish
24·4 months agoLemmy is written in Rust.
I hope that the language’s
ints are at most 32 bits. For 8 bits it could even be written by hand & the source code for a 32 bit version would only take upavg_line_len * 4GiBspace for the source code of the function. But it might take a bit of time to compile a version that supports the full range of 64 or 128 bit ints.
ferric_carcinization@lemmy.mlto
Linux@lemmy.ml•Flathub has passed 3 billion downloadsEnglish
4·6 months agoThey’re on the feddit.uk instance, so it’s more likely that they’re British. Either their VPN prefers USA servers for some reason, or they’ve only done about 138 million downloads at most.
ferric_carcinization@lemmy.mlto
Programmer Humor@lemmy.ml•Why make it complicated?English
1·6 months agoWhat’s disgusting about it? The only thing I can think of is the implicit return, which felt a bit icky at first.
Also, as the if expression is an expression, you can call methods on it like so:
if 1 > 2 { 3 } else { 4 }.min(5)(the above is still an expression, so it could be used, for example, as part of a condition for another if)
Of course, you can write horrible code in any language, but the ability to use blocks where expressions are expected can be great sometimes.
ferric_carcinization@lemmy.mlto
Programmer Humor@lemmy.ml•Why make it complicated?English
2·6 months agoRust would allow you to
let ret = if some_condition { <a lot of expensive calculations> result_of_operations } else { <a lot of other different expensive calculations> result_of_other_operations };Now you don’t have to declare it inside the blocks.
If it were a magic lang item, you could treat the resulting value in a special way. Then, you could create an optimization pass for this situation: if a variable is assigned random in a loop and the loop can only be exited with a certain value, the compiler can coerce the magic rand value to it.