Skip to main content
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

I have stumbled across some questions where it is hard to determine whether or not the code in the question actually works or not.

Example #1: http://codereview.stackexchange.com/questions/35616/replacing-parenthesis-in-codehttps://codereview.stackexchange.com/questions/35616/replacing-parenthesis-in-code

Example #2: Creating a binary search treeCreating a binary search tree

This has got me thinking, can we do something to encourage users to add a snippet of code that proves that there code is working as it should? Kind of like a small unit test, it does not have to be a long snippet, probably just a couple of lines for most questions.

Of course it is not possible to add such a snippet for all questions here, but I think that for many questions that ask about code that is independent from other things it would be useful.

A big advantage of providing a testing code snippet is that it shows reviewers how their code is meant to be used, what one or more entry-points to the code is. I believe this would help the reviewers getting a better understanding about their code in general.

So can we (or should we) do something to encourage users to include a code snippet that proves that their code works and/or how it is used?

I have stumbled across some questions where it is hard to determine whether or not the code in the question actually works or not.

Example #1: http://codereview.stackexchange.com/questions/35616/replacing-parenthesis-in-code

Example #2: Creating a binary search tree

This has got me thinking, can we do something to encourage users to add a snippet of code that proves that there code is working as it should? Kind of like a small unit test, it does not have to be a long snippet, probably just a couple of lines for most questions.

Of course it is not possible to add such a snippet for all questions here, but I think that for many questions that ask about code that is independent from other things it would be useful.

A big advantage of providing a testing code snippet is that it shows reviewers how their code is meant to be used, what one or more entry-points to the code is. I believe this would help the reviewers getting a better understanding about their code in general.

So can we (or should we) do something to encourage users to include a code snippet that proves that their code works and/or how it is used?

I have stumbled across some questions where it is hard to determine whether or not the code in the question actually works or not.

Example #1: https://codereview.stackexchange.com/questions/35616/replacing-parenthesis-in-code

Example #2: Creating a binary search tree

This has got me thinking, can we do something to encourage users to add a snippet of code that proves that there code is working as it should? Kind of like a small unit test, it does not have to be a long snippet, probably just a couple of lines for most questions.

Of course it is not possible to add such a snippet for all questions here, but I think that for many questions that ask about code that is independent from other things it would be useful.

A big advantage of providing a testing code snippet is that it shows reviewers how their code is meant to be used, what one or more entry-points to the code is. I believe this would help the reviewers getting a better understanding about their code in general.

So can we (or should we) do something to encourage users to include a code snippet that proves that their code works and/or how it is used?

Tweeted twitter.com/#!/StackCodeReview/status/403689792065789952
Source Link
Simon Forsberg
  • 59.4k
  • 1
  • 78
  • 172

Encouraging users to include a code-snippet that proves that their code works

I have stumbled across some questions where it is hard to determine whether or not the code in the question actually works or not.

Example #1: http://codereview.stackexchange.com/questions/35616/replacing-parenthesis-in-code

Example #2: Creating a binary search tree

This has got me thinking, can we do something to encourage users to add a snippet of code that proves that there code is working as it should? Kind of like a small unit test, it does not have to be a long snippet, probably just a couple of lines for most questions.

Of course it is not possible to add such a snippet for all questions here, but I think that for many questions that ask about code that is independent from other things it would be useful.

A big advantage of providing a testing code snippet is that it shows reviewers how their code is meant to be used, what one or more entry-points to the code is. I believe this would help the reviewers getting a better understanding about their code in general.

So can we (or should we) do something to encourage users to include a code snippet that proves that their code works and/or how it is used?