ID:2888915
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
Currently there is a lot of uses of lists as a data storage mechanism, where the list stores a fixed number of known attributes in specific slots in the list.

e.g as a synthetic example
#define X_POS 1
#define Y_POS 2
#define Z_POS 3

var/list/pos = list(mob.x, mob.y, mob.z)

and then you access data like so

var/direction = pos[X_POS] + pos[Y_POX]


This is essentially replicating the behaviour of a struct in other languages, and is used when we want to store data, but don't want the overhead of an entire datum or object, especially when the number of lists scale to hundreds or thousands in existence at a time.

If we could have a type that allowed us to syntactically sugar this it would be excellent.

e.g
/struct/pos
var/x
var/y
var/z

At compile time this would desugar into a array with numeric acceses as before.

The advantages are
1) clearer code for a better developer experience
e.g
var/pos/location = new pos(x,y,z)
var/value = location.x + location.y


2) you can ensure that only valid array indexes are accessed at compile time.
e.g location.fw would be a compiler error.

You can even optimise this further since it doesn't need to be a dictionary list and therefore can avoid the cost of the sorting mechanisms, this can simply be a straight up c array with 3 numeric indexes.
would personally love this
Ensuring valid array indexes has to be done at runtime as well, because of the fact that BYOND isn't strongly typed.