unreachable.cloud
  • 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
159
fedilink
444

Infallible Code

lemmy.ml

Destide@feddit.uk to Programmer Humor@lemmy.mlEnglish · 2 days ago
message-square
159
fedilink
alert-triangle
You must log in or register to comment.
  • Randomgal@lemmy.ca
    link
    fedilink
    arrow-up
    3
    ·
    4 hours ago

    Yeah but did you know he worked for Blizzard tho

  • I Cast Fist@programming.dev
    link
    fedilink
    arrow-up
    5
    ·
    4 hours ago

    Oh shit, gotta check the negative numbers as well!

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

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

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

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

  • Kuma@lemmy.world
    link
    fedilink
    arrow-up
    7
    arrow-down
    1
    ·
    14 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

  • JackbyDev@programming.dev
    link
    fedilink
    English
    arrow-up
    41
    ·
    21 hours 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
      ·
      16 hours ago

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

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

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

  • keepcarrot [she/her]@hexbear.net
    link
    fedilink
    English
    arrow-up
    4
    ·
    16 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
    ·
    21 hours ago

    no unit tests huh.

    /s

  • WraithGear@lemmy.world
    link
    fedilink
    English
    arrow-up
    2
    arrow-down
    1
    ·
    edit-2
    14 hours ago

    Would this be a case of modulo saving the day?

    Like: If Number modulo 2 = 0, true

    This has to be taken out of context

    • queueBenSis@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      3
      ·
      9 hours ago

      well that’s the joke, isn’t it

      • WraithGear@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        arrow-down
        1
        ·
        9 hours ago

        I mean, is it a joke? Because i have no context other than, after making a bad opinion known, there is a lot of talk about his code being terrible. So i guess this is fabricated then yea?

        • queueBenSis@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          2
          ·
          5 hours ago

          oh. is it assumed we know who the person is? i have no idea who that is.

          • WraithGear@lemmy.world
            link
            fedilink
            English
            arrow-up
            1
            ·
            5 hours ago

            He’s Thor, worked for blizzard entertainment, indie dev, has a Ferret sanctuary, knows cyber security. Seems like a cool enough guy i guess, has incorrect opinion on video game preservation.

  • Treczoks@lemmy.world
    link
    fedilink
    arrow-up
    6
    ·
    20 hours ago

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

  • redxef@feddit.org
    link
    fedilink
    arrow-up
    34
    ·
    1 day 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
      9 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
        ·
        2 hours ago

        deleted by creator

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

      He loves me, he loves me not

    • vandsjov@feddit.dk
      link
      fedilink
      arrow-up
      1
      ·
      21 hours 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.

  • 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
      ·
      21 hours 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
      ·
      21 hours ago

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

  • Patches@ttrpg.network
    link
    fedilink
    arrow-up
    15
    ·
    1 day ago

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

  • Clbull@lemmy.world
    link
    fedilink
    arrow-up
    20
    ·
    1 day 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
          ·
          21 hours ago

          no the code is

  • myotheraccount@lemmy.world
    link
    fedilink
    arrow-up
    105
    ·
    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
        ·
        18 hours ago

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

        • balsoft@lemmy.ml
          link
          fedilink
          arrow-up
          3
          ·
          15 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.

  • Euphoma@lemmy.ml
    link
    fedilink
    English
    arrow-up
    24
    ·
    1 day ago
    def even(n: int) -> bool:
        code = ""
        for i in range(0, n+1, 2):
            code += f"if {n} == {i}:\n out = True\n"
            j = i+1
            code += f"if {n} == {j}:\n out = False\n"
        local_vars = {}
        exec(code, {}, local_vars)
        return local_vars["out"]
    

    scalable version

    • xthexder@l.sw0.com
      link
      fedilink
      arrow-up
      6
      ·
      1 day ago

      Not even else if? Damn, I guess we’re checking all the numbers every time then. This is what peak performance looks like

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

        O(1) means worst and best case performance are the same.

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: [email protected]

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.

  • 347 users / day
  • 1.56K users / week
  • 3.14K users / month
  • 9.76K users / 6 months
  • 1 local subscriber
  • 37.2K subscribers
  • 1.56K Posts
  • 26.7K Comments
  • Modlog
  • mods:
  • AgreeableLandscape@lemmy.ml
  • cat_programmer@lemmy.ml
  • BE: 0.19.5
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org