https://kotlinlang.org logo
#announcements
Title
# announcements
a

Andrew Gazelka

06/09/2019, 3:35 PM
let's say I have a config which has several values with several variables
Copy code
a,b,c,...,z
Let's say I have a complicated algorithm/function sequence which I want to break up into smaller unit testable functions. Each function takes a subset of config values and some calculated values (by previous parts by other functions)... this can get pretty annoying as each time I pass arguments into a function I have to pass in a ton. It would be nice if Java/Kotlin supported something like in TS where I can have an interface for some JSON and any JSON which had the proper fields and types would be allowed... this would allow for just passing in the entire config as an argument (or if I am unit testing passing in a subset of the config if needed). I am almost certain there is not a good solution to this in Kotlin/Java, but do you think there is one? I guess you could pass in a map as a parameter but this would not be compile-time type safe ... additionally, nested functions in Kotlin could be nice but the issue with them is that they are impossible to unit test. Thoughts?
s

Shawn

06/09/2019, 6:20 PM
well, do you have some kinda config class? a constructor w/ defaults might be at least kinda closer to what you’re asking for
a

Andrew Gazelka

06/09/2019, 6:21 PM
yes I have a config interface
I guess I can just have defaults for all of the values
like you mentioned... think that is the best way to go around it?
2 Views