Why arrays instead of structs with non homogenous data?
Why arrays instead of structs with non homogenous data?
I've seen a lot of distro scripts use arrays instead of distro to store non homogenous data (such as a mobile reference, a string and an integer). This happens especially when passing variabiles with StartScript(). Shouldn't be better to pass a structure when the variables are non homogenous? Is there any precise design choice behind the use of arrays? Does it improve performance? Am I doing any mistake in using structures instead of arrays for non homogeneous data?
I think usually its just a preference. Pass it as an array because you can declare it like
array{ who, item, something }
then split it up into variables in the other script instead of
struct{ who := who, item := item, something := something }
and still breaking it up into variables in the other script since its a bit shorter to use...
array{ who, item, something }
then split it up into variables in the other script instead of
struct{ who := who, item := item, something := something }
and still breaking it up into variables in the other script since its a bit shorter to use...
I think also that it has been said many times that "the way to pass variables between scripts using 'startscript' is to store them in an array". In fact I had thought that was the only way until recently. I can't remember ever reading, atleast here on the forums, of anyone using a struct to pass them.
Ok, since noneone told me I'm a fool using a more complex structure rather than an array, I'll stay with structures, which I use with startscript whenever variabiles passed are non homogeneous. Maybe I'll stay with arrays even if variables are non homogeneous only in those rare cases where performance is critical
-
Marilla
heh.. to pile on; If you find that using a struct works best for you, then by all means, use them! My preference for arrays is due to what was mentioned above; ease of creating and passing an array. However, if a struct makes your code easier to read or understand, or just seems better to you, use it 
Yes, I find it much easyer to read, especially when the array is big after months it's hard to remember which index was what (or, one can add comments, but I prefere to have variables autoexplaining their meaning)
I asked onyl because I wanted to know if there is any relevant efficiency different behind that choice of if it's just a different style
I asked onyl because I wanted to know if there is any relevant efficiency different behind that choice of if it's just a different style
-
Marilla
There -might- be the most miniscule of effeiciency differences between the two. However, it's not likely to even be measurable unless we're talking really huge collections (array vs dictionary). Generally, indexing an array is faster than searching an index of a dictionary, but the difference is likely to be terribly small, unless you are talking about comparing an array or collection of hundreds or thousands of items in them.