I'm thinking in particular of this very recent question, where the OP has constructed a For
loop that actually solves their problem, except that instead of using AppendTo
, they are using Append
, and so of course they are falling victim to a common new user pitfall.
I am tempted, of course, to vote to close the question (and last I looked, there were already 4), not only because if it being clearly a duplicate: if someone comes to the site looking for the answers posted below the question (because they are working on the same problem), they will not actually end up running into this question, since the title is about For
loops, and the question body is about "What went wrong?", not "How do I make this particular algorithm speedier?"
However, I don't want it to close, because there are three excellent (for varying reasons) answers that I would like not to disappear. For instance, Verbeia posted a nice non-speedy answer that exposes the OP to Outer
, which every Mathematica user should know and love in their hearts. Belisarius posted a very neat and succinct answer that I find extremely clever and would like to learn from. And finally, any time you can get ciao/rasher to chime in with some performance-tuning, there just has to be something interesting about the question.
I am considering asking the OP to modify the title and question with more details about the actual problem, and have them turn the problem into a performance-tuning question, but I don't know if that's really the right way to go, and I don't know the OP cares enough about the philosophy of the site to put in that work. But I might try anyway, and if the question becomes closed, I'll vote to re-open.
In any case, I am soliciting advice here. This isn't an entirely uncommon problem, but it pops up now and then, and it's been percolating around in my brain for awhile.