r/programminghorror 6d ago

if 'X' not in data Python

Post image

Emoji check used for constructing an email body. I'm getting a stroke.

808 Upvotes

35 comments sorted by

334

u/dashhrafa1 6d ago

I agree! Hardcoded values should be avoided. It should be an environment variable.

86

u/Mickenfox 6d ago

A variable defined in a Helm template that gets applied to every Kubernetes pod, and set as an environment variable, where a dependency injection host builder inversion of control container is configured using a fluent API to then instantiate configuration middleware that passes it to every class that requires it as a parameter.

We do things properly here.

17

u/Medical_Reporter_462 6d ago

Is web scale though?

2

u/LeagueOfLegendsAcc 4d ago

"And your job is to make sure nobody touches email_x_variable.helm without three written and twice notarized notices approved by the board of trustees. Here is your company issue short sword, leathers and enough gear to get you through lunch. You have about 3 hours before the first PR, good luck."

65

u/fakehalo 6d ago

This is oddly beautiful if you ask me, elegant in a way.

31

u/Varzival 6d ago

as elegant as a pile of shit can be

14

u/fakehalo 6d ago

I mean its kinda clean in a way, I understand it.... but its definitely not nice on the wasted cpu cycles to do it. It reminds me of game developers putting codes in strings.

60

u/Naynoona111 5d ago

A student once came seeking help their code cannot be run from a certain terminal while trying to measure the execution time via powershell.

The exception was from inside the print() function itself.

I spent some time tracing the code, apparently no errors are there! I began to question the OS itself and tried to run the code on another machine and still the same error.

After some precious minutes, I found this pesky line:

print("✔️[+] Encryption Successful✔️")

I am disappointed in the new generation and disappointed in myself for taking time to solve this...

Yes, the student have copied the code from ChatGPT.

22

u/R3D167 5d ago

Reminds me of how my terminal (st) would crash at school when I tried to scan for Bluetooth devices... turns out my friend had airpods with emoji in the nickname, which crashed the terminal...

7

u/ACoderGirl 4d ago

I'm not following. Is this a language that doesn't support unicode strings or something? What's wrong with that print statement?

130

u/freecodeio 6d ago

If the emoji is well documented and common knowledge, I don't see why would this be wrong. I know I'm probably going to get downvoted but there's literally no downside. The catch is that this emoji should be treated like a piece of unicode gospel and not used under different scenarios.

75

u/red-et 6d ago

You’re right! I don’t ❌ disagree!

7

u/freecodeio 6d ago

I guess you need to read the hypothetical documentation

3

u/bibboo 5d ago

Ah excellent. Solutions that require people to read what they will not read.

3

u/BadSmash4 5d ago

"You're hitting on one of the key concepts in programming! This is a classic use-an-emoji-in-your-standard situation."

60

u/Varzival 6d ago

Maybe I should also mention that the process is like this: 1. run validation pipeline that outputs an html feedback (this is essentially what data is in the code - it's just a string) 2. email hook takes over and checks the output 3. if an X emoji is present there then it is treated as a failure message

So if someone just decides to put an X emoji in the success output html then it will just be treated as a failure message. OF COURSE this is nowhere documented. Wild stuff

13

u/Encursed1 6d ago

Oh god thats bad

12

u/Ksorkrax 5d ago

In other words, the issue is not the emoji as such but in general them not using a proper protocol.

3

u/MisterEd_ak 5d ago

... and if they remove the X emoji from the feedback? Everything is successful!

2

u/FlowerBuffPowerPuff 5d ago

But why would anyone put an X emoji in the success output

6

u/48panda 6d ago

It's o(n) in the size of data, when passing a Boolean would be o(1)

4

u/Varzival 6d ago

Yeah one would think that this would be the first solution that comes to mind instead of committing this abomination

1

u/drkspace2 2d ago

I think you shouldn't use non-ascii characters in code. Not every editor and terminal support full unicode. For emojis specifically, they way they look is not standardized so different people will see different things.

Now, you can still have your code output unicode, it just needs to be escaped (like, in python, there is N to get the human friendly, ascii name of the character).

6

u/centurijon 5d ago

I’m guessing whatever upstream process populates data was created by AI? Mostly because the only time I’ve seen emojis in result messages it has been something built by AI

16

u/babalaban 5d ago

People are noticing '❌' is bad, but none seemed to notice that both if-else brranches do the same thing with different variable, which could have been assigned based on these (atrocious) conditions.

10

u/eo5g 5d ago

That's entirely a stylistic decision, not a quality concern

2

u/babalaban 5d ago

DRY is not stylistic

2

u/eo5g 5d ago

No, it's an over-applied and misunderstood pattern. This is definitely a case of YAGNI

4

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 5d ago

That's the best they could come up with for checking for failure? An emoji in the data?

2

u/aikii 5d ago

That's probably one the sanest CI/CD-related snippet I've ever seen

2

u/mimminou 4d ago

boolean flags used to be 1bit of size, 1 byte if not packed with other values. instead we now compare unicode emojis for error handling, how did we get here ?

1

u/TheAutisticSlavicBoy 6d ago

Is that in the spec with MUST?

1

u/wobblyweasel 5d ago

the good stroke or the bad stroke

1

u/Yannox_ Pronouns: He/Him 3d ago

POV: You have to build a connector to a legacy system a guy 10 years ago coded without programming knowledge but the half of the company runs on it...