On 2010-10-21, Jean-Michel Pichavant <jeanmic...@sequans.com> wrote: > Let me quote the paper I linked in the previous post: > > list1 = [] > for x in theList: > if x[0] == 4: > list1 += x; > return list1 > > compare it to: > > flaggedCells = [] > for cell in theBoard: > if cell[STATUS_VALUE] == FLAGGED: > flaggedCells += cell > return flaggedCells
The latter is better, but: flagged = [] for cell in board: if cell.flagged(): flagged += cell; is probably even better. (Here's where I love Ruby's idiom of "flagged?" as a method name.) The "Cells" suffix on flagged is questionable; I'd omit it in context because the programmer knows we're working on cells. The "the" prefix on "theBoard" is actively harmful -- it communicates nothing and clutters. Adding symbolic words to the cell[0] == 4 test is a great idea, but it's been done questionably: 1. Did we just clutter the entire global namespace with "FLAGGED" and "STATUS_VALUE"? If not, what namespace are they in, that we're able to use them unqualified? 2. Why are we exposing that much of our interface in the first place? -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nos...@seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. -- http://mail.python.org/mailman/listinfo/python-list