Sabriath I think your missing the point. Sure, I could (and currentlt DO) achive structures in different ways - I use multiple arrays myself, but thats horrible, simply horrible. Wanting to use maps or lists for them is even nastier. Just because you CAN currently do it another way, doesn't mean it's any good.
I wasn't saying that because you can do it another way that it shouldn't be implemented...but what I said was that the underlying performance used on a ds_list will be virtually the same exact thing as adding structures without methods. Unless you plan to revolutionize the way GM does it's variables, I'm looking at it from the standpoint of structures being nothing but an object that is not placed on the event queue. This means that variables can be "created" on the object by adding it to the name map, and when reading the value, it searches the map for name->pointer and returns the GMVALUE for it.
Compare that to a ds_list, which is exact in its nature of WHICH element you are choosing and updating, which means you go from a O(log) to an O(1) method of search. The downside is that you must read and write separately (so you cannot do += ), so other than the ease of the eyes for source code, I am not seeing how performance will be improved on the matter.
As to not defining them in code... Well, I've yet to see any evidence to it being inconsistent with the rest {of} GML, {particularly} if we allow scoping (instance, var and global), in which case it's the same as everything else. However, like any new feature, you won't have to use it until you see a {benefit} yourself.
The benefits of using a ds_list outweigh that of the hypothetical structure (in performance) that you are suggesting based on the assumption of your remark of:
So... while structs do behave somewhat similar to objects/instances in terms of storing data, you won't have functions/events associated with them, and they will use far, FAR less memory.
I also strongly disagree it's a bad thing to teach. I learnt it back in assembler days because it gave me some serious felxibilty into how I visualised my data. Part of the problem with most folk these days is they don't "really" know how data is stored, and as such they waste LOADS of memory, and hence speed. Memory bandwidth is a killer, and if you don't know your data, your burning performance. Classes (and objects) hide a lot of sins, simple structs let you fine tune your data. So just like your ds_map example, your hiding lots of issue, and just assume it should run quickly and be memory efficient. This is hardly ever true.
I never said that 'structures' were a bad habit to teach...what I said was 'implementing structures in function code' is a bad habit to teach. Obviously structures are an almost necessity in programming, but putting it in GML forces the interpreter to run over the structure before it builds it in memory...which means it is no longer seen as a resource (and from what I can envision, cannot be exported/imported). I am only suggesting that it be initialized separate from GML coding styles.
However, since most of how GM works is self-interpretive (execute_string/file/etc.), here are some added ideas to make structures code in GML (similar to how object_add works):
stats = structure_create();
structure_add_variable(stats, "experience", 0);
structure_add_variable(stats, "nextexp", 100);
structure_add_variable(stats, "level", 1);
structure_add_method(stats, "gain", "experience += argument0; if(experience >= nextexp) level += 1;");
PlayerStat = stats.new();
PlayerStat.gain(104); //yay, level up
So until someone gives me a hard and fast reason as to why we shouldn't (like the Mac issue), I don't see any reason not to add it....
I never said you _shouldn't_ add it....I'm clarifying my suggestion that you should change _how_ to add it.
Because they wouldn't be structs anymore, they'd be classes. And that's a considerably more complex kind of entity, especially when it comes to scoping variables and methods, or when features such as inheritance are introduced.
Structures, enums, and even unions can have methods....it is not limited to classes.
Edited by sabriath, 06 February 2011 - 11:59 PM.