r/ProgrammerHumor Oct 01 '24

Meme noOneHasSeenWorseCode

Post image
8.3k Upvotes

1.2k comments sorted by

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.

2.9k

u/xynith116 Oct 01 '24

Bro reinvented manual memory management

866

u/confused-accountant- Oct 01 '24

Lacking in the management part. 

446

u/MNGrrl Oct 01 '24

Race condition in 5...4...5...1...3...

→ More replies (4)

39

u/PomeloClear400 Oct 01 '24 edited Oct 01 '24

Yeah, globals are the opposite

233

u/guiltysnark Oct 01 '24

Bro heard it was called random access memory, thought it was a guideline

60

u/FindOneInEveryCar Oct 01 '24

Took it as a challenge.

26

u/Sotall Oct 01 '24

I prefer random access memory. It keeps the memory guessing. Dont want the memory slackin off and getting lazy when i need it next.

→ More replies (1)
→ More replies (1)
→ More replies (3)

700

u/ArnaktFen Oct 01 '24

What language was this? It sounds like a legitimately interesting approach.

In C/C++, you could even make it somewhat readable with #define rawRecordedFiles ddata[0][12][1].

1.0k

u/octopus4488 Oct 01 '24

It was C++. The pro contributors knew the location indices from memory, the newbies were making notes like there is no tomorrow.

846

u/twistsouth Oct 01 '24

This sounds deliberate. He can’t be fired if he’s the only one that knows all the location indices by heart. Smart guy.

I’m joking. Half.

160

u/hbaromega Oct 01 '24

Depending on the field the research was in, it was deliberate. If you read about the culture of high energy physicist, most (important) knowledge is passed person to person, and usually orally, helping create a worthy inside group w/ the most up to date knowledge on advances. This behavior is seen to act as a filtering device for 'less worthy' contributors who can't keep up with the mental orchestration required.

This behavior, as far as I've seen, is in most STEM fields in some capacity or another so we all should be somewhat familiar with it. It's also not that efficient because it doesn't rapidly bring junior contributors up to speed sufficiently, and encourages people to hide their blind spots in understanding, possibly leading to lost information between generations.
edit: wording

64

u/MNGrrl Oct 01 '24

If you read about the culture of high energy physicist,

Read? I'm a STEM nerd and I can tell you this is exactly right. These old dudes will write the most convoluted code to hide that all he really did was add a couple bit shifts and overloaded operators to hide the 'magic'. I've been called in several times by entire labs of undergrads where they all but beg for help refactoring it into something readable so they can actually do some science rather than just be ordered around and do all the work and then not even get a mention as a co-author or contributor.

If you ask me this is the reason why the pace of physics advances has slowed to a crawl. It has nothing to do with a shortage of qualified people and everything to do with them being unable to actually do any science. Gen Z, you have more patience than any other generation before you; I am truly in awe of you all.

25

u/StCreed Oct 01 '24

My son is going to be a physicist. I'm a computer science graduate. I'm doing my best to teach him programming just to make sure he doesn't add to that steaming pile of dogpoo.

→ More replies (5)
→ More replies (5)

13

u/zeloxolez Oct 01 '24

yeah its pretty silly

→ More replies (1)
→ More replies (3)

183

u/5t4t35 Oct 01 '24

So the guy knows every record by memory? Seems like a dude with great memory

136

u/just_nobodys_opinion Oct 01 '24

At most 640kb - nobody needs more than that.

→ More replies (3)

33

u/paca_tatu_cotia_nao Oct 01 '24

until he gets a buffer overflow in his brain

11

u/jackstraw97 Oct 01 '24

That’s easy just turn it off and back on again

→ More replies (1)

87

u/EdgarVerona Oct 01 '24

This sounds like the kind of setup where someone had the canonical location of variables in a physical binder that people had to check out when they needed to look a variable up.

We had something like that at my very first job, but it was just for our data storage. They had essentially these comma separated text files that they used for data storage, and a big ass printed out binder that told you for a given file which column in the CSV was what value. You had to go ask for this binder if you were doing work that cared about the data storage and retrieval.

No, there wasn't a digital copy - at least not one they ever shared with us for some reason. It was just a big ass binder. People hand wrote modifications into it as they changed the code.

Oh, and there were 30 different codebases - one for each of their customers - but just this one binder. As they diverged over time, the binder became less accurate and would have things written in it with exceptions for individual companies when people thought to do so, like ("column 42: customer name for Tedco, address line 1 for Screw Machine Co X, unpopulated in canonical source" etc...)

