I think a lot of gis.SE visitors are looking for code. Sometimes a small snippet of code is sufficient to answer a question, but other times it can become lengthy. Also, at some point it becomes more of an exercise in programming rather than in GIS.

When code gets long (like here), where should we put it?

I've considered getting involved in CodeProject, but it doesn't seem an appropriate home for code that hasn't been polished.

Many of these visitors probably don't care much about the underlying science of GIS, they may simply be programmers asked to do something with GIS but are not sure of the right approach.

I just discovered CodeReview.Stackexchange, which looks like a good place for questions about code, though not sure how it would integrate with gis.SE.


3 Answers 3


(Let's face it: some of the most popular GISes are requiring exponential increases in code verbosity as they mature. What used to be done in one to three lines now takes one to three pages. In another generation it will be two or three chapters. :-)

I don't mind lots of code in answers: it can be handy and usually is not distracting. But when a page or more of code appears in a question, that turns me right off. It tells me this question may take a lot of study even to read and, often, that the OP didn't make the effort to narrow down their problem or find a minimal length example--so why should I go to that effort on their behalf?

  • 2
    a long winded agreement at chat.stackexchange.com/transcript/message/951408 May 9, 2011 at 16:23
  • 1
    It's too bad Google Wave didn't work out. This issue is actually the only application (that I've found) that Wave would have been useful for. May 10, 2011 at 19:52
  • 1
    Here's a good example of such a question. May 11, 2011 at 13:37
  • Is it okay to post a largeish amount of code in the question if it's the solution and another answer was accepted already, or should I have put the code as a separate answer?
    – blah238
    May 16, 2011 at 23:09
  • @blah Because it functions as a solution I would have no objection.
    – whuber
    May 17, 2011 at 0:44

I've posted a few longer code answers, usually because it felt best to give a solid answer to a question than to only provide a line or two because I think it improved the quality of the answer and helped give context. On the other hand, as @whuber mentions, it seems like bad form when questions are asked with a long rambling code sample asking for help debugging, where it often seems like just an end run around the hard work of actually thinking about the problem.

There are also many other questions where the code distracts from the core question being addressed, and should instead rely on pseudo code than trying to get the error trapping right. Something like implementing an MFD algorithm is best communicated in psuedocode, which can be translated to specific GIS software as needed, but perhaps this is asking too much.


I don't think a long question or a question with a lot of code means that the user did not tried to debug it. Some of these questions require some context.

  • You are correct; there are exceptions to any generalization. However, there can be such a thing as too much context! The surest way to get a good answer to a programming problem is to isolate the problem as much as possible before presenting it to the help desk or a user site. (In many cases the problem is identified during the isolation process...)
    – whuber
    Jul 8, 2011 at 22:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .