2

I'm not sure whether this is the best place for feature suggestions, but I think having a diff viewer for code that compares source code snippets to answer's code snippets would be a very helpful feature.

Generally when the answer requires a tiny modification to the code in the question we copy the entire code with the modification done and add a comment to clarify that there was a change in this place. I think having a diff viewer would highlight the change while keeping the full code there — allowing snippets to still run inline.

Would there be a reason not to have such thing? Or should I have this discussion somewhere else?

5
  • 2
    Do we? If there's so much code and such a small change, chances are the failure was answering at all, instead of downvoting and closing for lack of an MCVE, or as a typo. Dec 19, 2015 at 18:29
  • 4
    "I'm not sure whether this is the best place for feature suggestions,"....this is the perfect place. The only better place is the meta of metas if it would be for all/multiple sites
    – codeMagic
    Dec 19, 2015 at 18:45
  • 1
    Yeah I know. Consider the case of a couple of changes in a 100 lines code snippet. I find myself having to mention the number of changes and adding comments next to them to clarify them. @Deduplicator Dec 19, 2015 at 18:48
  • At least 90% of SO answers are code answers, regardless we like it or not. Even if the answer explains the solution well, a little code always helps. So should we include the whole code with the modifications (most probably the answerer already has it in his favorite IDE), or just the changes? For the asker its better to include only the modifications, for other visitors its better to have the whole code so they can see how its working. Jun 30, 2016 at 23:47
  • There are cases where the best solution is a code answer with a short explanation and a link to the docs. The other day somebody asked on SO about his error in a Rust code. Totally unrelated, the code could be made much shorter with the use of rust closures. (OP explicitly asked for a better solution), so I decided the best is to mention that closures exist, with a link, and his code rewritten to the shorter form. There was not much more to explain there, I saw no point in copying whole pages of syntactic grammar about 5 lines of code. So yeah, diff highlight would be useful imho. Jun 30, 2016 at 23:54

1 Answer 1

4

I get where you're coming from, but in cases where it's a small change to a large code block, a little explanation and a comment in the code is usually sufficient.

Something like:

You just need to add property X, like so:

.example{
  foo: ...;
  bar: ...;
  baz: ...;
  X: .....; /* see change here */
}

Property X works because it flobbers the garble, so it should get you where you need to go.

You can learn more about property X in the documentation here.

6
  • 3
    But in larger code snippets with a couple of changes it will be much hard to spot. I find myself having to mention the number of changes I did in order to give a clear answer sometimes. Dec 19, 2015 at 18:47
  • @Louy In general it's a good idea to explain your changes and why you made them. Adding a comment to highlight where the change occurs will help the OP spot the diff.
    – apaul
    Dec 19, 2015 at 18:49
  • I agree with you, but again this would be better than having to say "I changed x to y and z to whatever to make it work". It will also add clarity in a sense that code-only answers will become much much easier to read and understand. Even for the short ones. (say >10 and <20 lines) Dec 19, 2015 at 18:55
  • @Louy That is a good example of why code only answers aren't a good idea... A code dump may help the original asker, but it usually isn't very useful to anyone else. Better answers not only solve the problem, but also educate people on the nature of the problem and how the problem is solved.
    – apaul
    Dec 19, 2015 at 18:58
  • 3
    Related: a "this fixes it" answer, plus a puzzled answerer who, when prompted, asks me what I fixed (??).
    – Jongware
    Dec 19, 2015 at 22:39
  • @Jongware thanks, that sums it up pretty well.
    – apaul
    Dec 19, 2015 at 22:47

You must log in to answer this question.

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