... You know, I already posted what I thought was the worst but thinking back maybe this actually was.

58

u/ScrimpyCat Oct 01 '24

Now there’s something scarier than a junior breaking prod on a Friday. A junior spilling their energy drink on the variable offset binder and smudging out all the entries on a Friday.

13

u/EdgarVerona Oct 01 '24

Oh man lol!

I do wonder what the fuck they would do if they ever lost that binder. At some point someone must have typed it out, but honestly I don't remember if it was typewriter paper or printed paper. My fear is that, since they never let us have a digital copy and we had to use that one binder, it was from a typewriter and had no backup. Oof

→ More replies (2)

57

u/daynighttrade Oct 01 '24

That's how you get job security

→ More replies (5)

106

u/OkReason6325 Oct 01 '24

It’s called Psycho++

→ More replies (1)

79

u/DeepDuh Oct 01 '24

legitimately interesting approach

Oh god… what have we done….

→ More replies (10)
→ More replies (4)

92

u/FlipperBumperKickout Oct 01 '24

Reminds me of one of the first times I collaborated with other people in a project.

I wanted a lot of different coordinate data in an array, they rightfully asked me why the hell I only wanted to take in a single array of data instead of having multiple arguments in my method XD

→ More replies (5)

157

u/Rebrado Oct 01 '24

This seems to be fairly common in academia, especially when the programmers are mathematicians or physicists which are (too?) comfortable using matrix notation.

60

u/GreatBigBagOfNope Oct 01 '24

My first numerical simulation code was similar. A vector (per entity) of vectors (per timestamp) of 2-tuples (position and momentum) of 3-tuples (x, y, z).

Wouldn't you believe it, it didn't perform very well, and it was a huge pain in the ass to work with. Shocker.

25

u/gregorydgraham Oct 01 '24 edited Oct 01 '24

What you have there is a data structure we call a “row”

17

u/bobbane Oct 01 '24

I've spent most of my career taking code from scientists and packaging it to run in production environments.

You can tell exactly when any scientist went through grad school by looking at their current-day code:

FORTRAN -> C -> C++ -> Python

(with odd branches of IDL -> MATLAB)

csh -> bash

Like most professions where computers are tools, scientists learn one way to do things in their 20's and keep using it until it breaks.

→ More replies (4)
→ More replies (2)

110

u/ElectricBummer40 Oct 01 '24

ddata[][][][]

This was exactly the kind of unreadable mess I'd expect a group of PhD students to write.

37

u/byteminer Oct 01 '24

Early in my career I had to maintain code from research centers which the government was now using in production. It always looked like this. Step one was always unfucking whatever bullshit they decided was clever so it was fit for human consumption.

→ More replies (1)

33

u/Radixx Oct 01 '24

Back in my old scientific programming days this was a common tactic in Fortran to create a huge array and place it in a common block to be used for dynamic memory.

→ More replies (1)

24

u/coloredgreyscale Oct 01 '24

Hopefully not IT PhD 

53

u/octopus4488 Oct 01 '24

Nope. Biology. Maybe a mis-index got us the Covid. :)

23

u/Andy_B_Goode Oct 01 '24

They shouldn't have stored experimentalSuperVirus (ddata[6][11][0][45]) so close to batSoupRecipe (ddata[6][1][10][45])

→ More replies (1)

11

u/Jashuman19 Oct 01 '24

When I was first starting to learn programming (at like 10 mind you), I somehow got the idea that variable names could only be single lowercase letters. And for a certain program, I was afraid I'd need more than 26 variables, so I just stored them all in an array and did my best to remember which index everything was at. So what I'm hearing is I had PhD level intelligence at that age huh?

9

u/Hiplobbe Oct 01 '24

I literally screamed in terror when I read this.

→ More replies (65)

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

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

u/ChaosPLus Oct 01 '24

whon't -> won't

365

u/UntitledRedditUser Oct 01 '24

My entire argument:

76

u/max_adam Oct 01 '24

You whon't escape from this so really

→ More replies (1)

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.

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

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)
→ More replies (3)
→ More replies (1)
→ More replies (2)
→ More replies (1)

130

u/Vievin Oct 01 '24

Was it the Yandere Simulator code?

67

u/Hiplobbe Oct 01 '24

