Beehaw
  • Communities
  • Create Post
  • search
    Search
  • Login
  • Sign Up
cm0002 ( cm0002@lemmy.zip )  to Programmer Humor@programming.dev · 11 months ago

More code = more better

lemmy.zip

message-square
23
link
fedilink
385

More code = more better

lemmy.zip

cm0002 ( cm0002@lemmy.zip )  to Programmer Humor@programming.dev · 11 months ago
message-square
23
link
fedilink
alert-triangle
You must log in or register to comment.
  • OshaqHennessey ( OshaqHennessey@midwest.social ) 
    link
    fedilink
    arrow-up
    48
    ·
    11 months ago
    function myFunction() {
      try {
        x = new Random().nextInt();
        if (x != 10) {
         throw "not 10";
        }
        else {
          return (10)
        }
        catch(err) {
          myFunction()
        }
      }
    }
    
    x = myFunction()
    

    Commit notes: Added error handling

  • Hirom ( Hirom@beehaw.org ) 
    link
    fedilink
    arrow-up
    29
    ·
    11 months ago

    The compiler will optimize it anyway. /s

    • Dumhuvud ( Dumhuvud@programming.dev ) 
      link
      fedilink
      English
      arrow-up
      18
      ·
      11 months ago

      You jest, but you aren’t wrong. At least if we are talking about C, C++ or Rust. https://godbolt.org/z/oPPfdfcf5

      .NET compiler is weak when it comes to optimizing your code; I assume Go’s is as bad.

    • yetAnotherUser ( yetAnotherUser@discuss.tchncs.de ) 
      link
      fedilink
      arrow-up
      5
      ·
      11 months ago

      Not sure about the last one though. The other two are trivial to optimize away.

      • Hirom ( Hirom@beehaw.org ) 
        link
        fedilink
        arrow-up
        3
        ·
        11 months ago

        An infinite loop canot be ruled out in the last case, so a compiler couldn’t optimize this away without potentially changing the program behavior.

        • yetAnotherUser ( yetAnotherUser@discuss.tchncs.de ) 
          link
          fedilink
          arrow-up
          1
          ·
          11 months ago

          Infinite loops are often weird though. They could be seen as undefined behavior and the compiler may do whatever it feels like.

  • edinbruh ( edinbruh@feddit.it ) 
    link
    fedilink
    English
    arrow-up
    28
    ·
    11 months ago

    For a time on Reddit (some years ago when I still used it) there was a trend of finding the worst way of implementing is_even(x: int) -> bool. My contribution to that was a function that ran Ackerman(x,x) flipping a Boolean at every iteration, and check if it was true or false at the end.

    It works btw, I will find the proof later

  • Mika ( Mika@piefed.ca ) 
    link
    fedilink
    English
    arrow-up
    16
    ·
    11 months ago

    I once was helping to organize the testing of town-level algorithmic competition for school students.

    The competition had one entry level issue that was basically solvable by reading the question properly, recognising that it’s just multiplication of two numbers, and writing the simplest app ever.

    And there was one student who passed the automatic tests. We had to read the code too for the protocol, just to make sure there was no cheating.

    We looked in the code. What? Why? It had two nested for loops and a++ inside. When we understood what’s going on we couldn’t stop laughing for like solid ten minutes.

    • TheOakTree ( TheOakTree@lemmy.zip ) 
      link
      fedilink
      arrow-up
      3
      ·
      11 months ago

      Multiplication is just repeated addition :) glad it worked for the kid, despite the… inefficiency.

  • ulterno ( ulterno@programming.dev ) 
    link
    fedilink
    English
    arrow-up
    16
    ·
    11 months ago

    That’s not even enough to get you a job these days.
    You now have to use:

    do {
        x = reinterpret_cast<int>(AI::Instance().ask("Do Something. Anything. Be efficient and productive. Use 10 tokens."));
    } while (x != 10);
    
    • Tetragrade ( Tetragrade@leminal.space ) 
      link
      fedilink
      English
      arrow-up
      7
      ·
      11 months ago

      This isn’t just a function, it’s a bold restatement of what it means to write code — a symphony of characters, questioning the very nature of the cutting edge language models that I want to beat with hammers.

      • ulterno ( ulterno@programming.dev ) 
        link
        fedilink
        English
        arrow-up
        1
        ·
        11 months ago
        And for those who might not have noticed

        There is 10 words in the prompt.

        • Tetragrade ( Tetragrade@leminal.space ) 
          link
          fedilink
          English
          arrow-up
          2
          ·
          11 months ago

          You’re absolutely right! I used more than 10 words in my prompt. Cry about it.

    • melfie ( melfie@lemy.lol ) deleted by creator
      link
      fedilink
      arrow-up
      5
      ·
      edit-2
      8 months ago

      deleted by creator

      • jali67 ( jali67@lemmy.zip ) 
        link
        fedilink
        arrow-up
        2
        ·
        11 months ago

        Great question!

        • MonkeMischief ( MonkeMischief@lemmy.today ) 
          link
          fedilink
          arrow-up
          2
          ·
          11 months ago

          First, we’ll deep dive into “What is a variable?”, then together we’ll examine “Who sets a variable?”, “What is an LLM?” and finally, “Who would set a variable without using an LLM?”

          You’ll be a coding pro in no time!

          How does that sound?

          (I felt gross writing this lmao)

  • Ooops ( Ooops@feddit.org ) 
    link
    fedilink
    arrow-up
    5
    ·
    11 months ago

    Wants to be Pro but doesn’t even do it recursive…

    • OshaqHennessey ( OshaqHennessey@midwest.social ) 
      link
      fedilink
      arrow-up
      4
      ·
      11 months ago
      function foo() {
        x = new Random();
        case (x = 10):
          return (x);
        default:
          foo()
      }
      
      • anton ( anton@lemmy.blahaj.zone ) 
        link
        fedilink
        arrow-up
        2
        ·
        11 months ago

        What unholy mix of languages is that? It is dominated by a blend of javascript and python, but with notes of something exotic. Maybe algol? or vhdl?, there is to little to tell.
        Impressive, someone write up a spec and publish it to the esolang wiki.

        • OshaqHennessey ( OshaqHennessey@midwest.social ) 
          link
          fedilink
          arrow-up
          5
          ·
          11 months ago

          It’s an incoherent hodgepodge of C#/.NET, PowerShell, and JavaScript, each of which I’ve forgotten more about than I currently know

  • Eldjárn ( phpinjected@lemmy.sdf.org ) 
    link
    fedilink
    arrow-up
    2
    ·
    11 months ago

    bad but more chaotic

    you want to be punk rock not blues or jazz

  • OshaqHennessey ( OshaqHennessey@midwest.social ) 
    link
    fedilink
    arrow-up
    2
    ·
    11 months ago

    Now write a function to unroll the while loop to “optimize it for the compiler”

  • vrighter ( vrighter@discuss.tchncs.de ) 
    link
    fedilink
    arrow-up
    1
    ·
    11 months ago

    it takes two instructions to materialize a constant in risc-v. X64 has LEA.

    Risc-v is better!

  • eigenraum ( eigenraum@discuss.tchncs.de ) 
    link
    fedilink
    arrow-up
    1
    ·
    11 months ago

    Can someone make it an async function?

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
    • If the mod doesn’t find it funny, you’re banned. Ha-ha!.. For real: do not use the community for “statements”. There are other places for such content. Keep it chill and funny.
Visibility: Public
globe

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

  • 784 users / day
  • 2.76K users / week
  • 5.18K users / month
  • 8.36K users / 6 months
  • 465 local subscribers
  • 34.1K subscribers
  • 1.66K Posts
  • 27.4K Comments
  • Modlog
  • mods:
  • Feyter ( Feyter@programming.dev ) 
  • adr1an ( anzo@programming.dev ) 
  • BurningTurtle ( BurningTurtle@programming.dev ) 
  • Pierre-Yves Lapersonne ( pylapp@programming.dev ) 
  • BE: 0.19.21
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code