Subscript operator for vectors

Discussion about recent product features & solutions!
Search

Post Reply
1 post • Page 1 of 1
dvribeira
Posts: 8
Joined: Mon Mar 18, 2019 10:53 am

Subscript operator for vectors

Post by dvribeira » Thu Oct 10, 2019 6:51 am

So I have been playing quite a bit with the new CONTROL features of P013 and I wanted to bring this to your attention. Up until now, all the containers subscript operators in control script where 1-based, meaning for instance that mylist[0] would be out of bounds. When the new vector type was introduced with P013 and with no comment on the documentation on the contrary, I was assuming it would also be 1-based, but surprise: it is 0-based.

I understand that this might be because the underlying language is of course 0-based as well. And of course I would have been happy as well if the old containers would have been 0-based. But the problem is that with this choice now we have a set of containers that are 1-based (all the dyn_) and one that is 0-based. This will undoubtedly make the use of the subscript operator more prone to errors and the review of code more cumbersome (now you need to know the exact kind of container just to know if it is 1 or 0 based, which might even get more cumbersome if you're using the new using feature for type alias). Since this was introduced in the last patch, there is for sure still a tiny code database making use of vectors, so it would still be feasible to change this to be 1-based for coherency.

Example:

Code: Select all

    vector<int> list;
    list.append(1);
    list.append(2);
    DebugN(list[1]);
    dyn_int list2;
    list2.append(1);
    list2.append(2);
    DebugN(list2[1]);
This will print:

Code: Select all

WCCOActrl2:[2]
WCCOActrl2:[1]
I know the subscript for string was also behaving differently, but you don't (usually) exactly use a string the same way you use the other containers...


I guess these things have been already considered and I might be missing sth, but just in case I wanted to give my 2 cents and would be interested in hearing the opinion of developers or other users on this subject.

Kind regards,
Daniel

Post Reply
1 post • Page 1 of 1