tucson.social
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
SavvyWolf@pawb.social to Programmer Humor@programming.devEnglish · 1 year ago

4 billion if statements

andreasjhkarlsson.github.io

external-link
message-square
29
link
fedilink
315
external-link

4 billion if statements

andreasjhkarlsson.github.io

SavvyWolf@pawb.social to Programmer Humor@programming.devEnglish · 1 year ago
message-square
29
link
fedilink
I recently stumbled upon this screenshot while researching social media on the train. Of course, it was followed by a cascade of spiteful comments, criticizing this fresh programmer’s attempt to solve a classical problem in computer science. The modulus operation.
alert-triangle
You must log in or register to comment.
  • Ephera@lemmy.ml
    link
    fedilink
    arrow-up
    50
    ·
    1 year ago

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

    • ArtVandelay@lemmy.world
      link
      fedilink
      English
      arrow-up
      6
      ·
      edit-2
      1 year ago

      What’s another 40 gb of node_modules anyway

  • Hotzilla@sopuli.xyz
    link
    fedilink
    arrow-up
    34
    arrow-down
    1
    ·
    1 year ago

    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@programming.dev
      link
      fedilink
      arrow-up
      35
      ·
      1 year ago

      Well yeah, if you allow cheating!

    • bjorney@lemmy.ca
      link
      fedilink
      arrow-up
      15
      ·
      edit-2
      1 year ago

      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@programming.dev
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

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

  • case_when@feddit.uk
    link
    fedilink
    English
    arrow-up
    31
    ·
    1 year ago

    This is poetry.

    My favourite part is that he uses the modulo operator in his Python script to generate the C code.

  • Aatube@kbin.social
    link
    fedilink
    arrow-up
    12
    ·
    edit-2
    1 year ago

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

  • NovaPrime@lemmy.ml
    link
    fedilink
    arrow-up
    10
    ·
    1 year ago

    Andreas is a maniac

  • Great Blue Heron@lemmy.ca
    link
    fedilink
    arrow-up
    11
    arrow-down
    1
    ·
    1 year ago

    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@lemmy.basedcount.com
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

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

  • themusicman@lemmy.world
    link
    fedilink
    arrow-up
    15
    arrow-down
    7
    ·
    1 year ago

    It’s not a trade off between dev time, execution time and memory as the author claims. It’s materially worse for all 3

    • pflanzenregal@lemmy.world
      link
      fedilink
      arrow-up
      18
      ·
      edit-2
      1 year ago

      I think he was being sarcastic, playing with words. Meaning, that you trade in time, runtime and memory and get nothing in return :D so a pretty bad trade haha.

      Of course it’s worse, I mean, that was the point of this blogpost, wasn’t it? :p It’s just a (long) joke.

      • themusicman@lemmy.world
        link
        fedilink
        arrow-up
        6
        ·
        1 year ago

        On reread, you’re totally right. Went right over my head

  • mexicancartel@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    7
    ·
    1 year ago

    Well i hate this:

    PS > .\program.exe 0

    THIS:

    .\

  • Clbull@lemmy.world
    link
    fedilink
    arrow-up
    6
    ·
    1 year ago

    This is peak YandereDev.

  • BastingChemina@slrpnk.net
    link
    fedilink
    arrow-up
    4
    ·
    1 year ago

    I’ve lost some of my sanity reading this !

  • dylanTheDeveloper@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    1 year ago

    It works don’t it

  • DarkGamer@kbin.social
    link
    fedilink
    arrow-up
    4
    arrow-down
    2
    ·
    1 year ago

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

    • jaybone@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      1 year ago

      Or bitwise AND.

      • Reptorian@programming.dev
        link
        fedilink
        arrow-up
        2
        ·
        1 year ago

        This is what I prefer too! I also some times prefer to use bitshift when it comes to division or multiplication of power of 2.

    • MxM111@kbin.social
      link
      fedilink
      arrow-up
      2
      arrow-down
      1
      ·
      1 year ago

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

      • sus@programming.dev
        link
        fedilink
        arrow-up
        6
        ·
        1 year ago

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

        • iknowitwheniseeit@lemmynsfw.com
          link
          fedilink
          arrow-up
          2
          ·
          1 year ago

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

  • frezik@midwest.social
    link
    fedilink
    arrow-up
    3
    arrow-down
    1
    ·
    1 year ago

    Those are rookie numbers. Professionals came up with the nested logic monstrosity that is the JSON-LD specification:

    https://www.w3.org/TR/json-ld11-api/#context-processing-algorithm

    Looks through the algorithm bits in the various sections. How would you implement that? The answer is invariably by copying the highly nested statements of the spec directly into your language. Maybe there’s a better way, but you’d have to understand all that nested logic first, and you’d be exhausted at that point and just want to move on.

  • Hector_McG@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    I first saw this joke back in the days of 8-bit home microcomputers. Of course then it only needed 256 lines of code, and took up about 8k of your precious, precious RAM.

  • onlinepersona@programming.dev
    link
    fedilink
    English
    arrow-up
    6
    arrow-down
    6
    ·
    1 year ago

    I honestly thought this was going to be about AI 😅

    CC BY-NC-SA 4.0

    • MxM111@kbin.social
      link
      fedilink
      arrow-up
      3
      ·
      1 year ago

      No, this is about NS. Natural Stupidity.

    • qwertychomp@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      Wait, what’s with the creative commons license? Are you licensing your comments?

Programmer Humor@programming.dev

programmer_humor@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmer_humor@programming.dev

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 629 users / day
  • 3.92K users / week
  • 9.69K users / month
  • 19K users / 6 months
  • 1 local subscriber
  • 24.4K subscribers
  • 1.5K Posts
  • 49.3K Comments
  • Modlog
  • mods:
  • Feyter@programming.dev
  • adr1an@programming.dev
  • BurningTurtle@programming.dev
  • Pierre-Yves Lapersonne@programming.dev
  • BE: 0.19.11
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org