Hi…
Certain behaviour in my application is defined by the contents of my JSON file and I am wondering whether anyone has recommendations on how I should implement this…
Here is an example of some JSON from my application
"effect_fortitude": {
"type": "MyApp.Modifier.Health",
"params": {
"health_property": "intestinal_fortitude",
"transition_type": "linear",
"start_time": 0,
"end_time": 4000,
"relative_amount": -10
}
}
Currently, my module looks like this
defmodule MyApp.Modifier.Health do
def execute(health_property, transition_type, start_time, end_time, relative_amount) do
#do things here based on the parameters
end
end
But I have been doing some more reading around using Keyword lists as the optional parameters that can be passed to a function.
I can see pro’s and con’s of doing it either way.
For example, by taking a keyword list, down the track, I might be able to better handle changes to my JSON schema, for example, I might add a new property to the params “max_amount_of_damage”. By using keyword lists, I wouldn’t have to change the arity of the function and could handle it accordingly. That said, I would probably need to update the inner workings of my execute() function
The other approach I see working (if I keep it like I have it now) is that if the JSON schema changes, I simply refer to a different module in my JSON, e.g… MyApp.Modifier.HealthVersion2 which might keep my code better organised and avoid conditions in my execute() function calls if I went the Keyword Lists route…
Has anyone done anything similar and had success or failure?