QforMortals3/Comments

From Kx Wiki
Jump to: navigation, search

1.5 Comments

The forward-slash character ‘/’ indicates the beginning of a comment. Actually, it instructs the interpreter to ignore everything from it to the end of the line.

Information.png Tip: At least one whitespace character must separate ‘/’ intended to begin a comment from any text to the left of it on a line.

In the following example, no definition of c is seen by the interpreter, so an error occurs.

q)b:1+a:42 / nothing here counts      c:6*7
q)c
‘c

Notice the succinct (ahem) format of q errors: a single vertical quote (called “tick” in q-speak) followed by a terse error message. In this case, the error should be interpreted as “Error: c is not recognized.”

The following generates an even more succinct error.

q)a:42/ intended to be a comment
‘
Information.png Coding Style Recommendation: The q gods have no need for explanatory error messages or comments since their q code is perfect and self-documenting. Even experienced mortals spend hours poring over cryptic q error messages such as the ones above. Moreover, many mortals eschew comments in misanthropic coding macho. Don't.



Prev: The_Q_Console, Next: Assignment

Reprinted with the author's permission from: q for Mortals Version 3, An Introduction to Q Programming by Jeffry A. Borror.

The book is available on Amazon. In the United Kingdom, it is available at Amazon UK.

©2015 Jeffry A. Borror/ q4m LLC

Personal tools
Namespaces
Variants
Actions
Navigation
Print/export
Toolbox