-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
capacity for seq and string #460
Comments
Since this probably yet another system.nim extension and it is rather rare to come up, can we name it |
Yes, makes sense, I do not have a suggestion about the naming. |
"space" and "room" might be short, whole word alternatives, but maybe they also get used in video games which, at one time, was a popular Nim arena. :-) (EDIT: but I don't think the name matters much. Transparency to better time/avoid allocations is a good thing.) |
Neither "space" nor "room" is as spot on as "capacity" is though. But of course, it's subjective. |
(I was just brainstorming - it's already been "*OfCap" forever which would be the strongest consistency argument in favor of just |
I'd stick to something related to "capacity". Whether it's the short form "cap" or the full word, I personally don't care too much though. |
related: nim-lang/Nim#19727 |
One thing to consider that came up with my work, is that when exposing internal state, like capacity to user code, is that when fuzzing code like that it would be impossible to correctly reproduce the conditions for a crash. That's because when copying or serializing the capacity is not saved. |
Abstract
Allow read-only access to
cap
ofseq
andstring
.The name is suggested to be
capacity
instead ofcap
.It is a very simple and tiny RFC.
Motivation
It is a nice information to design macros and metaprogramming,
like unrollings,
setLen
,newStringOfCap
,newSeqOfCap
, etc.len
andsetLen
ofseq
andstring
is usable, butcap
is not.Examples
I imagine something kinda like
(Pseudocode-ish)
Change would require 3 ~ 5 lines at most (?).
Before
cap
is not accessible, it is always unknown.This can not be implemented with third-party Nimble modules, in a non-hacky way at least.
After
myString.capacity
returns anint
with the allocated capacity.Backward incompatibility
No backward-incompatible changes, because it is a new proc.
The text was updated successfully, but these errors were encountered: