LMM
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
Destide@feddit.uk to Programmer Humor@lemmy.mlEnglish · 2 days ago

Infallible Code

lemmy.ml

message-square
160
link
fedilink
446

Infallible Code

lemmy.ml

Destide@feddit.uk to Programmer Humor@lemmy.mlEnglish · 2 days ago
message-square
160
link
fedilink
alert-triangle
You must log in or # to comment.
  • I Cast Fist@programming.dev
    link
    fedilink
    arrow-up
    5
    ·
    12 hours ago

    Oh shit, gotta check the negative numbers as well!

    • Shayeta@feddit.org
      link
      fedilink
      English
      arrow-up
      1
      ·
      11 hours ago

      You can do that more efficiently by using abs(number).

  • Randomgal@lemmy.ca
    link
    fedilink
    arrow-up
    3
    ·
    11 hours ago

    Yeah but did you know he worked for Blizzard tho

  • JackbyDev@programming.dev
    link
    fedilink
    English
    arrow-up
    42
    ·
    1 day ago

    This is why this code is good. Opens MS paint. When I worked at Blizzard-

    • benjaminb@discuss.tchncs.de
      link
      fedilink
      English
      arrow-up
      8
      ·
      24 hours ago

      And he has Whatever+ years of experience in the game industry…

      • onlooker@lemmy.ml
        link
        fedilink
        arrow-up
        4
        ·
        22 hours ago

        Which sounds impressive until you realize a janitor who worked there for the same amount of time could claim the same.

  • Kuma@lemmy.world
    link
    fedilink
    arrow-up
    7
    arrow-down
    1
    ·
    22 hours ago

    I am more amazed that he didn’t stop at 10 and think “damn this is tiresome isn’t there a one liner i could do?”. I want to know how far he went. His stubbornness is amazing but also scary. I haven’t seen this kind of code since back in school lol lol lol

  • helvetpuli@sopuli.xyz
    link
    fedilink
    arrow-up
    2
    ·
    17 hours ago

    Oh. I thought that was Elixir until I zoomed in.

  • keepcarrot [she/her]@hexbear.net
    link
    fedilink
    English
    arrow-up
    4
    ·
    24 hours ago

    I want to assess coders by lines written! The more the better!

  • kreskin@lemmy.world
    link
    fedilink
    arrow-up
    9
    arrow-down
    1
    ·
    1 day ago

    no unit tests huh.

    /s

  • redxef@feddit.org
    link
    fedilink
    arrow-up
    36
    ·
    2 days ago
    def is_even(n: int) -> bool:
        if n < 0:
            return is_even(-n)
        r = True
        for _ in range(n):
            r = not r
        return r
    
    • OddMinus1@sh.itjust.works
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      16 hours ago

      Could also be done recursive, I guess?

      boolean isEven(int n) {
        if (n == 0) {
          return true;
        } else {
          return !isEven(Math.abs(n - 1));
        }
      }
      
      • ⛓️‍💥@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        1
        ·
        9 hours ago

        deleted by creator

    • dragonlobster@programming.dev
      link
      fedilink
      arrow-up
      2
      ·
      23 hours ago

      He loves me, he loves me not

    • vandsjov@feddit.dk
      link
      fedilink
      arrow-up
      1
      ·
      1 day ago

      No, no, I would convert the number to a string and just check the last char to see if it was even or not.

  • Treczoks@lemmy.world
    link
    fedilink
    arrow-up
    6
    ·
    1 day ago

    Good if you are rated by an AI that pays for LOCs.

  • myotheraccount@lemmy.world
    link
    fedilink
    arrow-up
    106
    ·
    2 days ago

    ftfy

    bool IsEven(int number) {
      return !IsOdd(number);
    }
    
    bool IsOdd(int number) {
      return !IsEven(number);
    }
    
    • balsoft@lemmy.ml
      link
      fedilink
      arrow-up
      15
      ·
      edit-2
      2 days ago

      You kid, but Idris2 documentation literally proposes almost this exact impl: https://idris2.readthedocs.io/en/latest/tutorial/typesfuns.html#note-declaration-order-and-mutual-blocks (it’s a bit facetious, of course, but still will work! the actual impl in the language is a lot more boring: https://github.com/idris-lang/Idris2/blob/main/libs/base/Data/Integral.idr)

      • myotheraccount@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        1 day ago

        I hadn’t seen Idris2. Thank you for providing me with a new rabbit hole!

        • balsoft@lemmy.ml
          link
          fedilink
          arrow-up
          3
          ·
          22 hours ago

          I’m glad to tell more people about it. It’s really quite amazing (I could write a somewhat complex algorithm and prove some properties about it in a couple afternoons, despite limited formal verification experience) and I’m sure that in 20 odd years the ideas behind it will make it into mainstream languages, just as with ML/Haskell.

  • Onno (VK6FLAB)@lemmy.radio
    link
    fedilink
    arrow-up
    150
    ·
    2 days ago

    Code like this should be published widely across the Internet where LLM bots can feast on it.

    • mkwt@lemmy.world
      link
      fedilink
      arrow-up
      24
      ·
      2 days ago

      The Daily WTF

  • sik0fewl@lemmy.ca
    link
    fedilink
    arrow-up
    11
    arrow-down
    1
    ·
    1 day ago

    This code would run a lot faster as a hash table look up.

    • PieMePlenty@lemmy.world
      link
      fedilink
      arrow-up
      6
      ·
      1 day ago

      I agree. Just need a table of even numbers. Oh and a table of odd numbers, of course, else you cant return the false… duh.

    • Valmond@lemmy.world
      link
      fedilink
      arrow-up
      5
      ·
      1 day ago

      In a Juliana tree, or a dictionary tree if you want. For speed.

  • Patches@ttrpg.network
    link
    fedilink
    arrow-up
    15
    ·
    2 days ago

    Y’all laugh but this man has amazing code coverage numbers.

  • Sibbo@sopuli.xyz
    link
    fedilink
    arrow-up
    90
    ·
    edit-2
    2 days ago
    else print("number not supported");
    
    • Destide@feddit.ukOP
      link
      fedilink
      English
      arrow-up
      8
      arrow-down
      1
      ·
      edit-2
      2 days ago

      As we’re posting examples I’ll add how lovely it is in Elixir. Elixir def not putting the fun in programmer memes do. One reason I picked it because I can’t be trusted to not be the meme.

      def is_even?(n) do
        rem(n, 2) == 0
      end
      
      • balsoft@lemmy.ml
        link
        fedilink
        arrow-up
        10
        ·
        edit-2
        2 days ago

        I mean, it would be almost this exact thing in almost any language.

        fn is_even(n: i64) -> bool {
            n % 2 == 0
        }
        
        even n = n `rem` 2 == 0
        
        def is_even(n):
            return n % 2 == 0
        

        etc

        • vinnymac@lemmy.world
          link
          fedilink
          arrow-up
          4
          ·
          2 days ago

          Personal preference, but elixir just strikes a balance that doesn’t make me feel like I’m reading hieroglyphs so I’m actually happy to see it praised.

          • fushuan [he/him]@piefed.blahaj.zone
            link
            fedilink
            English
            arrow-up
            4
            ·
            2 days ago

            I would have preferred for the function to be called mod, since it’s the modulo operation, which in math is represented with a percentage or “mod”. Most programming languages use a percentage because of that, so do a lot of calculators.

          • balsoft@lemmy.ml
            link
            fedilink
            arrow-up
            2
            ·
            2 days ago

            Yeah, I agree that Elixir is a fine language for some tasks. I personally find the readability somewhat average, but it’s very maintainable (due to how it enables clear program structure), the error handling is great, and the lightweight process system is amazing.

  • Clbull@lemmy.world
    link
    fedilink
    arrow-up
    20
    ·
    2 days ago

    This is YandereDev levels of bad.

    • lime!@feddit.nu
      link
      fedilink
      English
      arrow-up
      6
      ·
      1 day ago

      this is yanderedev.

      • Clbull@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        1 day ago

        Nah, this is yanderedev

        • lime!@feddit.nu
          link
          fedilink
          English
          arrow-up
          4
          ·
          1 day ago

          no the code is

Programmer Humor@lemmy.ml

programmerhumor@lemmy.ml

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: !programmerhumor@lemmy.ml

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
Visibility: Public
globe

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

  • 208 users / day
  • 1.53K users / week
  • 3.09K users / month
  • 7.25K users / 6 months
  • 1 local subscriber
  • 37.2K subscribers
  • 515 Posts
  • 2.57K Comments
  • Modlog
  • mods:
  • cat_programmer@lemmy.ml
  • BE: 0.19.12
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org