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

Infallible Code

lemmy.ml

message-square
39
link
fedilink
7

Infallible Code

lemmy.ml

Destide@feddit.uk to Programmer Humor@lemmy.mlEnglish · 2 months ago
message-square
39
link
fedilink
alert-triangle
You must log in or register to comment.
  • myotheraccount@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    2 months ago

    ftfy

    bool IsEven(int number) {
      return !IsOdd(number);
    }
    
    bool IsOdd(int number) {
      return !IsEven(number);
    }
    
    • balsoft@lemmy.ml
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      2 months 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
        1
        ·
        2 months ago

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

  • JackbyDev@programming.dev
    link
    fedilink
    English
    arrow-up
    3
    ·
    2 months ago

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

  • QuazarOmega@lemy.lol
    link
    fedilink
    arrow-up
    2
    ·
    2 months ago

    No, no, you should group the return false lines together 😤😤

    if (number == 1) return false;
    else if (number == 3) return false;
    else if (number == 5) return false;
    //...
    else if (number == 2) return true;
    else if (number == 4) return true;
    //...
    
  • huf [he/him]@hexbear.net
    link
    fedilink
    English
    arrow-up
    2
    ·
    2 months ago

    pff, i aint reading all that, lemme optimize it:

    private bool isEven(int number) {
        return rand() < 0.5;
    }
    
  • ZILtoid1991@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    2 months ago

    YanDev: “Thank God I’m no longer the most hated indie dev!”

    • ImplyingImplications@lemmy.ca
      link
      fedilink
      arrow-up
      2
      arrow-down
      1
      ·
      2 months ago

      YanDev is a literal pedophile. It’s honestly mind boggling people care more about a guy who won’t sign a petition on preserving video games than pedophiles and bigots. I don’t get the hate.

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

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

  • TomMasz@piefed.social
    link
    fedilink
    English
    arrow-up
    1
    ·
    2 months ago

    A decent compiler will optimize this into return maybe;

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

    This is YandereDev levels of bad.

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

      this is yanderedev.

  • Sibbo@sopuli.xyz
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    2 months ago
    else print("number not supported");
    
  • Patches@ttrpg.network
    link
    fedilink
    arrow-up
    1
    ·
    2 months ago

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

  • FunkyStuff [he/him]@hexbear.net
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    2 months ago

    Throwback to when someone shared the OG version of this meme to my uni chat, I replied with "Oh you can simply do

    def is_even(n: int) -> boolean:
        if n > 0 return not is_even(n - 1)
        elif n < 0 return not is_even(n + 1)
        else return True
    

    And instead of laughing at the joke the TA in the chat said “When you start getting internships you’ll do n % 2” like I was being serious.

  • segfault11 [any]@hexbear.net
    link
    fedilink
    English
    arrow-up
    1
    ·
    2 months ago

    pro hacker tip: you can optimize this by using “num” for the variable name instead of “number”

    • Patches@ttrpg.network
      link
      fedilink
      arrow-up
      1
      ·
      2 months ago

      I prefer the cryptic each variable gets a single letter of the alphabet.

  • AlyxMS [he/him]@hexbear.net
    link
    fedilink
    English
    arrow-up
    1
    ·
    2 months ago

    What you do is use a for loop to generate a million lines for you, then paste it in. Writing it manually is moronic. You can easily make it support numbers above 1,000,000 too this way, talking about scalable

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

      No, silly. You ask chatgpt to write (steal) a loop that would generate all those lines. Haven’t you heard about meta-vibe template-programming?

      • AlyxMS [he/him]@hexbear.net
        link
        fedilink
        English
        arrow-up
        0
        ·
        2 months ago

        I once saw someone unironically sharing their new trick of “if you need to write a bunch of really similar lines just with different numbers, chatGPT does it really well”.

        Kind of blew my mind (and everyone else that saw the thread)

  • Packet [none/use name]@hexbear.net
    link
    fedilink
    arrow-up
    1
    ·
    2 months ago

    The end user yearns for their machine to be utilized fully, so instead of that, you can import full deepseek model to do the task

  • Euphoma@lemmy.ml
    link
    fedilink
    English
    arrow-up
    1
    ·
    2 months 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

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.

  • 107 users / day
  • 731 users / week
  • 3.67K users / month
  • 3.93K users / 6 months
  • 2 local subscribers
  • 38K subscribers
  • 1.3K Posts
  • 14.9K Comments
  • Modlog
  • mods:
  • AgreeableLandscape@lemmy.ml
  • cat_programmer@lemmy.ml
  • UI: unknown version
  • BE: 0.19.11
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org