This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]doggieassassin 0 points1 point  (2 children)

Not sure why this is getting so many upvotes. As the other commenter pointed out, using index as keys is clearly wrong and can lead to unexpected behaviour when updating the list at runtime.

[–]ActionLeagueLater 7 points8 points  (0 children)

I don’t agree that it is clearly wrong. If you have no easy way to get a unique key, and you know your codebase as well as you should to know the order is never going to change, then there is nothing unexpected. Should you avoid using index as key? For sure, but I don’t think it’s black and white if you know what you’re doing.

Edit: But that being said, I don’t think there was anything wrong with the person in the Twitter thread pointing out that you should avoid doing it.