Starter Code
Learn about how to create starter code for a language
Starter code is the code that we provide to users when they start a challenge. It’s the code that they’ll be building on top of.
Required Files
At the minimum, starter code is expected to have the following files:
README.md
- A README file that explains how to run the starter code & submit code to CodeCrafters.
codecrafters.yml
- A YAML file with the keys
language_pack
anddebug
. - The name of this files depends on the challenge.
your_docker.sh
for Docker,your_git.sh
for Git etc.
- A YAML file with the keys
- An executable script that runs the starter code.
- Skeleton code that the user will build upon.
- This code must also include a section that can be uncommented to pass the first stage.
- Any configuration files commonly required by the language / package managers.
- For example,
requirements.txt
for Python,package.json
for JavaScript etc.
- For example,
.gitignore
- A
.gitignore
file that ignores files commonly ignored by the language.
- A
.gitattributes
- A
.gitattributes
file that sets thetext=auto
for all files (to avoid issues with line endings on Windows).
- A
First stage solution
To make it easier for users to get started, we automatically generate a solution to the first stage of the challenge. This is done by uncommenting lines in the starter code.
Example:
Stage 1 solution, auto-generated from starter code
The way this works is that course-sdk will look for markers like this in the starter code:
# Uncomment this to pass the first stage
These markers will be deleted and any code after them will be uncommented to generate the solution.
The full logic for this is here.
Templates
Since starter code for different languages are likely to have a lot of similar code, we use templates to create these.
- The raw files are stored under starter_templates, the compiled versions are under compiled_starters.
- The starter-repository-definitions.yml file contains the mapping from template files to their corresponding compiled paths.
Was this page helpful?