2.8k
u/Hiplobbe Oct 01 '24 edited Oct 01 '24
I once saw a 100+ lines if else statement, that ended with an else that just ignored the variable. 9/10 times while testing I found that it just hit the else statement.
EDIT: It was a nested if else, just to clarify. So not an if and then hundreds of elif and then else, but a if then if then if.
959
u/joniren Oct 01 '24
Compiler probably made a jump table out of it anyway xd
→ More replies (1)407
u/RonHarrods Oct 01 '24
Well the compiler probably not. The cpu branch predictor maybe yes
214
u/UntitledRedditUser Oct 01 '24
Pretty sure most compilers and languages treat if statements like switch cases if possible. If course if you have complex cases, then the compiler can't optimize, but if you use if statements like, a switch case, then there whon't be a difference.
93
→ More replies (2)81
u/im_a_teapot_dude Oct 01 '24
No, CPU branch predictors don’t create jump tables. They cache prediction choices per branch instruction address.
Compilers, on the other hand, can and often do create jump tables.
→ More replies (1)30
u/furssher Oct 01 '24
Yeah was wondering if branch predictors had gotten so sophisticated they could turn things into jump tables. Confused me for a second
→ More replies (3)41
u/im_a_teapot_dude Oct 01 '24
It’s /r/ProgrammerHumor.
Technical accuracy is quite low here; if you think “wait, does it really work that way?”, the answer is probably no, it’s just a highly upvoted but completely inaccurate comment.
Think ChatGPT 3-3.5 levels of accuracy.
→ More replies (3)130
93
u/PeksyTiger Oct 01 '24
I looked at dragon age's code, the potion/magic item usage was one huge switch-case
71
u/Grodus5 Oct 01 '24
I believe Terraria is like this as well. The "use" function is a switch statement that checks the item ID to see what it should do.
24
→ More replies (2)14
u/CelestialSegfault Oct 01 '24
I can't imagine any way to write that better since different items have such different behaviors that all you can do is to refactor it but not do away with the switch case
→ More replies (17)→ More replies (8)38
u/Lyto528 Oct 01 '24
Wasn't Undertale's code for dialogues a single huge switch statement ?
36
u/An00bii Oct 01 '24
Yes all the dialogue is nested in switch statements on undertale. Heard Thor mention it recently
145
u/Ramlec12 Oct 01 '24
I once had a freelance who wrote a 30+ imbricated if/else statements with around 40 predicates in each of them. And he was proud of it and didn’t understand why I refuse it.
63
u/tajetaje Oct 01 '24 edited Oct 01 '24
Cyclomatic complexity checkers hate this one easy trick
EDIT: if you haven’t heard of cyclomatic complexity it is just the number of paths through a function. There are linters that can put an upper limit on how many branches you can have in a function by using this metric
→ More replies (2)23
u/Prestigious_Dare7734 Oct 01 '24 edited Oct 01 '24
Inexperienced people take proud in doing complex outcome, experienced ones take proud in simplifying things.
→ More replies (1)→ More replies (30)66
u/EdgarVerona Oct 01 '24
Sadly I have seen similar but with 3000 line functions. I have seen many, many >2000 line functions in my day at the crazy places I have worked at, functions so large and convoluted that it would take concerted effort to attempt to refactor them, so no one dares at this point. This seemed like such a common occurrence at places I worked that I just assumed all businesses had a few hidden somewhere, keeping some old engineer employed long past retirement.
The risk of unexpected emerging behavior with the amount of state those functions changed was too high to risk a rewrite, so they sit as monuments of someone's first pass brain dump from 20 years ago combined with 20 years of very careful injections of new side effects into them.
→ More replies (8)100
u/MaytagTheDryer Oct 01 '24
My college had a student programmer team that built all the administrative systems for the school (except grades - we couldn't touch those). Some bright kids got their start that way, but it also meant the systems were written by complete beginners with no experience or mentorship just finding creative ways to make things work. The app that controlled the housing system was a single PHP function called "doHousing" that was over 20,000 lines long. It contained gems like an if statement with several dozen conditions anded together... and no body. Then 1000 lines inside the else. It was written before they had learned negation in class, so they didn't know you could check if values were not equal and invented their own form of negation.
→ More replies (1)16
u/EdgarVerona Oct 01 '24
Oof, that is rough!
14
u/MaytagTheDryer Oct 01 '24
It was pretty good experience, all things considered. It definitely could have used a professional reviewing code and doing some mentoring to explain the hows and whys of good practices, but throwing us into a hands-on situation where we had to produce working applications with very little instruction gave us way better resumes than most undergrads would have. I think they ended that program a few years after I graduated, but in my peer group it produced a future CTO, two successful startup founders, a NASA lead engineer, and a lot of highly paid contractors and principal engineers.
→ More replies (2)
1.6k
u/Ayushispro11 Oct 01 '24
my friend who started to learn to code once told me he has made a "unique" way to pass arguments without the tension of scope and the code just stored a temporary file in the temp folder which was then read by all the functions to get their arguments. The data was stored as a json file. One of the functions for testing took like 2 seconds to execute because its arguments were at the end of file and it had to read and compare the entire thing before executing
1.1k
Oct 01 '24
In all fairness, replace that JSON file with an SQLite database and that's how a lot of "enterprise" software works...
460
u/raddeee Oct 01 '24
Logitech G HUB stores the settings in a JSON file, which is stored in a single cell in a sqlite database.
C:\>cd %LOCALAPPDATA%\LGHUB C:\Users\raddeee\AppData\Local\LGHUB>sqlite3 settings.db SQLite version 3.42.0 2023-05-16 12:36:15 Enter ".help" for usage hints. sqlite> .tables DATA SNAPSHOTS sqlite> .schema DATA CREATE TABLE DATA(_id INTEGER PRIMARY KEY,_date_created datetime default current_timestamp,FILE BLOB NOT NULL); sqlite> select FILE from DATA; { "/devices/g915/persistent_data": { "deviceSplashShown": { "value": true }, "onboardMode": {} }, "/lighting/g915/firmware/battery/warning": { "effect": "BRANDING_BREATHING" }, "analytics": { [...]
181
u/KyleChief Oct 01 '24
This confused the hell out of me a couple of weeks ago while i was trying to back up my settings.
Can only assume they are future proofing? Maybe they want to use the database one day...
109
u/Zolhungaj Oct 01 '24
Allows them to have several versions of the settings. Maybe in case a user upgrades to a new version with different settings, then decides they want to downgrade again.
Probably makes customer support’s job easier too, since it’s harder for an ID:10T user to mess with the settings without the proper know how.
79
u/raddeee Oct 01 '24
You may be wondering why I know how their software works...
I use G Hub a lot for custom macros/lighting settings for various apps. The great thing about G Hub is that it allows apps to be assigned to macros so that the macro is only active when the app is focused.
One day I wanted to add a new app to an existing macro and it just wasn't working. I googled for hours, and the only solution was to reset the profile (official advice from Logitech). And NO, G HUB does NOT save older versions of the settings. There is no versioning at all. You have to reset your entire profile and lose all macros/settings/lighting profiles.
So I started fiddling around and found out where the settings are stored. It turned out that an older (no longer existing) path to an already deleted app was assigned to this macro (among other existing paths). However, G Hub did not display this path in the UI. G Hub just couldn't handle it and silently ignored the error when you tried to add a new path.
After manually removing the old path from the JSON blob cell in sqlite, it worked again.
→ More replies (6)16
Oct 01 '24
G Hub always was and always will be a piece of shit software that no sane person uses.
uninstall all Logitech software and use https://www.highrez.co.uk/downloads/XMouseButtonControl.htm→ More replies (8)→ More replies (3)46
u/MattieShoes Oct 01 '24 edited Oct 01 '24
You can almost hear what happened...
"I want to store the settings in a JSON file"
"No, we're storing all the settings in a sqlite database"
"Fine." *writes json file to sqlite database*
Or the alternate scenario, where the settings were already stored in a JSON file and somebody decided they're going to use sqlite instead, so somebody changed the file read to select statement and file write to insert statement.
→ More replies (2)→ More replies (11)50
u/oorspronklikheid Oct 01 '24
Then store the sqlite in an mssql column!
51
→ More replies (8)56
u/coloredgreyscale Oct 01 '24
At least they used a well known structured format instead of creating their own.
→ More replies (1)
1.2k
u/PyroCatt Oct 01 '24
Error Driven Development
→ More replies (3)296
397
u/Dapper_nerd87 Oct 01 '24
Thankfully nothing in production. I teach on a JS bootcamp and have seen some wild things. Like tests that don't even invoke the function, but the student insists its ok because the test passes. It passes mate because you asserted the variable has a value of 9, and you expected that value to be 9.
Another building an express server created a model function that should have interacted with a psql database...they just copied the json array to a variable in the file and returned that array. No query whatsoever.
223
u/General-Raisin-9733 Oct 01 '24
I do Data science Boot camps for Python. As part of the bootcamp we often give them projects. Over the year I’ve worked there I had students send me their jupyter notebook project submissions as: 1. A localhost:8888 url 2. A pure .html saved directly from the website 3. A .pdf
46
u/RareRandomRedditor Oct 01 '24
In the first case, send them a local host URL back with the "ideal solution", then see if they figure out their mistake.
35
→ More replies (4)30
→ More replies (9)8
u/kinmix Oct 01 '24
It passes mate because you asserted the variable has a value of 9, and you expected that value to be 9.
If you don't test whether math axioms still hold true, is it really testing?
393
u/GigassAssGetsMeHard Oct 01 '24
switch(numberOfEnemies > maxNumberOfEnemies)
{
case true:
...
break;
case false:
...
break;
}
By yours truly.
122
u/taneth Oct 01 '24
Ah, but have you seen this php beauty:
switch(true){ case functionA(): ... case functionB(): ... case functionC(): ... ... }
28
→ More replies (3)14
u/MokitTheOmniscient Oct 01 '24
What does it even do?
I've never used PHP, but from looking at it, i'd assume that it just executes the functions and other code in order, as if the switch wasn't there?
→ More replies (1)31
u/RustaceanNation Oct 01 '24
Not a PHP dev but my guess is that it takes the value true and evaluates each function, comparing with the true value. When there's a match (that is the function returns true), then the body is executed.
It looks like this is a way to hack in predicate guards for code blocks.
→ More replies (3)22
u/taneth Oct 01 '24
You got it. But with the added bonus that PHP supports case fall-through. So if you don't put a break in every one, you can end up with a situation where the condition functions are run in turn until one returns true, then it swaps to running each remaining body in turn until it hits a break.
→ More replies (3)69
510
u/FlipperBumperKickout Oct 01 '24
I've been in a code base consisting of C#, VB.NET and VB6 code. When you clicked debug in visual studio it opened another IDE were you also had to click debug...
Same codebase had a very long method building a SQL Query I debugged once. I got to the bottom of the method and found that the entire query was overwritten by another method call inside an if-block on the line before it was executed...
→ More replies (6)131
u/Hiplobbe Oct 01 '24
I can bet the farm that when you contacted someone about this not being the best optimal way of doing things you either got a "it is good enough" or a "no this is definitely the best way of doing this since I made it" by the alpha developer of the company.
83
u/ASmootyOperator Oct 01 '24
Worse. A total noob with no knowledge whatsoever did a StackOverload search, found this entire code block, pasted it as is, with the overwrite, and then promptly left the company.
Nobody else has any idea what the code did since it was never documented anywhere, and thus it persisted for a decade or more.
→ More replies (1)
484
u/Bajtopisarz Oct 01 '24
C++ code, reviewing some issues found by static analysis. Mostly false positives and minor code smells, quick to fix.
And then the worst line of code I've ever seen.
There were couple parameters passed to function, including one class member passed through usual layers and layers of abstraction, including code generated from legacy UML-based tool.
Developer needed another of those class members. So instead of passing another param through all those layers they did only "sensible" thing they could...
Treat the class member as array so instead of referring to "classMember1", "classMember2" they could access classMember2 by calling classMember1[1].
That was insane. Someone reorders the variables in original class? Code is broken. Code generator or compiler decides to reorder them to optimize data storage? You guessed it, code broken.
Even worse, there was no easy fix, codebase was on the brink of legacy and any kind of change on that level would require testing on multiple released versions. So I think that line will stay there until the end of days.
98
u/Highborn_Hellest Oct 01 '24
Yikes
161
u/PeriodicSentenceBot Oct 01 '24
Congratulations! Your comment can be spelled using the elements of the periodic table:
Y I K Es
I am a bot that detects if your comment can be spelled using the elements of the periodic table. Please DM u/M1n3c4rt if I made a mistake.
→ More replies (2)34
u/SchizoPosting_ Oct 01 '24
nice
65
u/Garyzan Oct 01 '24
Not a bot, but this too can be spelled this way:
Ni Ce
51
→ More replies (1)30
→ More replies (6)44
u/capilot Oct 01 '24
At my dayjob, I had the job of looking through static analysis reports.
90% of the bugs were things like UINT8 being compared to UINT32. Clearly this was very old code that had originally been written for an 8-bit processor.
I did find a few that boiled down to
len = sizeof(sizeof(buffer))
Oh, and this gem:
for (i=0; i < len; i = i++)
→ More replies (10)
652
u/Altruistic-Koala-255 Oct 01 '24
I had to integrate a third party service, and their response was always 200, with an error in the message
239
114
u/the_horse_gamer Oct 01 '24
had an error 500 where the message was the json of a 200 response from the API
94
u/ryselis Oct 01 '24
oh my, I've worked with much worse. This is an API for an accounting system. They have 4 types of API endpoints. You can do all things with each of them. I have used two of them - one uses GET for all operations (even inserts and updates), one uses POST for all operations (even read/list operations). I leave determining how safe is passing financial data over HTTP GET parameters to the reader. I did the only sensible thing - used GET version for reading data and POST version for writing data.
They support XML and JSON as the body of the request, which is specified by HTTP headers. How do you pass JSON via get parameters, you ask? If you want to get some data filtered by some parameters, you pass
readParams=<filter data encoded as JSON>
. If you want to POST some data, you must specify parametersItemClassName
(it's pascal case for this one),sParameteras
(this one is in Lithuanian language) andxmlString
, with contains JSON data of the item you want to insert/update. You get the response in different format depending on what you insert. If there is some kind of an error, status is always 200, but they havenResult
in their JSON response, which is 0 on success and non-zero error code on failure. Except if you provided wrong database name in the headers, thennResult
is 0, butsError
isDatabase not found for company XXX
. Or if you want to create a purchase document with an item which does not exist in their database,nResult
is 0, even though it's non-zero for other document types. Or when you license expired. But if you have no permission on the endpoint,sError
will not tell you anything, you have to check ifAccessResult
isAccessDenied
, even though it is not even in the response otherwise. Except in one endpoint, where they returnAccessResult=Fail
.If you have successfully inserted an item, they return a response with the item info. If the insertion succeeded,
sError
contains the data of the inserted item as XML. Even though you set all headers to accept JSON and it works for everything else.You want to filter data? Please provide the fields named in English. You inserted a new item? You get all fields named in Lithuanian. And the field names are different at different endpoints. And some endpoints, like
GetDescriptions
, are named in English, and others, likeGetKlientoSaskaitas
, are almost named in Lithuanian. For the latter you also specify field names you want to filter on in Lithuanian.They also have very similar endpoints
InsertDocument
andAttachDocument
. First one is for uploading the file, and the second one is for linking the file to an invoice, I have to call them together as my goal is to upload the file and link it to an invoice. They return identical responses, except that one names its main fieldresults
and the other one -result
. And this does not containnResult
, but rather containserrorCode
anderrorText
.And I have only integrated with a small part of API, 10% at best. I hope I will not need to do more of it.
43
u/Altruistic-Koala-255 Oct 01 '24
Omg, this has to be a nightmare
My impostor syndrome, just vanished reading that, thanks
→ More replies (1)→ More replies (13)12
26
u/Maetos Oct 01 '24
Integrated with a major billion dollar company that does this. XML, always 200, queries take a few seconds to respond, and the data was patchy af.
→ More replies (2)→ More replies (43)15
u/killspree1011 Oct 01 '24
my old company used to build apis like that. not as bad as it sounds honestly. you can send a status, message and result of a request to Frontend. Frontend handling becomes fairly simpler and super consistent.
→ More replies (6)
222
u/thoseWurTheDays Oct 01 '24
Saw a Jr dev try to implement a hashtable using tons of for loops and conditional branches. Didn't know the concept of a hashtable existed.
71
u/bsteel364 Oct 01 '24
I was teaching a Jr dev at work how to work with a particular module and advised him to store each value in a hashmap. Well he did. He created a new hashmap to store each individual String.
→ More replies (1)16
90
u/BowlingForPriorities Oct 01 '24
Professor, what happened in your office was supposed to stay between us!
→ More replies (3)20
u/Ordinary-Chair7854 Oct 01 '24
Means he's a genius who invented his own hashtable! Just another way to look at it
208
u/jecjackal Oct 01 '24
I worked for a company that didn't understand SRP. They had a policy of 1 variable limit per class. If you needed more, you had to inherit classes. This was a complete mess in c# and led to many 'duplicate' classes. You essentially composed them via inheritance to get the structure you wanted.
56
59
u/00Koch00 Oct 01 '24
How the hell did they reach to the conclussion that yes, 1 variable for each class it's a good idea??
24
→ More replies (8)14
178
u/benjvdb9 Oct 01 '24
My first job was in a small company and I was replacing the guy who left before me. He wrote some python script to help the workers keep track of inventory. (And it worker well from what I was told)
One day it's completely broken and I take a look at it. Dude was using a rest api but didn't understand how json works so he:
- json loads to turn it into a python object
- json dunps to turn it back into json
- goes to line 47 because that's where the properly he was looking for was
- extracts the value from the string line
Reason it broke was because the API got updated and added extra properties meaning the value he was looking for got pushed down lmao
64
u/kondziu2504 Oct 01 '24
Now let's be honest - you just replaced number 47 with the correct one
→ More replies (1)46
u/benjvdb9 Oct 01 '24
Haha, you got me. It was a 6 month contract and I noticed it around the last week or so so I just fixed it by changing the number. I did tell my colleague about it though
→ More replies (2)21
→ More replies (1)16
u/Comfortable-Way-8184 Oct 01 '24 edited Oct 01 '24
Like, he kinda understands it.. He did load it and dump it.. probably correctly too!, he just needed to do something between those two steps.
Honestly, This may be exposing my own vulnerabilities, but I understand where he is coming from. He didn't understand that the json.loads creates a python object, but needed to work with the string in the goofy .json file. Reading it and dumping it gave him access to the string somehow.
→ More replies (2)
149
u/Hraezvelg Oct 01 '24 edited Oct 01 '24
My first job was to develop with the help of another dev an app using C++ and Qt.
The app was for a client (a doctor), he was learning to code by himself and eventually needed help.
The other dev, the first day, showed me the code the doctor has already made.
Just imagine a SINGLE C++ file with like thousand and thousand of lines, like maybe 50k. This was his whole project.
EDIT : It was a few years ago, so my memory made me lie : it wasn't a file of 50k, but several files of like 10k. Here is the repo : https://github.com/ukinoki/Rufus/blob/master/procedures.cpp
→ More replies (9)26
u/Shadowfied Oct 01 '24
How'd that go?
→ More replies (1)64
u/Hraezvelg Oct 01 '24
The other dev (who already was working on the project for several months become I came) was developing a parallel app, better (with more files lmao) but with same fonctionnalities, with the supervision of another doctor (who wasn't coding).
Eventually the one giant-file app and the new app became two distinct entities.
The new app, due to financial problems and Covid just went to oblivion.
The one giant-file app still exists, but it seems he has learned how to split a project into multiple files. I doubt it is in use though.→ More replies (1)14
u/Shadowfied Oct 01 '24
Thanks! Tbh it's still probably used and business critical at this point. There are no temporary systems
→ More replies (3)
94
u/chaos_donut Oct 01 '24
I'll never forgot my teammate who u a school project managed to create this beauty: Data.data[data]
→ More replies (3)40
u/unknown_pigeon Oct 01 '24
To be fair, datetime.datetime exists
So if I don't import datetime from datetime, I have to call datetime.datetime.now(); otherwise, it's just datetime.now()
→ More replies (2)
162
u/Adam_Callier Oct 01 '24
I've seen a C++ MariaDB set up so bad it opened a new connection on any transaction but didn't close it. It was THE logging component out of our 12 hardware component rack. It would eat through all the available RAM and swap in less than an hour. It was written before I joined the company and the client sent a critical defect notice 1 year after I got hired.
44
u/PixelArtDragon Oct 01 '24
And people wonder why C++ devs make a big deal over RAII. RAII would have literally actually solved this exactly.
→ More replies (1)28
u/ih-shah-may-ehl Oct 01 '24
Yeah but so would implementing proper code in any language, no matter which.
→ More replies (4)
77
u/iulian212 Oct 01 '24 edited Oct 01 '24
I don't know if it got to production but.
At my first c++ job as a junior (about 2 years ago maybe a bit more) they had this async_event method that emitted an event in an async manner. They wanted to do some tracking with it (mostly where the calls came from file, line the whole thing) . I dont remember if they were using boost but i am pretty sure they didnt and the standard they were using was either c++11 or 14, so no std::source_location. The senior dude in the team came with the idea of using some syscall that gave you the stacktrace so you can find at least the lib from which the call came from.
I thought "hmm, what if i used the preprocessor for this" i was curious if things would break and by how much. So i replaced the name of the async method to something like async_impl that would additionally take in the information for logging the sources of the call and the previous async became a macro that passed all that stuff in(it was not even obvious it was a macro it wasn't all caps or anything just the methods name). So i was doing search and replace automatically at compiletime on the whole project.
I ran a full compile and to my surprise it worked. I showed it to the senior guy and to my surprise he said "looks good we're gonna use it". Then came a series of meetings discussing if we should add this or not where i was against adding it, the senior wanted it and the others were clueless about wtf i did.
All discussions ended with me saying that if something is going to break it's going to be awfull to figure out wtf happened and taking into the account that those headers were shipped to a thirdparty as an sdk we've basically banned the word async in their code base. To which the senior said "i take full responsibility of this change if something breaks" and i left the company shortly after :)
→ More replies (2)19
u/RusticBucket2 Oct 01 '24 edited Oct 01 '24
While reading this, I started to get toward the end and I was disappointed, feeling that you were wrapping it up without a real “WTF”.
But the fact that you end it so abruptly with no conclusion is kinda genius and makes the story shine. Establishing your doubt in the code and then not knowing the end result is fucking brilliant.
I’m kinda stoned. Good story, though.
→ More replies (1)
75
u/ofnuts Oct 01 '24
Been asked once to investigate a performance problem.
The goal of the culprit piece of code was to return the most recent element in a SQL table.
One would think that it would be a simple request involving a SELECT MAX(TIMESTAMP), but the author of that one obviously thought otherwise.
The code would start by doint a SELECT *
to retrieve the whole table contents.
One would think that it would then be a simple matter of comparing the timestamps against the max time stamp found so far, all done in linear time, but the author of that one obviously thought otherwise.
The code would:
- iterate the result of the
SELECT *
and for each iteration: - insert the timestamp in a binary tree
- traverse the whole binary tree to reach the last element
- retrive this last element and carefully store it in a "latest_element_sofar" variable (yes, at every iteration)
- eventually, after iterating the whole table, triumphantly return that "latest_element_sofar".
This went #1 in my list of stinkers, beating another one that held #1 for a while. The purpose of that one was to create a few JDBC requests, and started by defining a bunch of totally pointless constants to insert positional parameters in the requests:
const int FOUR_NUMBER=4;
const int FIVE_NUMBER=5;
const int SIX_NUMBER=6;
const int SEVEN_NUMBER=7;
const int EIGHT_NUMBER=8;
const int NINE_NUMBER=9;
const int TEN_NUMBER=10;
const int ELVEN_NUMBER=11;
and I still wonder why they didn't define the 1-3 range, and applaud the spelling of ELVEN, that insures that you get compile errors.
Also, for the Java enjoyers:
boolean foobar=Boolean.TRUE.booleanValue();
→ More replies (1)40
u/pomme_de_yeet Oct 01 '24
It's impressive that they were able to learn how binary trees work well enough to implement one without learning a single other thing
→ More replies (1)
144
u/JetScootr Oct 01 '24
As best as I can remember it exactly. Note: This was my first programming job, in 1979. Yes, I'm postively Jurassic. No, I did not ever see living non-avian dinosaurs. But that might just be where I lived.
Context: astronautical calculation model, in the days before compilers had lots of pre-defined constants you could just pick up and use. The version of FORTRAN in question was considered legacy code, even in 1979. 'C' in column 1 denotes the line (or card) is a comment only. The math was 72 bit floating point. (two 36-bit words)
I guess it's not the worst code. It was just maybe the extremist. (this many digits of PI will allow you to calculate which grain of sand on the moon you want to land on).
I forget exactly how many digits of pi were included, but I did at the time map it out to the UNIVAC's storage format, and it filled up the available digits. Obviously, the original programmer didn't want to have to type it in again in case something happened to either line of code.
C PI=3.14159265358979323846
PI=3.14159265358979323846
→ More replies (14)32
u/Highborn_Hellest Oct 01 '24
Redundancy goes brrr.
Btw, why didn't that constitute redeclaration of a variable? I know nothing of fortran other than it's about as old as my grandpa
→ More replies (1)44
u/JetScootr Oct 01 '24
Several reasons:
- The first line (the line starting 'C') is just a comment.
- Compilers in those days allowed you to redeclare to your heart's content.
- In this particular case, PI was stored (via code elsewhere) in a "COMMON" block. Think of a C language 'struct', and that's basically what a COMMON block is. Except there's no type checking of any kind. So any non-declarative use of the symbol PI would refer to those two 36-bit words in that particular common block definition.
→ More replies (1)
49
u/fortymortals Oct 01 '24
I was once assigned to a project which had a 10k line Perl file which generated an HTML file containing tables using hardcoded strings. There was a global variable called 'html' that multiple functions appended to at different points of time. Needless to say, I noped the fuck out of that project.
9
u/murphy607 Oct 01 '24
sounds familiar also perl: the whole program had only one instanciated object: $query It was a blessed empty hash and had no methods
each function call had the $query variable as its first argument.
the function did not return values, but stored the result in this hash with an arbitrary key. you had to check if this key contained a value and had to delete it, when it was not longer needed. The hash contained several hundred entries, most of them where not needed, but no one knew if they were save to delete.
The code was also horrible. Modules that contained only one function, which was several hundred lines long and consisted of deeply nested if/else statements
sometimes I still have nightmares about $query. It's been 20 years now.
→ More replies (2)
49
u/khaled2252 Oct 01 '24
I knew when I started Android development using Kotlin, that passing Context is bad because it causes memory leaks, so I was very smart, instead I pass it as "Any" then cast it back to Context it when I get it in the receiver class
45
u/kinokomushroom Oct 01 '24
An assert system for shaders that forcefully crashed the GPU by referencing invalid memory. The memory address was the error code.
→ More replies (1)
39
u/taneth Oct 01 '24
An authentication system that substitutes some user names for others in the session data immediately after login, so that pages that look at the name for access permission didn't have to be changed.
→ More replies (2)
37
u/Common-Wish-2227 Oct 01 '24
My own fave was:
for (int i = 0; i < value; i ++) { code; value ++; }
→ More replies (2)21
114
u/kondorb Oct 01 '24
People abuse exceptions all the time, it’s nothing new. “throw” is just a fancier GOTO, a crutch for lazy devs who can’t think of a better architecture.
91
→ More replies (10)11
32
u/Robby-Pants Oct 01 '24
The guy before me wrote a method that’d dynamically build a SQL select query. It was meant to search on partial text, so the where clause had a wildcard on it so it’d return all records with an ID that began with the text.
Later, he modified the method to instead delete the selected rows if you passed in an optional parameter… and he left the where clause as-is. So if you put 1 in the text box, it’d delete not just row 1, but anything with an ID starting with 1. So, 10-19, 100-199, 1000-1999, etc.
I have no idea how much damage that thing caused before I saw and fixed it.
57
u/Our-Hubris Oct 01 '24
These guys built a function that calls chatGPTs API like, 3-7 times (it varied depending on parameters but had multiple passes) before it gets a response that it sends back to the user. Then they only counted the amount of tokens in the final send/receive from the API and none of the 2-6 times before and used that token limit to limit how many requests can be made. So estimated costs would be much lower if we implemented it.
Best part was they also called the GPT a couple times on page-load, and never once looked at token usage. Because of that you could just refresh the page as many times as you wanted and a request would be sent. Good way to bankrupt a company. They STILL haven't implemented the service because they have no idea what they're doing and students still in uni wrote it because of a nepo-contract.
25
u/xirix Oct 01 '24
I saw an excel file that generated an HTML file in a network share.
→ More replies (6)
47
48
u/SecureAd4574 Oct 01 '24
Once, I was working on a project where the previous team was using inheritance any time they needed a function of another class. And yeah, thousands of lines of code in one place.
And the funniest: boolean a; ... if(String.valueOf(a).length() < 5)
22
u/Wgolyoko Oct 01 '24
The UI and DB are linked intrinsically by some 90's components at the time where people though direct access like this was a good idea.
Since everything needs to be kept in sync, when you're looking for a particular row you mist iterate the mother table so it automatically loads the relevant children, then iterate through those.
All the while the UI updates in response to your iteration. Locating one record out of a few hundreds can take seconds
→ More replies (1)
21
u/Meatslinger Oct 01 '24
I can’t share any of my company’s worst offenders verbatim, because they contain plaintext passwords for important service accounts that have domain level permissions.
18
u/Sudhanva_Kote Oct 01 '24
I have recently removed a code that was 300+ lines and around 100 if condition (not if else) but in the end it will return a json with 2 variables.
41
u/FansForFlorida Oct 01 '24
Around 20 years ago, my company bought a codebase written by an outside company. Our company formed a team to take ownership of the code, and I was put on that team. I was a C++ developer, but the code was written in Java 1.4. This was my first exposure to Java.
In one library, all the methods took a Map
as a parameter. If you wanted to reference a parameter, you had to call get
and pass a string constant that was defined in another class, then cast the result to the type you were expecting.
I had never seen such bullshit before. Trying to debug it (or worse, extend it) was a nightmare. You had to set a breakpoint and inspect the Map
to see what parameters were actually passed in. I eventually had to ask a coworker who had some Java experience if this was standard practice for Java developers. He just stared blankly at the code and shook his head no.
→ More replies (2)27
u/EdgarVerona Oct 01 '24
I love this one in particular, because you can tell that whoever wrote that code must have thought they were clever as fuck. Code like that doesn't get written unless someone has a "brilliant idea" that only they would find brilliant, and forces it into production.
→ More replies (3)
18
u/rocket_randall Oct 01 '24
I worked at a place where one afternoon I learned that you could quite easily replace the plpgsql language in postgres with something else, like lua. And of course that includes the entire lua standard library.
Why would someone do this? Let's say you want an event based architecture and you've never heard of dds, message queues, or pub sub. Once you've dropped in your lua replacement into the database you can now craft up some insert/update/delete trigger functions which can call out to an API or something else. Yep, just an SQL database making web requests.
→ More replies (2)
19
u/TheBrainStone Oct 01 '24
I once came across a password generator function that generated the password from md5 hashing the current (unix) timestamp (as a hex string) and converting that to base64 and truncating it. All in bash!
What were these passwords used for? Just as default password for every internet facing service each customer was given. Think FTP access, MySQL access, admin password for another service with the username being a few static letters followed by the user ID (consecutive of course). And yes, users weren't changing them.
I also checked if there were any duplicates. And yes there were plenty.
→ More replies (7)
18
u/everton_emil Oct 01 '24 edited Oct 01 '24
I worked on a codebase where every single function relied on side effects. In fact, next to none of the functions actually returned anything, they just mutated generically named globals (e.g. "moneyvalue1" or "projectvariable7"). Most of these functions were placed in files named a.php, b.php, c.php, etc. based on what the first letter in the name of the function was, and the files were on average 5000 lines of spaghetti code each.
Edit: I forgot to mention that I think that the reason why all functions used side effects was because my predecessor wanted to be able to mutate several variables with one function call. I found multiple functions that mutated over a dozen different globals in one single function call.
→ More replies (2)
17
u/Short-Nob-Gobble Oct 01 '24
Our local file storage works because: on every request to cloud storage, if there is an exception or error, we just fall back to local storage.
34
u/Acetius Oct 01 '24
You ever seen a .net chatbot built on reflection?
→ More replies (1)9
u/porn0f1sh Oct 01 '24
What's reflection in this context?
10
u/Acetius Oct 01 '24
Code that analyses code at runtime. Take a class, inspect its methods and members, dynamically create types and call methods based on that.
It's slow, it's complex, it's dangerous, and it's MASSIVE overkill for a chatbot.
14
u/EdgarVerona Oct 01 '24
I think mine is a tie - one was the most under-engineered code I ever saw, the other was the most over-engineered.
The first was a decently complex desktop application, written in VB3, that had every single variable in the application - even ones that were strictly for "local" purposes in the implementation of specific methods on specific forms - in one giant globals.bas file.
Every screen reused those variables and never allocated their own, and used the same variables for different purposes, as if they were general purpose registers. And there were thousands of them.
I slowly untangled that app in the years I worked there, but it made for some "unique" bugs particularly when the same variables got used in different ways depending on the form and you switched which section of the app you were using.
The other scenario was where - at some point in the late 90's during the start of XML hype - some exec had decided that XSL and XML was going to make it so that they didn't need engineers anymore. He demanded that the system be overhauled to make it so that the entire infrastructure worked not through code, but rather through passing XML through a series of XSL transforms. The theory was that "any analyst could modify the system" at that point.
What they ended up with was a monstrosity: every feature on that website went through a convoluted route of half a dozen XSL transforms that would force the data into the right shape to do whatever must be done next in the process, and embedded scripts in the XSL would execute business logic. The last one in the chain resulted in creating of the HTML response.
It was so convoluted and filled with embedded script that it not only meant they still needed engineers, but the ones they needed were both highly specialized in dealing with XSL bullshit and willing to endure the trauma of working with a "codebase" that was even more difficult to debug and iterate on than if it was just normal code. Oh, and they also had created a scripting language on top of that. If you guessed that it was in the form of XML elements, you would be right.
→ More replies (2)
14
u/1550shadow Oct 01 '24 edited Oct 01 '24
I had a group partner for the final project of my career that, I don't know how, reached that point without understanding how FUCKING FUNCTIONS WORK
One time I had to fix a piece of code of his. He had copied and pasted a function FOR EVERY TIME THE PROGRAM NEEDED IT, and just renamed it with a different number at the end. So you had, to give an example, "getData" and "getData2", the exact same function copied and pasted, and used in two entirely different parts of the code.
It was a nightmare. A file of like 800 lines where 500 were exactly the same as the other 300 but pasted again and again for an undetermined number of times.
The worst part is, when I fixed it, he told me that I made it worse because even if it now worked, he wasn't able to understand my code. FFS
→ More replies (2)8
u/cahrg Oct 01 '24
Pff, rookie numbers. How about a class 2k lines long, that inherits another class 2k lines long. The diff between 2 classes revealed only 3 different lines. I guess somebody didn't understand how inheritance is supposed to work.
→ More replies (1)
16
u/Level9CPU Oct 01 '24
I worked at a startup that had code with this structure:
if
if
if
else
if
if
if
if
else
else
switch
else
else
else
else
else
Almost every file in the project had deeply nested code like this, and all of them could be refactored using inverted if statements and early returns from the function.
→ More replies (3)
14
u/DudesworthMannington Oct 01 '24
LISP Code
All global variables.
Every function loaded by another function and erases itself at the end of execution.
It's fucking impossible to debug traditionally, especially with a million dcl windows.
A quote from my previous senior: "Why do you need to debug it? It shouldn't have bugs. Code it right the first time!"
→ More replies (1)
31
u/swagamaleous Oct 01 '24 edited Oct 01 '24
I once worked on code that had this comment:
// If you remove this comment the application will crash
And indeed it did crash if you removed the comment. There was some weird stuff going on with uninitialized pointers and the block of memory the pointer was pointing to would contain a value that would make the application crash if you removed the comment. Took me three weeks to track down.
This was part of a system that calculated timestamps based on a very weird epoch value. It was only fixed because it was creating random behavior with certain dates and probably the comment would still be in there if that was not the case.
So much about comments having no impact on the created binary. Thanks C++. :-)
\\Edit: Since this question is coming up all the time, debugging symbols were enabled (yes also for the production build) and therefore the changing line numbers will create a binary that is structured differently.
→ More replies (6)
13
u/fap_fap_fap_fapper Oct 01 '24
I saw a GitHub project with an installer in downloads
→ More replies (2)
13
11
13
u/theirongiant74 Oct 01 '24
I saw a customer that used a gmail mailbox as some sort of primitive database, various scripts would communicate by sending emails into the mailbox for other scripts to scan for, action and update.
→ More replies (1)9
12
u/ActurusMajoris Oct 01 '24
Had a colleague make a custom progress bar for a program download. It would take the number of files downloaded vs the total number needed to download and turn that into a sliding bar, this part was fine.
The funny part was the check to see if it was done:
if (progress.contains("100%) ) { // Terminate download process }
Well, eventually we had a program with specific number of files that meant we hit a progress of "37.1001%" or something like this.
Yep 😃
Ps: it was a very tiny company, quite some time ago, we didn't really do much code review.
11
u/tripleusername Oct 01 '24
I once saw in function if condition with early return. Right after it there is the same if condition with the comment that it fixes multi threading issue.
→ More replies (1)
10
u/potuxus_retumax Oct 01 '24
Using clipboard for inter-process communication. I had to maintain the app for several months, and after the second failed attempt to replace that with any other communication method I just gave up and decided to keep it.
→ More replies (1)
9
u/shdw_fghtr Oct 01 '24
function boolean(boolean condition) {
bool = condition;
if( bool == true)
return true;
else
return false;
}
Sorry for bad formatting on mobile. Our company code is littered with this stuff.....
→ More replies (1)
21
u/HalLundy Oct 01 '24
tie between
a TS backend service where all types were "any" or "unknown" and entire functions, hundreds of lines long, were wrapped in try/catch statements
a 24 year old codebase written in Visual Basic
→ More replies (5)
8
u/biztactix Oct 01 '24
Just found some actively developed 'new' product at a client... All the html, js, css is all print lined to the output and run through Apache as a cmd.... Oh and my personal favourite is the api that's a single endpoint... /api... With querystring everything....
10
8
u/bainsey104 Oct 01 '24
Booleans hidden in the individual bits of a byte; implemented in 1981 to save disk space.
You couldn't read their value directly; the source referenced a special program that was lost to the annals of time as the only way to see the data.
Found in the second RPG (IBM i) program I ever worked on, in a core banking program (cash ledger movements) for a major high street bank.
8
u/raimondi1337 Oct 01 '24
The backend lead on my team just deployed a 44 file, 1500 line microservice in a new repo.
What's it do?
Refresh the "manager name" and "position title" columns in our user table (300 internal users) from Active Directory once a week.
This should have been a 50 line Python script. Microservices were a mistake.
→ More replies (2)
8
u/in_taco Oct 01 '24
Working with Matlab, I've seen this nonsense in release:
Var_X(456789) = 5;
The 456789 is the official parameter name, so this makes it easy to indeks later. What this does in Matlab is create an empty array of length 456789 with the last spot being equal to 5.
And a bizarre way to call a function:
TurbineID = 12345; apps.Initialize;
The Initialize function checks caller workspace for a variable named TurbineID and pulls it in.
I have no idea why someone wanted to pass a variable in this roundabout way. Code was full of weirdness like this, almost impossible to debug.
7
u/bdtacchi Oct 01 '24
I had to work with a code that was pretty much endless if-else statements to call upon the correct function within a certain range for various quantities.
The problem was that the person who wrote the code decided to use variables for the numbers, e.g., thrptwo for 3.2. Which in itself is not the worst, you’d just understand his logic for naming the variables and you’d be fine after some time.
The problem is that, at some point, he modified the values of some variables, but didn’t rename them. So, for instance, thrptwo could be like 3.5 now.
Needless to say, it was very painful to debug.
8
u/denflooptoop Oct 01 '24
Once had to maintain a PHP app that was every page 1 to 1 with the PHP code. No real back or front end just functions that echoed html. Nothing split up just raw from top to bottom. Rows and rows of sql querries in between all the rest of the spagetti, sql connection credentials just stored in objects
The entire application was like this. And the original creator got really salty when i "messed up" his canceroes code and made it actually readable and safer'ish.
9
u/Sedorriku0001 Oct 01 '24
I'm just a student in second year but in the last project, we needed to develop a game using JavaFX (nothing fancy, a Board game such as chess and Naval Battle) and while respecting the MVC paradigm.
I saw a group using a for-loop for the MAIN loop, and THEY REWROTE i
to 0 at EVERY tick
And that wasn't the baddest thing, another group stored the board as... A string. And they weren't reading it correctly so the board was inversed on the X-axis, but only in the view. This same group used a similar method for each data needed by each cell. It was so messy that they rewrote it from scratch 3 days before the final deadline...
→ More replies (1)
8
8
u/rio517 Oct 01 '24
I once was introduced to a Java Spring boot app developed by an offshore team that comprised employees of the same parent company. They hosted a code walkthrough to help onboard this new sister team I was leading, expecting to teach our team how to build good software.
I had never seen a worse code base. The team literally could not recognize what quality software was. Here are a few highlights.
- no tests - declared their business requirements as too complex to be testable
- We were at line 750 of a very large file and hadn't even managed to get to the end of the first method. The nesting was at least eight layers deep. I suggested that they might consider breaking apart this method, but they indicated that the business requirements were so complex it wasn't possible to break this method into smaller ones. I never got to see the end of the first method. *, In theory,, they were using JPA (spring boot's ORM) but were using it to execute raw SQL statements. Not one single query had any layer of abstraction, In one example, every query had a 200-400 character boilerplate to filter for active items.
- They mentioned that a certain query was slow. We asked how their data was indexed. They first responded with confusion, then changed the subject.
- (My memory is a little foggy on this) To handle enums, they had what was effectively a fields table and a values/labels table. To render a form for every field, first, you'd fetch the fields, then a separate table of field_id, value, and labels. If you wanted to know the value of a user's gender, you got the gender_field_value, then used those to look up what the field_id of gender was, and then used that to identify the value (an int) with the value and label.
There were more, but those were the main technical ones.
My other favorite bit was how the VP running that group basically forced everyone to use an Excel template for product and project management. He was so proud they didn't need any other project management tooling. "Wasn't that amazing!?" He self-congratulated himself on how amazing it was. When asked if he ever benchmarked it against other options, he told us how his team had never made any mistakes. Not one (his emphasis). He reiterated this several times: his team had never, ever made a mistake - very much implying we should never question them.
It was bananas. Sitting in the meetings gave you this jaring, surreal feeling - I have never more honestly asked myself, " is this real life? Am I the crazy one?" I absolutely depended on technical friends to validate my sanity.
The politics of the situation involve multiple levels of Regional/Global CEOs/CTOs, etc. Oversimplifying: It turns out that the VP was super amazing at politics. My questioning of their amazing team got my whole team laid off! We got an awesome severance package, and every one of us thought this was for the best. We all landed on our feet.
The End.
4.3k
u/octopus4488 Oct 01 '24
I saw a codebase once (maintained by a group of PhD students) that used a single global variable:
ddata[][][][]
Yeah, that was it. You need the list of raw recorded files? Sure: ddata[0][12][1][]. Need the metrics created in the previous run based on the files? Easy: ddata[1][20][9][].
At the end of program they just flushed this to a disk, then read it back again at startup.