3 ms·
@int_19h, @xigoi perhsps you're right but how many times have you ever indexed backwards? Other, I grant, than to get the last item in a list. If it's more gene
by _a_a_a_ 4y ago
@int_19h, @xigoi perhsps you're right but how many times have you ever indexed backwards? Other, I grant, than to get the last item in a list. If it's more general then reversing the list would be better, alternatively you might have
lst.reverse()[x]
which the compiler could guasrantee to recognise and simply implement as a calculation.
- int_19h 4y agoWell, I write plenty of Python code, so it actually comes up quite often. The annoyance with Python is that it just treats negative values as magic, so if you accidentally end up with a computed negative index, it silently does the wrong thing. But the alternative approach with explicit index-from-end syntax - whether like in C# and Nim, or like Julia and Matlab - doesn't have that problem; it's pure convenience. And yes, of course, you can always do the same in some other, more verbose way. But why should we tolerate that verbosity when there's a solution that makes code both shorter and more readable? I rather hope that more languages will adopt one of these techniques.
- _a_a_a_ 4y ago(per your other posts, extension methods is their name. And they aren't supported here, got it). > it silently does the wrong thing yeah, my original complaint was this > why should we tolerate that verbosity when there's a solution that makes code both shorter and more readable? Because it's a balance. How much it benefits how many users to what degree vs. extra cost of implementation and maintenance. If you're not careful you go down the kitchen sink road and end up with bloat. Be careful when adding stuff cos you have to support it forever. Anyway, thoughtful answers thanks.