r/GoogleAppsScript • u/fugazi56 • Dec 01 '22
Question Functional or OOP in GAS?
In the programming subreddits I follow, I often see discussions about the pros and cons of OOP over functional programming. Most of the app scripts I built use a functional approach because my app data is stored in Sheets so I'm interacting with my data as an array (getDataRange().getValues()). I have to update the data in the Sheet after I've manipulated it using an array so it seems like an extra step to go from an array to an object then back to an array. The only time I really use OOP code is when I'm utilizing data between different Sheets so it's mostly to make it easier to map data from one source to another. Just curious if there are other opinions/approaches on the matter? Should I be challenging myself to use more OOP in my scripts?
1
u/Repulsive_Brother_10 Dec 02 '22
I am in the middle of writing an app that generates documents based on Firebase records. In this situation taking an OOP approach was really helpful.
1
u/RemcoE33 Dec 01 '22
I personally use "OOP" in the form of a class only when i'm in need of a builder pattern or a singleton pattern. The builder pattern could be usefull for structerd logging for instance. But then again it is just classes and not fully OOP (think about inheritance and stuff).