Source code samples: snippets to paste into a demo, files to feed a syntax highlighter, a linter, a formatter, or a parser, and small programs to show a language doing something.
One subfolder per language, named after the language in lowercase:
| Folder | Language | Extensions |
|---|---|---|
c/ |
C | .c, .h |
cpp/ |
C++ | .cpp, .hpp |
csharp/ |
C# | .cs |
dart/ |
Dart | .dart |
go/ |
Go | .go |
java/ |
Java | .java |
javascript/ |
JavaScript | .js, .mjs, .cjs |
kotlin/ |
Kotlin | .kt |
php/ |
PHP | .php |
python/ |
Python | .py |
ruby/ |
Ruby | .rb |
rust/ |
Rust | .rs |
shell/ |
Shell | .sh |
swift/ |
Swift | .swift |
typescript/ |
TypeScript | .ts |
A language that has no folder yet gets one, named the same way. The folder is the
language, never the framework — a React component is a sample of JavaScript or
TypeScript, and says react in its file name instead.
Code is the one place in this repository where names follow the language's own
convention rather than the repository's kebab-case rule, because some languages
enforce theirs: HelloWorld.java has to match its class, and hello_world.py is what a
Python module looks like.
Everything else still holds:
- Name the file after what the sample demonstrates:
fizzbuzz.py,BinarySearch.java,read-file-async.js,struct_traits.rs. - Add the qualifier to the name when the point is a variant:
sort-quick.go,sort-merge.go,fizzbuzz-recursive.py. - Mark a sample that is meant to be broken with
-invalid,-malformed, or-broken, the same way datasets do. A file that will not compile on purpose has to say so.
Each language folder holds samples of two sizes, and both are wanted:
- Snippets — one construct each, a screen or two long:
closures-counter.js,SwitchExpressions.java,pattern_matching.rb. These are what a syntax highlighter, a formatter, or a tutorial wants. - Programs — a few hundred to a thousand lines, doing something whole:
lisp_interpreter.py,MazeSolver.java,query-builder.php. These are what an indexer, a static analyser, a diff viewer, or a context-window test wants, and they are the only samples that show a language's constructs used together.
Two programs per language is the target. They are named after what they do, not after their size — a reader can tell them apart by opening one.
- Self-contained files. A sample should be readable on its own and run, compile, or at least parse without a project around it. No build scripts, no lockfiles, no vendored dependencies. This holds for the long programs too: each is one file with an entry point and, where the language has a convention for it, its own tests.
- Plain standard-library code, unless the sample exists to show a specific library.
- A header comment on a program saying what it does and how to run it. A snippet rarely needs one; a program always does.
Markup and stylesheets are documents rather than programs, so .html and .css samples
live in documents/, and SQL lives in
datasets/sql/ with the rest of the data.
Code written for this repository is covered by its LICENSE. A sample that comes from somewhere else keeps its own license, and is listed here with its source, author, and terms before it is added. Nothing has been added yet.