/r/programminghorror
Share strange or straight-up awful code.
RULES:
All posts MUST show terrible code. There are no exceptions.
No Editor Themes - If it's just your editor that looks bad, it doesn't belong here.
No Advertisement Code. This is generally written by people in marketing who only know what "code" looks like from other ads. It's not real code, so it doesn't belong.
No Student Code. Yes, they're learning, but bad code is part of the process.
No Generated Code. If it's minified JS, generated XML, or what have you, we don't want it here. Yes, the YouTube homepage has an extra right-angle bracket. We know.
No Asking for Help. Go to r/learnprogramming. What are you doing here?
No Spamming/Advertising. We don't care about your shitty Youtube video or new crypto that will "change the world".
Be Nice. No hate speech of any kind is allowed, as well as generally being a jerk. Talk about the code, not eachother.
No Direct Contact of the Mods. Please use the modmail, we don't want to be contacted directly.
Please direct stories without code to /r/talesfromtechsupport, and programming questions to /r/learnprogramming
Programming Horror is where developers come together to revel in the idiocy of our peers.
This subreddit is meant for sharing funny programming related stories and strange or straight-up awful code.
For the sake of not being mauled by rabid lawyer bears, please make sure to anonymize your stories - changing the names of people and companies.
For code examples, indent all your lines with 4 spaces to make it more readable:
foo = 'bar'
Sister subreddits
/r/programminghorror
Hello guys,
I have to develop an app which uses the Supabase Backup. I'm new to programming so I dont actually know where to start. I set up the Database and it's schema and I started developing the app with Flutter. Now, where I have to make the App interact with the Backend, I dont have any idea where to start. Does anybody here has some experience with Flutter and Supabase? As I mentioned, I don't have any experience regarding to this and I don't know where I should start. Does anybody knows some tutorials or websites where all this stuff is explained in a good way?
If ChatGPT can't figure it out, it's all good right? https://chatgpt.com/share/67734996-8390-800b-9bcc-bdeae5ae0b93
Don't even try to imagine the nested logic loops to get this working properly. This might be the most advanced PyWebIO app in existence.
Only after learning NextJS & React I realize what a fail this was.
The solution works, but at the cost of my sanity, efficiency, and readability...
I must say, breaking Python conventions is incredibly entertaining.
Hello,
I am trying to get my head around how casting works in C.
While I can definitely understand why casting is necessary in some cases I have come upon an example where I can not see how this casting helps here. Here is a code example I found where we simulate the execution of an invalid OP code on some SoC to force a system exception:
uint32_t* pSRAM = (uint32_t*)0x20010000;
*pSRAM = 0xFFFFFFFF;
(void)(*some_address)(void);
some_address = (void*)pSRAM;
some_address();
On the first line where we create the pointer and make it indicate to memory 2001000, why would I need the cast to uint32_t*?
I mean the pSRAM pointer is a uint_32 pointer pointing to address 0x20010000. So whenever I am accessing the contents of that address via the pSRAM pointer, whatever content is stored over there will be interpreted by the compiler as a uint32_t data since the pointer is declared as such. Is this not correct? Then why would I also need the cast to uint_32? Isn't that redundant? To tell the compiler that the content of that address should be threated as uint_32? Isn't it enough that it knows the pointer type? I hope my question makes sense.
Assuming(I guess I am :D) wrong, what could go wrong if I don't include that cast? What happens if I for example have something like this? Can it in theory exist a situation where this would make sense?uint32_t* pSRAM = (uint16_t*)0x20010000;
Also what is a good book that has a good section on casting? All the tutorials I have found online just give some introduction to casting and some basic examples but do not explain in depth why and when you should use it to avoid running into problems.
Thank you very much for reading!
Dudes, I just made a release trailer for my upcoming ASCII art video game but I am a noobie and that is my first video game so I have no idea on how to make a good trailer. Any peace of advice would be very welcomed so that I could remake my trailer for better. Here is the video: https://youtu.be/rHrKYJ1u_7A?si=jGjaOtI4_CS43RAM
Found on Reddit, don't want to crosspost because it seems that OP is a newbie to assembly
Anyway, those blocks go much further down...
With AI getting better at coding and automating more tasks, I'm starting to wonder: Should I be worried about losing my job? How is AI likely to impact the job market for experienced developers like me? Should I pivot to a safety team security ?
Would love to hear your thoughts
I received the API documentation for a mid-sized company in Brazil. They claim to be the "Leader" in providing vehicle/real-state debts.
They use the following proprietary algorithm for authentication purposes:
Comments are in portuguese, but here's what it does:
Step 1- create a SHA1 hash from the clientId + "|" clientsecret (provided)
Step 2 - Retrieve a unix-timestamp
Step 3 - Create a string with clientId (again) + | + clientSecret (again) + timestamp + step1Hash
Step4 - Base64-it
Step5 - "Rotate it" - basically, Caesar-cypher with a 13 right shift.
That's it. For instance, if clientId = "user" and clientsecret = "password", this is the expected "cypher":
qKAypakjLKAmq29lMUjkAmZ0AQD4AmR4sQN0BJH3MTR2ZTAuZzAxMGMxA2D3ZQMyZzD0L2ZmMGOwZGSzZzH1AQD=
Note that I didn't provide the timestamp for this "cypher": De"-rotate" it and this is the plaintext:
user|password|1734448718|049e7da60ca2cde6d7d706e2d4cc3e0c11f2e544
The credentials are in PLAINTEXT. The hash is USELESS.
To be clear: I know that in Basic Auth, the credentials are also only Base-64 obfuscated. The rant here is that they created an algorithm, and presented it as the best authentication method there is.
int i = 3; i = -++i + (i = i-- - 3);
what is the value of i?
Well, first do ... end
blocks allow functions to execute multiple expressions (last value is implicitly returned from a block). Any "variables" and functions declared inside them are going to be fred when end
is reached.
Second, "methods" allow a better(?) syntax to call functions on values, without them you'd need to use or a, parse '4'
in line 3
Added `do ... end` blocks with their own scopes and \"methods\"
(parse {str}
parses a string to a number because i haven't implemented numeric literals yet, and {a} or {b}
acts both as the logical and the bitwise or operator, depending on whether its being ran on bools or numbers)
The way "methods" are implemented is very hacky and imperative (see call_method
and the //lit
funcs in the rust code).
It essentially parses a or b
as a(or, b)
, and makes a
's code be basically like if args.is_empty() { return a; } else { return args[0].eval(a, b); }
(where b = args[1]), meaning that a
(a()
) just returns a, whereas a func b
(a(func, b)
) returns func(a, b)
... Yeah
Had to anonymize variable, function and type names but this is real production code:
if (foo instanceof TypeA) {
((TypeA) foo).doTheThing();
} else if (foo instanceof TypeB) {
((TypeB) foo).doTheThing();
} else if (foo instanceof TypeC) {
((TypeC) foo).doTheThing();
} else if (foo instanceof TypeD) {
((TypeD) foo).doTheThing();
} else if (foo instanceof TypeE) {
((TypeE) foo).doTheThing();
} else if (foo instanceof TypeF) {
((TypeF) foo).doTheThing();
} else if (foo instanceof TypeG) {
((TypeG) foo).doTheThing();
} else if (foo instanceof TypeH) {
((TypeH) foo).doTheThing();
} else if (foo instanceof TypeI) {
((TypeI) foo).doTheThing();
} else if (foo instanceof TypeJ) {
((TypeJ) foo).doTheThing();
} else if (foo instanceof TypeK) {
((TypeK) foo).doTheThing();
} else if (foo instanceof TypeL) {
((TypeL) foo).doTheThing();
} else if (foo instanceof TypeM) {
((TypeM) foo).doTheThing();
} else if (foo instanceof TypeN) {
((TypeN) foo).doTheThing();
} else if (foo instanceof TypeO) {
((TypeO) foo).doTheThing();
} else if (foo instanceof TypeP) {
((TypeP) foo).doTheThing();
} else if (foo instanceof TypeQ) {
((TypeQ) foo).doTheThing();
} else if (foo instanceof TypeR) {
((TypeR) foo).doTheThing();
} else if (foo instanceof TypeS) {
((TypeS) foo).doTheThing();
} else if (foo instanceof TypeT) {
((TypeT) foo).doTheThing();
} else if (foo instanceof TypeU) {
((TypeU) foo).doTheThing();
} else if (foo instanceof TypeV) {
((TypeV) foo).doTheThing();
} else if (foo instanceof TypeW) {
((TypeW) foo).doTheThing();
} else if (foo instanceof TypeX) {
((TypeX) foo).doTheThing();
} else if (foo instanceof TypeY) {
((TypeY) foo).doTheThing();
}
Thankfully the alphabet is large enough to cover all use cases /s
I want to achieve 2k rating @ codeforces by end of 2025 Here's what I m doing for that. ** I'm from medico background and no prior cs knowledge,
Learning python and currently "file handling" it's been 3 weeks
I don't know where to stop, Whenever I want to start DSA , it requires some other python programming that i haven't completed yet,
I try to attend codeforce's competition but the question are way more hard
So I'm puzzled and confused, can anybody please guide me what to do after python, and how much python i need to learn before starting DSA and when to attend competition.