Closed
Description
When applying the index or slice operations on a string/array/slice allow the keyword len
inside the brackets. In that case len
will mean len(a)
where a
is the referred string/array/slice variable before the brackets.
For example, if s is of string/array/slice type:
s[len-1]
will be exactly the same ass[len(s)-1]
s[len-5:len-2]
will be exactly the same ass[len(s)-5:len(s)-2]
Pros:
- Readability, specially when the variable name is long.
- Does not add any new keyword to the language.
Cons:
- Will break programs that use
len
as variable name.
Related issues: