Best Practices
These are the best practices for working within Code Thesaurus.
Code Blocks
- Code blocks must technically compile. If someone copied and pasted the code, it should in theory work. (For example, saying "a variable would go here" won't likely work, but "a_variable_goes_here" likely would.)
- Try to have code blocks match other code blocks as much as possible. They should be structurally similar to other comparable languages, but match the style and syntax of the language you're working in.
- If there's more than one way to solve a problem, you can list each way in the
codeblock. Code blocks should be arrays when they contain multiple examples (though for backward compatibility, older files can use a string). Use thecommentblock to differentiate the examples and explain when someone might pick one over another. If any of them can be used, you don't have to leave a comment. - Operators need to show their order (prefix, postfix, infix). Just putting "" for multiplication is wrong; use "a * b" or " a b", as some languages differentiate the order of operators and operands.
Comments
- Keep comments out of code blocks and put them in
commentblocks instead. Keep eachcodeblock in the JSON files to as much code as possible, and put anything you wish to note in acommentblock. - In comments, you can use backticks (
like this) to refer to bits of code within the text.
Concept Metadata
- For each concept in a file, you can have
code,code + comment,not-implemented, ornot-implemented + comment. The optionalnamefield is also allowed. Other combinations are not valid and might result in errors when the build process checks them over. - If a concept doesn't exist in a language, mark it with
"not-implemented": trueand don't add equivalent code to make it happen. If a language doesn't have the functionality, don't write an algorithm to add it. - In language data files, concepts live under a
conceptsobject. A top-levelcategoriesobject belongs in the_metastructure files only and is deprecated in language data files, so don't copy it over when generating a structure file.
Keep the Reader in Mind
- Assume anyone reading it might be a beginner. What's "easy" or "obvious" to you may not be to someone else. This is a learning tool and new learners might be using it.