Skip to content

Instantly share code, notes, and snippets.

@dyllandry
Created July 7, 2023 01:30
Show Gist options
  • Select an option

  • Save dyllandry/975aac3fdc58252c7d64e0dce8403006 to your computer and use it in GitHub Desktop.

Select an option

Save dyllandry/975aac3fdc58252c7d64e0dce8403006 to your computer and use it in GitHub Desktop.
Some context around my code examples for the Ought Full-Stack Software Engineer position
This bit of code is from a recent rust project where I'm making the board game snakes and ladders. Specifically, it's the code that creates a new "board" which contains pawns, tiles, and connections (the snakes and ladders).
https://github.com/dyllandry/ladders-and-slides/blob/f79a28fb057f8839dd9b1d2f09fa9c136c118d35/src/ladders_and_slides.rs#L132
The reason I like this function is because:
- It's not complex. It hides enough complexity to be useful & the interface it exposes is simple.
- It includes argument validation with errors, so you catch issues during development.
- It lacks side-effects, just receives and returns data.
- Includes a comment to communicate something non-obvious in the code.
There's also tests for this code.
https://github.com/dyllandry/ladders-and-slides/blob/f79a28fb057f8839dd9b1d2f09fa9c136c118d35/src/ladders_and_slides.rs#L169
I like these tests because:
- They are high value, they test for cases that could ruin the game.
- There are few, so maintenance costs are low.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment