Naming of new commands

Writing Lisp code and coming up with a name for your new command must be done cleverly. The reason is that when a user starts typing it on the command line, he or she wants command completion to function optimally. In other words: You want to activate the new command with as little typing as possible.

How does command completion work?

Example for teaching

  • You start typing an L. The result is a long list, but command L (Line) is at the top. So alias L produces a command Line because it is a literally and completely typed command.
  • But we continue typing and it becomes LA. An enter returns a Layer command because LA is the alias.
  • And we continue typing: LAS, the alias for LayerState. The list now contains in order: LAS, LAStangle, LAStpoint, LAStprompt and arraycLASsic.

Conclusion

  • If the entered text results in a literal command then this is the value that is sensitive to an enter: LAS.
  • After that, follow in alphabetical order the commands that start with the text: LAS*.
  • Finally follow the commands with pattern *LAS*.

This knowledge can be used to choose better command names.

Grouping commands

“I’m working on BIM, but I forgot the name of the command. I start typing BIM and get a list. With the cursor I can walk through the list after which I give an enter”.

Suppose we add 12 commands for drawing profiles. By having the command names start with for example NP (Nedcad Profile) you have everything immediately available without remembering details. Naming it NP* is smart, naming it LA* is not.

Separate commands

Suppose we have created a command to turn the properties panel on and off, corresponding to the following menu item:

$M=$(if,$(and,$(getvar,opmstate),1),^c^c_propertiesclose,^c^c_properties);

It is a switch that switches the properties panel on and off. What will it be called? Suggestions: PropertiesToggle, PropertiesSwitch, PanelProperties, SwProp, PropSw, TogProp, TgProp, … The possibilities are endless.

For a user it has to be logical and short. Because there are many commands that start with Prop it may be better to choose for example SwProp or TgProp, especially if more switches are made.

The ultimate trick is simply entering a not existing command name on the command line, character for character and watch carefully what command completion suggests.

For example and as alternative to SwProp and TgProp, you could type PrP (PropertiesPanelswitch) or even PP and discover that it is short, unique and a great choice!

One last example, in Lisp several script short cuts are made. They basically do command Script and a script A, B or C. Just name the commands ScriptA, ScriptB or ScriptC.

Conclusion

Naming Lisp code remains a matter of personal taste but it is always wise from the user’s point of view to choose a well thought out name based on the above knowledge. I hope this article will raise some awareness.

Naming of new commands

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top