Contribute Media
A thank you to everyone who makes this possible: Read More

HOWTO write a function

Translations: en


Writing a function that the compiler will accept is much easier than writing a function that will get through code review on the first pass. I've written and reviewed lots of functions and the same advice comes up again and again.

  • Your function should have three parts: input, transform, and output. You should do them in order and not intermingle the three.
  • Keep the function readable by giving your reader context and keeping the amount of implied context low.
  • You can mostly ignore cargo cult practices like one-entry-one-exit and strict function length limits. We'll talk about why those cults exist and how to defend against them in a code review.


Improve this page