Funny Pieces of Codes Make Weekend Happier

13/Mar/2022 · 4 minute read

Sunny weekends make me cheerful always, and there are also some funny pieces of codes make it greater. Hope the following codes make you smile, too.

Although I hardly use Ruby programming language for a long time, I still remember a piece of code from Sidekiq, which is a asynchronous jobs framework for Ruby:

# https://github.com/mperham/sidekiq/blob/5ebd857e3020d55f5c701037c2d7bedf9a18e897/lib/sidekiq.rb#L51-L53
module Sidekiq
  # ...
  def self.❨╯°□°❩╯︵┻━┻
    puts "Calm down, yo."
  end
  ...
end

Aha! It is a unused method of which the name is a emoticon, and seems that the author of the code is annoying while he or she was writing it. However, there is also a corresponding and serious unit test for it:

describe "❨╯°□°❩╯︵┻━┻" do
  before { $stdout = StringIO.new }
  after  { $stdout = STDOUT }

  it "allows angry developers to express their emotional constitution and remedies it" do
    Sidekiq.❨╯°□°❩╯︵┻━┻
    assert_equal "Calm down, yo.\n", $stdout.string
  end
end

According some online discussion, I finally aware that the reason why the code is present is that the author was expecting to ensure that the code works normally with UTF-8 encoding.

Beyond this funny example from Sidekiq, I searched some other examples by the way, they all make people laugh out loud.

Time for funny codes

Exception up = new Exception("Something is really wrong.");
throw up;  //ha ha

What the hell does this guy lack of compassion? Why does he or she is able to smile after the program encountered something incorrect? Alright, I can only appreciate his optimism.

//When I wrote this, only God and I understood what I was doing
//Now, God only knows

Aha, it is a truth could not be more real. Not only the author of the code has this kind of trouble, but do I.

// drunk, fix later

What a conscientious programmer! How dangerous drunk coding is! Maybe it deserve considering punching somebody write codes after drinking.

#define TRUE FALSE

Oh no! I hardly imagine what will happen once this line of code has been merged and deployed. How terrible if your world is reversed, you are wrong if you think you are right, and you are right if you think you are wrong. Stop it please, I get goose bumps all over now!

return 1; # returns 1

What a nonsense comment! But it is understandable if your boss pays you for the number of characters in your code.

Catch (Exception e) {
  //who cares?
}

Alright, you are so proud. ╭(╯^╰)╮

I am not able to assert all people who care, but I can tell that your boss absolutely cares.

// I am not responsible of this code.

o(╯□╰)o Ok, but why you wanna left a footmark?

// it was hard to write
// so it should be hard to read

It looks like a impregnable argument. Who wanna challenge?

// I have to find a better job

Wait, if you really find a better job, could you take me with you? (^▽^)

// If this code works, it was written by Paul DiLascia. If not, I don't know
// who wrote it

I only write excellent codes, and ugly codes are all out of thin air.

# Linux Sex
$ date ; unzip ; strip ; touch ; grep ; finger ; mount ; fsck ; more ; yes ; umount ; sleep

Em… I don’t know it is, I am still a child and hiding my eyes from it.

long long ago; /* in a galaxy far far away */

Are you telling a story?

/**
 * Always returns true.
 */
public boolean isAvailable() {
    return false;
}

How dare you lie?! But which part is really wrong? The comment, or the function body?

//
// Dear maintainer:
//
// Once you are done trying to 'optimize' this routine,
// and have realized what a terrible mistake that was,
// please increment the following counter as a warning
// to the next guy:
//
// total_hours_wasted_here = 42
//

It was clear that here is a victims alliance.

return true; //true my ass! this doesn't work

How shall I put it? Fairy tales are lying.

For more funny codes

The above funny codes are all included in these articles, just click the links if you feel unsatisfied.

  1. Fuzzzy blog: 40 most funny code comments ever
  2. What are some of the funniest comments in source code?