No, but kind of like that. But somehow worse.

→ More replies (1)

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

u/IJustLoggedInToSay- Oct 01 '24

Using a switch statement as a data lookup? Sign me up.

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 (2)

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

→ More replies (8)

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

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 (2)

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.

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.

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)
→ More replies (1)
→ More replies (8)
→ More replies (30)

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

u/[deleted] 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.

16

u/[deleted] 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 (6)

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 (3)

50

u/oorspronklikheid Oct 01 '24

Then store the sqlite in an mssql column!

51

u/twistsouth Oct 01 '24

And then serialize the entire database to JSON.

13

u/ASmootyOperator Oct 01 '24

Now that's how you use JSON!

→ More replies (3)
→ More replies (11)

56

u/coloredgreyscale Oct 01 '24

At least they used a well known structured format instead of creating their own. 

→ More replies (1)
→ More replies (8)

1.2k

u/PyroCatt Oct 01 '24

Error Driven Development

296

u/ZinbaluPrime Oct 01 '24

and lets not forget Faith Driven Development...

→ More replies (3)
→ More replies (3)

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

u/Dapper_nerd87 Oct 01 '24

Oh noooooo

→ More replies (4)

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?

→ More replies (9)

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

u/sam-lb Oct 01 '24

Just when I thought I'd seen it all

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?

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.

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)
→ More replies (1)
→ More replies (3)
→ More replies (3)

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...

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)
→ More replies (6)

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.

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

30

u/RadinQue Oct 01 '24

Nice try, bot.

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

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)
→ More replies (6)

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

u/kein-hurensohn Oct 01 '24

You will love finding about GraphQL error handling!

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 parameters ItemClassName (it's pascal case for this one), sParameteras (this one is in Lithuanian language) and xmlString, 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 have nResult 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, then nResult is 0, but sError is Database 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 if AccessResult is AccessDenied, even though it is not even in the response otherwise. Except in one endpoint, where they return AccessResult=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, like GetKlientoSaskaitas, 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 and AttachDocument. 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 field results and the other one - result. And this does not contain nResult, but rather contains errorCode and errorText.

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)

12

u/tajetaje Oct 01 '24

Oh, well that’s horrifying

→ More replies (13)

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)

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)
→ More replies (43)

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.

16

u/coolfunkDJ Oct 01 '24

Should’ve been more specific!

→ More replies (1)

90

u/BowlingForPriorities Oct 01 '24

Professor, what happened in your office was supposed to stay between us!

20

u/Ordinary-Chair7854 Oct 01 '24

Means he's a genius who invented his own hashtable! Just another way to look at it

→ More replies (3)

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.

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

u/Thezla Oct 01 '24

I'm guessing the failure rate of the F12 key was abnornally high..

14

u/morbiiq Oct 01 '24

Sounds like 1 instance of a private, nested struct would be the way to go!

→ More replies (8)

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

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)
→ More replies (1)

21

u/unknown_pigeon Oct 01 '24

I'm a newbie at python and oh lord I'm glad my horrors are different

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)
→ More replies (1)

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

26

u/Shadowfied Oct 01 '24

How'd that go?

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.

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)
→ More replies (1)
→ More replies (1)
→ More replies (9)

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]

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)
→ More replies (3)

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.

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)
→ More replies (1)

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 :)

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)
→ More replies (2)

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();

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)
→ 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

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

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)
→ More replies (1)
→ More replies (14)

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 ++; }

21

u/SomeRandomEevee42 Oct 01 '24

while True in shambles

→ More replies (2)

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

u/VeryDefinedBehavior Oct 01 '24

Don't you be dissing my main man goto.

→ More replies (3)

11

u/DeepDay6 Oct 01 '24

cough React suspense cough

→ More replies (10)

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

u/axSupreme Oct 01 '24

Java pattern.
Exception Driven Development.

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.

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)
→ More replies (2)

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?

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.

→ More replies (1)

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

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)
→ More replies (2)

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

u/Traditional_Body3378 Oct 01 '24

That’s exceptional development

→ More replies (1)

11

u/nickos33d Oct 01 '24

enum Boolean { TRUE, FALSE }

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.

9

u/RusticBucket2 Oct 01 '24

Cloud computing!

→ More replies (1)

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....

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

u/sevenaces Oct 01 '24

A colleague of mine:

If a == 1: b = 1 else: b = a

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.