Code Snippets
A code snippet is a minimally functioning program that is used to demonstrate the use of a single feature of a programming language. A section of code is considered a snippet if
- It is a completely functioning program, and
- The demonstrates exactly one concept.
As an example, the following code would be a snippet for demonstrating functions in C++,
#include <iostream> void MyFunction() { std::cout << "Inside My Function" << std::endl; } int main() { MyFunction(); return 0; }
but the following would not, because it would not compile.
void MyFunction(std::string filename) { std::cout << "Inside My Function" << std::endl; } int main() { ... MyFunction("/home/stargazer/myfile.txt"); ... }
While snippets should only demonstrate a single concept, this can be difficult, because there are many times where multiple techniques are needed simply to show a more advanced concept. The key is that code snippets should be as small as possible while still demonstrating functionality.
Code Snippets should always follow good programming techniques.
page revision: 9, last edited: 15 Apr 2019 14:37