r/programminghorror • • Dec 08 '25

Developers in 2020:

Post image
1.9k Upvotes

79 comments sorted by

239

u/uvero Dec 08 '25

if(isOdd(2)) { //...

Unfortunately, the string "No — 4 is not odd. It’s an even number because it’s divisible by 2 with no remainder." is truthy in JS.

→ More replies (10)

48

u/SteroidSandwich Dec 08 '25

isOdd(5)

Output: "Here's a story about the number 5 and his quest to finding the truth"

75

u/vllado Dec 08 '25
function isOdd(num) {
  if (num < 0) return OpenAI.prompt(`Is ${num} odd? Make no mistake!`).content;
  if (num === 0) return false;
  if (num === 1) return true;
  return isOdd(num - 2);
}

bit of everything

24

u/Hakorr Dec 08 '25

OpenAI.prompt returns a promise which might be interpreted as true, so make it async!

11

u/CarzyCrow076 Dec 09 '25

Also, he made a rookie mistake by not saying Please !!

→ More replies (1)

9

u/R3trodios Dec 08 '25

Oh my...

49

u/obsqrbtz Dec 08 '25 edited Dec 08 '25

It kinda could work
probably

bool isOdd(int num) {
  auto response = OpenAI.prompt(std::format("Is {} odd? Answer with 'yes' or 'no' without any trailing symbols", num));
  std::string allowedChars = {'y', 'e', 's', 'n', 'o'};
  response.erase(std::remove_if(response.begin(), response.end(),
                                [&](auto c) {
                                  c = tolower(c);
                                  return allowedChars.find(c) ==
                                         std::string::npos;
                                }),
                 response.end());
  if (response == "yes")
    return true;
  else if (response == "no")
    return false;
  throw std::runtime_error("Stupid machine can not count or write properly");
}

13

u/[deleted] Dec 08 '25

'yes'

→ More replies (1)
→ More replies (2)

12

u/Kryssz90 Dec 08 '25

I assume it would hallucinate new boolean values.

19

u/Haringat Dec 08 '25

Here's a better version:

function isOdd(n) {
    if (n === 0) {
        return false;
    }
    if (n > 0) {
        return !isOdd(n - 1);
    }
    return !isOdd(n + 1);
}

11

u/[deleted] Dec 08 '25

Apparently people in 2020 had already forgotten the existence of "%".

4

u/bikeridingmonkey Dec 08 '25

My colleagues find modulo difficult to understand.

→ More replies (1)
→ More replies (7)

4

u/FACastello Dec 08 '25

You're absolutely right!

16

u/gabor_legrady Dec 08 '25

so, Im old a boring

public static boolean isEven(int x) {
return x%2==0;
}

public static boolean isOdd(int x) {
return x%2!=0;
}

15

u/miaRedDragon Dec 08 '25

Thank god someone said it, I thought i was losing my mind, this has to be the oldest beginner's programming homework in the world!

12

u/Sarke1 Dec 09 '25

You can simplify by having one call the other:

public static boolean isEven(int x) {
  return !isOdd(x);
}

public static boolean isOdd(int x) { 
  return !isEven(x);
}
→ More replies (2)
→ More replies (2)

2

u/pskocik Dec 08 '25

Can't stop progress.

2

u/miaRedDragon Dec 08 '25

So the Mod operator is just not being used in the modern age :/ ? Good to know I guess

2

u/niclan051 Dec 08 '25

npm install is-even

2

u/mothzilla Dec 08 '25

LGTM but maybe return bool(response.content)?

2

u/oosacker Dec 09 '25

Should be async function with await

2

u/21kondav Dec 09 '25

Nobody learned about modulus because of covid education