In bracket notation negative indexing is not possible but using at method you can easily navigate to the last index of array. It's just another way to access elements.
Which will be largely irrelevant to the vast majority of people. I bet you do a ton of stuff in your code which will be more inefficient than this (not judging, it's the nature of high level languages).
Readability > performance, true for 999/1000 use cases (probably more).
To put it in perspective I was playing around with how efficient I could make FizzBuzz, for no reason what-so-ever. I had to calculate it for the numbers 1 - 1 000 000 000 to get meaningfully measurable time period (1.9 seconds) to try to optimise. I got it to about 0.85 seconds!
1 second saved, over a billion operations. Don't worry about performance until your app is slow, then look at your API calls before you consider anything else.
28
u/HyerOneNA Oct 26 '21
Why use the at method when you can just use square bracket notation?