May 21, 2015
MarkBernstein.org
 

How Not To Crash

A series from Brent Simmons on How Not To Crash. Part 2: don’t enumerate mutable collections, because no one’s that smart. Good advice.

Obviously, you’d make an exception for really huge collections, collections so big that the copy is expensive. But in that case, you probably don’t want to be enumerating the collection in the first place, not if you can help it!

You might also be wondering about small collections enumerated in tight loops. You’d be wrong. Either the outer loop is small, in which case the copies don’t cost much, or the outer loop is not small, in which case your operation is at least quadratic and you’re probably headed for trouble.