
On Sun, 3 May 2009 12:28:47 pm Adam Atlas wrote:
Isn't the convention to suffix a name with an underscore when it would clash with a builtin? (range_, list_, type_, etc.)
That's one convention. Another is to name things alist, atype, astr,. etc. If you need two of them, the obvious extension is blist, btype... When writing *small* generic methods or functions, I'm also fond of using L for list, x and y for floats, n or i for ints, and similar. This needs to be handled with care, for obvious reasons.
I'm not sure how much I like that stylistically, but I've seen it used a lot. (I think in some cases there are better alternatives -- e.g. instead of naming a variable "seq" or "list_", I'd have the name specify what it's a list *of*.)
Well, this is Python, and we use duck-typing, so everything would need to be list_of_string_like_instances or similar :) But seriously, I tend to use plurals for that. If I have an argument that takes a collection of widgets, say, I call it "widgets", and write code like this: for widget in widgets: whatever() I don't think there's much to be gained by calling it "list_of_widgets" unless it really needs to be a list, and not any other collection type. -- Steven D'Aprano