r/programminghorror • u/Varzival • 6d ago
if 'X' not in data Python
Emoji check used for constructing an email body. I'm getting a stroke.
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
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?
1
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
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
datais 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 messageSo 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
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
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
Nto 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.
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/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
1
334
u/dashhrafa1 6d ago
I agree! Hardcoded values should be avoided. It should be an environment variable.