2 ms·
> this style of "parallel arrays" was seen as a scripting-language wart It was only a wart because they didn't support compound types at all (and in some cases
by dspillett 13y ago
> this style of "parallel arrays" was seen as a scripting-language wart
It was only a wart because they didn't support compound types at all (and in some cases they did support compound types but people were not taught them when moving to a better language and kept their old techniques). It is compounded by the fact most scripting languages are untyped, so structure packing (the main justification for using arrays like that in more modern languages (for general memory use, stack size, or cache-hit optimisations)) isn't nearly as relevant.
Basically if you see parallel arrays used without a comment stating that it is done for packing reasons or similar, it is there either because the language does not support compound structures well or because the programmer knew no better. In a language where structure packing can be useful, it is a perfectly valid optimisation (though for small data not in tight loops, it may be an optimisation too far).
- dllthomas 13y agoIt's also worth noting that it comes at a cost of locality for an individual row, so isn't always an optimization.