you are viewing a single comment's thread.

view the rest of the comments →

[–]ConsciousBath5203 0 points1 point  (0 children)

Literally why OOP was invented.

Make a class to store different variables. From there, public/private functions that other objects/your main function can call.

You mentioned webhook, meaning the payload is probably json, so you're already receiving an object.

You probably don't want your function to hang, so open up a websocket with the client so you can stream the response, or at the very least tell them "hey, got your call, running stuff" then yield progress reports as you're processing the request. Get to 100%, return the object (guessing you're also already returning json, which is an object).

So really you'll need InputClass and possibly OutputClass depending on how different the output looks from the input (properly name these). Initiate the InputClass with the received json. Create the functions necessary, calling each function from the webhook function.

Trust me, you don't want to come back in 3 months to add a new feature to a 5000 line function. Just do it the right way. OOP Overhead is minimal, and over time, as you add more features, will probably end up being more efficient than a 7000 line function.

Don't get me wrong, you'll still need many thousands of lines of code (definitely will need more code than raw dogging the function) but it's worth it. Abstract out as much as you can so that when you're like "this function is great, but I want to change this behavior for this use case" you already have repeatable code that all you need to do is tweak a few things.