This is a rather subjective based on the skill level of the intended audience.
You could add a comment to the ClassMethod to provide context to what is being done and why. For example:
/// This ClassMethod takes a delimited String from System-X that consists of sets of Questions and Answers.
/// The Sets are delimited by a pipe "|" and then the questions and answers are delimeted by a colon ":"
/// The response from this ClassMethod is a %Library.DynamicArray object containing the questions and answers
ClassMethod createResponse(data As %String(MAXLEN="")) As %Library.DynamicArray
{
;1.- Questions splitted by "|"
Set listQuestions = $LISTFROMSTRING(data, "|")
Set items = []
Set questionNumber = 0
;2.- Iterate
For i=1:1:$LISTLENGTH(listQuestions) {
Set questionAnswer = $LISTGET(listQuestions, i)
;3.- Update variables
Set questionNumber = questionNumber + 1
Set question = $PIECE(questionAnswer, ":", 1)
Set answer = $ZSTRIP($PIECE(questionAnswer, ":", 2), "<W") //Get rid of initial whitespace
;4.- Generate item
Set item =
{
"definition": ("question "_(questionNumber)),
"text": (question),
"answer":
[
{
"valueString": (answer)
}
]
}
Do items.%Push(item)
}
Quit items
}Or you could go one step further and be more descriptive with your comment at each action within your code. So, instead of:
;2.- Iterate
You could write something like:
;2.- Iterate through the list of Questions and Answers
If your intended audience is not familiar with ObjectScript, then you may want to introduce them to features in stages. For example, you could use $ZSTRIP on both the question and answer in your For loop, but only nest it for the answer and use comments to describe it all. Something like:
// Retrieve the question from the delimited entry
Set tQuestion = $PIECE(questionAnswer, ":", 1)
// Strip any whitespace from the start of the question
Set question = $ZSTRIP(tQuestion, "<W")
// It is also possible to nest functions, so below we will retrieve the answer and remove the whitespace in a single line.
Set answer = $ZSTRIP($PIECE(questionAnswer, ":", 2), "<W")- Log in to post comments
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)