Zig: Add a method to return length of ArrayList

Created on 22 Jun 2020  路  3Comments  路  Source: ziglang/zig

Previously there was ArrayList.count() (removed in c3d8b1f) and then ArrayList.len (removed in dd570db). ArrayList.items.len is now the way to determine the number of items . I'd prefer a count() method; it could simply return items.len just like the previously removed count().

proposal standard library

Most helpful comment

I think that would violate the "only one obvious way to do things" point of the zig zen. I personally don't see what's wrong with using items.len, having a dedicated method to access this value seems like a pointless abstraction.

All 3 comments

I think that would violate the "only one obvious way to do things" point of the zig zen. I personally don't see what's wrong with using items.len, having a dedicated method to access this value seems like a pointless abstraction.

I'm perfectly fine with that but this must eventually be properly documented. Knowing that ArrayList has an internal slice called items is not obvious unless you read the source.

Edit: To further clarify, it could be viewed as a leaking implementation detail and requires a stable implementation.

items is part of the API. It is not an internal implementation detail.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zimmi picture zimmi  路  3Comments

daurnimator picture daurnimator  路  3Comments

jorangreef picture jorangreef  路  3Comments

andrewrk picture andrewrk  路  3Comments

jayschwa picture jayschwa  路  3Comments