bearophile wrote:
Andrei Alexandrescu:
I'm rather weary of a short and suggestive name that embodies a linear operation. I recall there was a discussion about that a while ago in this newsgroup. I'd rather call it linearLength or something that suggests it's a best-effort function that may take O(n).

I remember parts of that discussion, and I like your general rule, and I agree 
that generally it's better to give the programmer a hint of the complexity of a 
specific operation, for example a method of a user defined class, etc.

But len() is supposed to be used very often, so it's better to keep it short, 
because if you don't have an IDE it's not nice to type linearLength() one time 
every 2 lines of code.

Being used so often also implies that you remember how it works, so you are 
supposed to be able to remember it can be O(n) on lazy iterators.

So in this specific case I think it's acceptable to break your general rule, 
for practical reasons.

Bye,
bearophile

If it's used often it shouldn't have linear complexity :o).

Andrei

Reply via email to