6
$\begingroup$

Is there a good convention for documenting functions/return values? If I just put them in comments on top of function, the alignment is all over the place. enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ I would generally recommend the "Code" style cells. They don't have automatic alignment, and generally the code looks much nicer with them, and typing experience is much more predictable and closer to a text editor. I use them for code almost exclusively. $\endgroup$ Commented Mar 30, 2017 at 21:26

1 Answer 1

7
$\begingroup$

Using a comment is awkward and unnecessary. If you have a very long function, you generally don't want to retrieve the full function later, while programming. Hence use the usage option, which will retrieve merely the usage information you've entered:

generateXY::usage = "generateXY[e_, yvar_, extraDims_, dsize_] here e controls how correlated, ..."; 

Later, you mere type

? generateXY 

to get the description, not all the (needless) code.

Simple example:

f[x_] := x^3; f::usage = "f[x] gives the cube of x" 

Later:

? f f[x] gives the cube of x 

Moreover

?? f 

retrieves the full information, should you need it:

f[x_] := x^3; f[x] gives the cube of x 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.