Programmer Humor

32484 readers
772 users here now

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

Rules:

founded 5 years ago
MODERATORS
1
 
 
2
 
 
3
 
 

https://en.wikipedia.org/wiki/Three_Dead_Trolls_in_a_Baggie

I gave up looking for the year this was actually written but it existed on mp3.com in 2001.

4
 
 
class BaseFunction {
  static #allowInstantiation = false;

  constructor(...args) {
    if (!BaseFunction.#allowInstantiation) {
      throw new Error(
        "Why are you trying to use 'new'? Classes are so 2015! Use our fancy 'run' method instead!"
      );
    }
    for (const [name, validator] of this.parameters()) {
      this[name] = validator(args.shift());
    }
  }

  parameters() {
    return [];
  }

  body() {
    return undefined;
  }

  static run(...args) {
    BaseFunction.#allowInstantiation = true;
    const instance = new this(...args);
    BaseFunction.#allowInstantiation = false;
    return instance.body();
  }
}

class Add extends BaseFunction {
  parameters() {
    return [
      ["a", (x) => Number(x)],
      ["b", (x) => Number(x)],
    ];
  }

  body() {
    return this.a + this.b;
  }
}

console.log(Add.run(5, 3)); // 8



5
 
 
6
 
 
7
 
 
8
 
 
9
78
Factory factory factory (factoryfactoryfactory.net)
10
 
 
11
 
 
12
 
 
13
 
 
14
 
 
15
 
 
16
 
 
17
 
 

18
 
 
19
 
 
20
 
 
21
 
 
22
 
 
23
 
 

Jim pondered aloud one morning to his wife, "Why do you always cut off the ends of sausages when you cook them?"

His wife replied, "I learned that from my mother. If you're interested, ask her yourself."

Intrigued, Jim sought out his mother-in-law and posed the same question: "Why do you always cut off the ends of sausages when cooking them?"

She responded, "I don't know, my mother taught me that. If you're curious, call her."

Determined to uncover the mystery, Jim dialed up and inquired: "This is Jimmy, your granddaughter (my wife) and your daughter (my mother-in-law) always cut off the ends when cooking sausages, saying that you taught them. What's the point?"

To this, she replied, "Are you still using my little saucepan to cook those sausages?"

24
 
 
25
 
 
view more: next ›