2
$\begingroup$

Suppose you have a very long code in which many new functions are created. For efficient programming, very short and easily iterated function names are preferred.

For example,

runningFast[x_]:=x^2 

can be named as

rf[x_]:=x^2 

Obviously, the latter function rf[] is preferable in such example as:

k[y_]:=rf[x]^3+Sqrt[rf[x]]+Log[rf[x]]+... 

because it is easy to write. However, if I come back to the same function later on, I might not remember what rf[x] does.

Question

Given a notebook, is there any way to keep track the function names with some explanatory note so that I can recall the names at will?

$\endgroup$
1
  • 2
    $\begingroup$ If you expect to modify/maintain something you have written later on, "because it is easy to write" ranks quite low on the list of reasons to pick a function name. More so if your memory is not the best. $\endgroup$ Commented Oct 9, 2018 at 16:30

1 Answer 1

7
$\begingroup$

Set a usage message

rf::usage = "rf[x] is short for runningFast[x]"; 

when you type rf you can click the help button that pops up as you type, or evaluate

?rf 

to get the usage message.

A tip from @m_goldberg in the comments is to put the usage statements in initialization cells in an auxiliary notebook, and include that notebook in your working notebook with a call to Needs.

$\endgroup$
6
  • $\begingroup$ Yes, it is an answer to my question. I wonder if there is any way to keep all of the usage messages in a separate notebook linked to the notebook where they are created. The reason is that I like to have an uncluttered notebook (without explanatory notes) and retrieve the names not as single elements but retrieve the entire notebook where the names are stored like a separate window open when I create other names.. $\endgroup$ Commented Oct 9, 2018 at 16:29
  • 1
    $\begingroup$ @TugrulTemel. You can put the the usage message definitions in an auxiliary notebook. Make all the definition cells initialization cells. Put a Needs function call at beginning of you working notebook to load the messages. Make the cell with the Needs call an initialization cell as well. $\endgroup$ Commented Oct 10, 2018 at 2:33
  • $\begingroup$ @m_goldberg: Thanks for the very useful piece of information. I want to accept your comment as an answer, how can I do that? $\endgroup$ Commented Oct 10, 2018 at 10:32
  • 2
    $\begingroup$ @TugrulTemel. You can't accept a comment, but you can accept the the answer it is attached to, which is what I recommend. I made my remarks a comment so as not to set up a rival answer to this one. $\endgroup$ Commented Oct 10, 2018 at 14:29
  • 1
    $\begingroup$ @m_goldberg: I added your suggestion to the body of my answer (with attribution). $\endgroup$ Commented Oct 10, 2018 at 15:20

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.