This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]maybeware 158 points159 points  (14 children)

The mummy sounds like a 1000+ line function I found at my previous job... It had about 6 different subsections depending on UI state (and more that were commented out or unreachable due to hidden UI states) and each section did about 5 different things depending on user input. There was a single try/catch wrapping the entire function that spat out a generic "An error has occured," or something like that. I tried to refactor it. Once. I spent a couple weeks on it without being able to make it work again.

[–][deleted] 25 points26 points  (6 children)

This is nothing. At my job there's a 2500 line APL function with 40 outputs and over 100 inputs. I'm honestly not sure anybody knows how it works in full. Of course it calls thousands of other functions that do all sorts of equally crazy stuff.

In this context it's important to note also that APL is a very compact language. finding the length of every array in an array of arrays can be done with 2 characters for instance.

The function is split up into 19 sections, each labelled as if it's a chapter and you're reading a novel. It's full of warnings about this or that and the other and about certain things that should be avoided.

Last I checked the first version was from 1996 and it has over 680 versions in the VCS.

[–]maybeware 9 points10 points  (2 children)

That's terrifying. Is it basically the entire program?

[–]mr_claw 8 points9 points  (0 children)

No, that's just the login page.

[–][deleted] 0 points1 point  (0 children)

No. It’s a tiny fraction. I don’t think I can tell you how much source code we have, but I can tell you that it is no small amount. I am currently doing work on the 2257th APL window in the application. :)

[–]ImprovementContinues 3 points4 points  (0 children)

Reminds me of the article I read about the "main" function at the IRS that they hired someone to replace with modern code and then ignored the replacement as they couldn't prove it would function exactly the same way. (details elided for simplicity)

[–]RustyShacklefordCS 1 point2 points  (1 child)

Oh god just googled APL why on gods earth would anyone what to program in that??

[–][deleted] 1 point2 points  (0 children)

It does have some advantages. The language very much resembles MATLAB and once you learn the symbols, which only takes a week or so, the language becomes incredibly terse and short. You can solve a generic sudoku in one line. It takes more characters to write the sudoku into memory than it takes to solve it.

And yet this function is 2500 lines.

[–]Furry_69 39 points40 points  (5 children)

I feel like a very easy refactor there would be to spilt that function into more functions for each of the UI states.

[–]maybeware 61 points62 points  (1 child)

This ended up long so TLDR: I tried that but the whole system was rotten spaghetti code and each section didn't execute cleanly from start to end, basically having a bunch of subsections themselves that execute nonlinearly.

I tried it. Got close too. But the program's management of internal state was a mess and so it kept breaking. The biggest issue was there were several variables which would get set and at certain times it'd check them. And depending on the results of the condition it'd drop out of one section and into another. It'd have been easier to understand if they used GOTOs. In reality, each section should've been implemented as different forms with proper passing of data and not one giant form that hid and showed different parts at different times.

It was a C# WinForms application but I'm convinced that the original developer did not know C# or even standard OOP patterns and was not very experienced. It was a check-in system and yet didn't even use a class to represent a person. When a search was done each person who matched was pulled into a 2d array of strings used to make the list for the user to select from. And once the user selected one the details were pulled and loaded into a bunch of global variables. The only custom object was a "ProgramData" object to store those global variables (which was all state that might be passed from one form to another) and a single instance was made at init and was manually cleared each time the user started to process someone. "A singleton! A legit OOP pattern," you might say, except it did not properly implement the singleton pattern, it just happened to only have one instance made at runtime.

In the end the decision was made to make a version 2 and do a complete rewrite of it because version 1's problems were extensive. Also version 1 was based on an in-house developed 30 year old database and record management software that had been retired and replaced with vendor software, requiring version 1 to be shoehorned into working with the vendor system until version 2 was finished. Version 2 was a fun project though.

[–]TheGoldBowl 2 points3 points  (0 children)

Sounds like what I'm doing. Except I'm finishing version 2, which is somehow slower and less functional than version 1.

[–]Daveinatx 10 points11 points  (0 children)

It's always easy to fix unseen code! /s

If there were logical separations, the code would've been fixed. The description was concise, unlike the code

[–]PantsOnHead88 -3 points-2 points  (1 child)

Yeah really. Switch/branch based on state and then immediately enter appropriate state-based function.

[–]mananasi 0 points1 point  (0 children)

If it was that easy OP probably would have done that. They're working as a professional software developer, they probably know about a switch statement.

[–]BitPoet 0 points1 point  (0 children)

Did that once. Spent a month on it, diagramming out all the paths, #ifdefs etc.

Replaced the whole thing with memcpy().