Code style and documentation strings

When a function starts to get more complex, incorporating arguments, refinements, return values, and so on, its code must stay readable, following a standard layout. Also, when used in production, functions and all their parts should have documentation. We can provide this with docstrings.

Here is how a general function should be styled:

func-name: func [        "Comments for the function itself"        arg1    [type1!] "Describe 1st argument"        arg2    [type2!] "Describe 2nd argument"        /ref1            "Describe refinement"                argref1 [type1]         return: [type3!] "Describe return value" ][     ; function body]

Here is a fully documented function in the standard layout:

max: function [        "Return the maximum of 2 numbers" arg1 [number!] "First number ...

Get Learn Red - Fundamentals of Red now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.