Is this just me?
Okay, Julian, what’s the next programming task. Ah, yes, deleting the old objects. Should be easy:
def delete(oldobjects): for oldobject in oldobjects: oldobject.delete()
Hmm… You know the object deletion is going to be slow – it may need to talk to the remote servers holding the objects, and it will get blocked on I/O. Maybe it would have better performance if I created a pool of threads, to delete multiple objects concurrently? Oh well, make a note to look at that if there is a performance issue. If it is fast enough, no need to optimise. YAGNI.
Okay, Julian, what’s the next programming task. Ah, yes, collecting the old objects. Should be easy; I just need to find the right point to insert a line of code:
if object.is_old(): oldobjects.add???(object)
Hmm…. what is the correct verb here? Do I add? insert? append? To answer that, I guess I have to decide what the data structure of oldobjects is. It is a collection of some sort, that supports iteration, but I really don’t care what sort; it isn’t that important.
I guess I will make it a list then. But, wait – the list data structure implies an ordering. My collection is unordered. I would rather not even suggest there is an ordering, because that will make it seem trickier to add concurrency later.
I guess I will make it a set then. But, wait – the set data structure implies no duplication. My collection is guaranteed to be free of duplications (and even if it wasn’t, object.delete() is idempotent, making it harmless). I don’t want the computer wasting its time enforcing a constraint that I don’t even have.
A more minor point is that set implementations generally involve using hash functions – I see no reason to enforce the constraint that my objects should support hash functions; they probably do, but if I shouldn’t need to think about it. I also shouldn’t need to thinking about whether hash function is efficient.
If I want efficient, I guess I could go with an array, but there is the implied ordering again, plus the concept of an index, which is another piece of semantics I don’t care about.
Bags, a.k.a. multi-sets? I wonder what the constant time of the insert operation is. I wonder what the insert operation is called. I wonder if there even is a built-in library for this, or do I have to go and search the net for an implementation?
Hmmm… If I was a multi-set implementation in the standard library, what would I be called?
WHOA! Stop! You started by saying the collection type was unimportant, and now you are searching for new libraries, and their performance characteristics? What is wrong with you? Make it a damned list and move on!
So, is it just me, or do other developers go through this internal debate just about every time they use a collection?