Cleanest way to write logically procedural software in an OO language

I'm an electrical engineer and I don't know what the hell I'm doing. Please save the future maintainers of my code. Recently I've been working on a number of smaller programs (in C#) whose functionality is logically "procedural". For example, one of them is a program which collects information from different databases, uses that information to generate a sort of summary page, prints it, and then exits. The logic required for all of that is around 2000 lines. I certainly don't want to stuff all of that in a single main() and then "clean it up" with #regions as some previous developers have been doing (shudder). Here are some things I have already tried without much satisfaction: Make static utilities for each coarse bit of functionality, e.g. a DatabaseInfoGetter, SummaryPageGenerator, and a PrintUtility. Making the main function look like: int main() { var thisThing = DatabaseInfoGetter.GetThis(); var thatThing = DatabaseInfoGetter.GetThat(); var summary = SummaryPageGenerator.GeneratePage(thisThing, thatThing); PrintUtility.Print(summary); } For one program I even went with interfaces int main() { /* pardon the psuedocode */ List toDoList = new List(); toDoList.Add(new DatabaseInfoGetter(serverUrl)); toDoList.Add(new SummaryPageGenerator()); toDoList.Add(new PrintUtility()); foreach (Function f in toDoList) f.Do(); } None of this feels right. As the code gets longer, both of these approaches start to get ugly. What's a good way to structure stuff like this?

Feb 3, 2025 - 05:06
 0
Cleanest way to write logically procedural software in an OO language

I'm an electrical engineer and I don't know what the hell I'm doing. Please save the future maintainers of my code.

Recently I've been working on a number of smaller programs (in C#) whose functionality is logically "procedural". For example, one of them is a program which collects information from different databases, uses that information to generate a sort of summary page, prints it, and then exits.

The logic required for all of that is around 2000 lines. I certainly don't want to stuff all of that in a single main() and then "clean it up" with #regions as some previous developers have been doing (shudder).

Here are some things I have already tried without much satisfaction:

Make static utilities for each coarse bit of functionality, e.g. a DatabaseInfoGetter, SummaryPageGenerator, and a PrintUtility. Making the main function look like:

int main()
{
    var thisThing = DatabaseInfoGetter.GetThis();
    var thatThing = DatabaseInfoGetter.GetThat();
    var summary = SummaryPageGenerator.GeneratePage(thisThing, thatThing);

    PrintUtility.Print(summary);
}

For one program I even went with interfaces

int main()
{
    /* pardon the psuedocode */

    List toDoList = new List();
    toDoList.Add(new DatabaseInfoGetter(serverUrl));
    toDoList.Add(new SummaryPageGenerator());
    toDoList.Add(new PrintUtility());

    foreach (Function f in toDoList)
        f.Do();
}

None of this feels right. As the code gets longer, both of these approaches start to get ugly.

What's a good way to structure stuff like this?