Replies: 2 comments 2 replies
-
|
Also as a newbie, if I were to encounter this line from the FAQ: This is just impossible to parse and figure out how long the slice is if I haven't committed to memory that "colon means len, two dots means end, or perhaps this is a bug and should be the other way around. Who knows?!". |
Beta Was this translation helpful? Give feedback.
-
|
They are mostly for different uses. The range syntax is predominantly used for ranges outside of slices: switch (foo)
{
case 2..5: io::printn("2-5");
}In this case we want an inclusive range. Similar with designated initializers: int[5] x = { [2..3] = 4 };However, once we slice, then We can note that switch (foo)
{
case 2:4: io::printn("2-5");
}
int[5] x = { [2:2] = 4 };I can only draw the conclusion that there is no way to make this more welcoming to users and it's an irreducible complexity. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
If I didn't catch this note in the FAQ, I wouldn't have noticed a possible bug in my code where I expected
[start:end]as it is in many languages (Python & co.) rather than[start:len].Either one is fine, but having both syntaxes, which are both commonly used, doing wildly different things and thus potentially causing hard-to-track-down bounds errors is a recipe for disaster.
Beta Was this translation helpful? Give feedback.
All reactions