There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

programmer_humor

This magazine is from a federated server and may be incomplete. Browse more on the original instance.

Ephera , in 4 billion if statements

Now we just need to someone to package it and upload it to NPM.

Hotzilla , in 4 billion if statements

Could be easily made 50% space saving by only iffin all odds and return even on else. Maybe one if before to handle overflow to avoid wrong even if over the last if.

Deebster ,
@Deebster@programming.dev avatar

Well yeah, if you allow cheating!

bjorney ,

Yeah but then ALL even numbers would be slow to compute because you would have to chain through every odd before you know that 2 is even.

Depends on the expected distribution of input values

coloredgrayscale ,

Heuristic: keep it until 512, afterwards powers of 2, and numbers like 1000, 2000,…, 10000, 20000,… (regex: [0-9]000+)

ThrowawayPermanente , in 4 billion if statements

Let’s be real though, everything is IF statements all the way down

Th4tGuyII ,
@Th4tGuyII@kbin.social avatar

There's not a single thing in this universe that cannot be accomplished with enough IF statements... as long as you've got infinite time to wait

firecat ,

The problem with if is the answer comes from user. There’s no mathematical reason or scientific explanation, only programmer who thinks the answer should include the subject.

Th4tGuyII ,
@Th4tGuyII@kbin.social avatar

True...

But even on a more metaphorical level, every single thing that has or will happen in this universe, down to even the smallest quantum fluctuations could be encapsulated into IF statements as long as you had enough of them.

DarkGamer , in 4 billion if statements
@DarkGamer@kbin.social avatar

This is why every programmer needs to understand the modulo operator.

MxM111 ,

I would divide by two (floating point) and check the fractional part.

sus ,

turns out that 2^53 + 1 is an even number

iknowitwheniseeit ,

The article only covers unsigned 32-bit numbers, so floating point division would be fine.

onlinepersona , in 4 billion if statements

I honestly thought this was going to be about AI 😅

CC BY-NC-SA 4.0

MxM111 ,

No, this is about NS. Natural Stupidity.

Aatube , in 4 billion if statements
@Aatube@kbin.social avatar

@programming_horror , anyone? We have an in production version of this used in Wikipedia

isildun ,

Instance friendly link: !programming_horror

DrDeadCrash ,

Thank you!

Aatube ,
@Aatube@kbin.social avatar

I'm pretty sure that my link also works regardless of instance. It works when I visit it on your instance.

GreatBlueHeron , in 4 billion if statements

I’m not a good reader - I skim most articles and often miss most of the meaning. I read, and enjoyed, every word of that!

librecat ,
@librecat@lemmy.basedcount.com avatar

Thanks, I totally would’ve skipped it without this comment.

merc , in 4 billion if statements

I like this bit at the end:

As a side note, the program is amazingly performant. For small numbers the results are instantaneous and for the large number close to the 2^32 limit the result is still returned in around 10 seconds.

caellian ,

Really makes you question your sanity when optimizing jumps in code without benchmarks.

merc ,

For a long time I’ve been of the opinion that you should only ever optimize for the next sucker colleague who might need to read and edit your code. If you ever optimize for speed, it needs to be done with massive benchmarking / profiling support to ensure that the changes you make are worth it. This is especially true with modern compilers / interpreters that try to use clever techniques to optimize your code either on the fly, or before making the executable.

Klear ,

The first rule of optimization: Don’t do it
The second rule of optimization: Don’t do it yet (experts only)

Ephera ,

I’m absolutely on-board …in application code.

I do feel like it’s good, though, when libraries optimize. Ideally, they don’t have much else to do than one thing really well anyways.

And with how many libraries modern applications pull in, you do eventually notice whether you’re in the Python ecosystem, where most libraries don’t care, or in the Rust ecosystem, where many libraries definitely overdo it. Because well, they also kind of don’t overdo it, since as a user of the library, you don’t see any of it, except the culmulative performance benefits.

merc ,

Libraries are also written and maintained by humans.

It’s fine to optimize if you can truly justify it, but that’s going to be even harder in libraries that are going to be used on multiple different architectures, etc.

blusterydayve26 ,

I’m still mad he didn’t use the size of the number to tell the system which block to read first. I feel like that would be a great use for division or maybe modulus?

merc ,

I just like how he used “% 2” in the Python code he used to generate the C++ code.

httpjames , in no.. just no
@httpjames@sh.itjust.works avatar

Joins must be a pain in the ass with hooks

SaltyIceteaMaker , in no.. just no
@SaltyIceteaMaker@iusearchlinux.fyi avatar

got no clue abot sql. what is wrong and how is it supposed to look like?

Daxtron2 ,

this basically xml being made to look like SQL. It’s gross and that’s why it’s funny

ILikeBoobies ,

Different language

traches ,

SQL is run on the server to communicate with a database. The screenshot is jsx, which is a front-end, UI templating language. Writing SQL this way is cursed

schnurrito ,

SQL is supposed to look like this: SELECT status, name FROM some_table LIMIT 5

BoastfulDaedra , in no.. just no

I haven’t been this pissed off since LINQ started allowing syntax switches in random-ass places.

Zangoose OP , in Good luck web devs
QuazarOmega ,

Hmm yes, web dev horrors beyond my comprehension!

grue ,

That, right there, is a perfect example of why folks need to stop trying to shoehorn web apps everywhere they don’t belong. It’s a use-case for a proper native mobile app if ever there was one.

owsei ,

even if it’s just mobile

you already have to handle landscape/portrait mode

now imagine having to handle angled

grue ,

That’s why you should’ve just handled arbitrary rotations instead of inventing a finite predefined set of orientation “modes” in the first place.

Things get a lot easier in the long run if you aggressively look for commonalities and genericize the code that handles them instead of writing bunches of one-off special cases.

xmunk ,

And this is why my webapp only renders properly on circular displays.

flambonkscious ,

Peak evil - well done. How much is the extra fee to wrap a letterbox around the circle on a conventional aspect ratio?

There’s good money in this idea!

AVincentInSpace ,

Why does this low key feel like something I would actually want to use

syd , in Good luck web devs
@syd@lemy.lol avatar

I won’t try implement something like this even my boss forces me.

muzzle , (edited )

No one does this kind of stuff because someone asked them to do it. This is the kind of useless, insane stuff you do for the lulz, or because someone dared you.

lynx , in Good luck web devs

How can you do fractional rotation? Does it only work with x11 or is it also supported in wayland?

Chewy7324 ,

Rotating the display by a custom angle is possible through xrandr on X.org.

There’s no Wayland protocol for custom angle rotation, and I don’t expect anyone to create a protocol extension without a use-case.

My wild guess: Theoretically it should be possible for a compositor to support similar custom rotation, as applications simply draw to their surface (window), without knowing how and where it is displayed on the viewport (display).

But it might require quite a bit of work, depending on the project, so I don’t expect to ever see custom rotation on anything besides smaller/niche compositors.

[1] unix.stackexchange.com/…/rotate-a-display-by-cust…

nintendiator ,

There’s no Wayland protocol for custom angle rotation, and I don’t expect anyone to create a protocol extension without a use-case.

Puh-lease. It’s Wayland; the devs fully and honestly expect every app developer (eg.: calc, Libreoffice, notepad.exe) to implement custom angle rotation on their own.

Vilian ,

in wayland the compositor is king they can do mhatever they want with the screen

m.youtube.com/watch?v=ZBLLC5fOy98&list=PLb7YRKEhW…

schwim , in Good luck web devs
@schwim@reddthat.com avatar

This is why people can’t take desktop linux seriously.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines