The SSCCE
Short, Self Contained, Correct (Compilable), Example
If you are having a problem with some code and seeking help, preparing a Short, Self Contained, Correct Example (SSCCE) is very useful. But what is an SSCCE? It is all in the name, really. Take a look at each part. The version prepared for others to see should be:
- Short (Small) - Minimize bandwidth for the example, do not bore the audience.
- Self Contained - Ensure everything is included, ready to go.
- Correct - Copy, paste, (compile,) see is the aim.
- Example - Displays the problem we are trying to solve.
Short
This depends on the group or forum. For a public forum, most readers will stop reading by 100 lines of code, and start complaining at 250-300 lines of code.
Tricks for Trimming
If the GUI has 40 buttons not related to the problem, remove them. If they are related to the problem (you remove them and the problem disappears) put one or two back in, if the problem reappears, include only those one or two buttons.
Problem Solved?
By identifying more clearly where the problem occurs, you have just made an important step toward solving it. The process that highlights where a problem originates can, in itself, help to solve it.
Self Contained
It is important to ensure that the code given to others can be ‘copied, pasted, compiled, run’ so that they can help quickly and with a minimum of fuss.
How to make an example self contained
If the code performs I/O to files, replace the file I/O with dummy data structures in problems that are unrelated to input/output.
Correct
If my example was correct, what would I be doing here? (Laughs) No, that is not what ‘correct’ means in this context. In this document, correct (or compilable, which particularly relates to computer source code) means ensuring that the example fits the accepted standards and protocols.
Example
Make sure the posted code, displays the problem! You have worked on the example for hours, perhaps days. It feels like forever. Now is a good time to take a breather, step back, stretch, perhaps go for a refreshing walk.
Example - Extra Points
We wish we had a dollar for every person who asked for help about a web page or the stylesheet for one, some JavaScript code, or a Java Applet - and did not provide a link.
Standards on the Internet
Therein lies another ‘gotcha’ when dealing with most things related to the internet. The internet, as well as most things associated with it, is just a little bit wild. For every standard there are two alternates.
Java Applets
For a long time Microsoft was shipping the Internet Explorer browser with an older version of Java (a version 1.1 JVM). After some events happened, MS put the latest Java engines into its browsers.
Why bother?
A very good question. Why go to all this effort? Perhaps someone can understand the problem you describe from the description you give.