Talk:CodingStandards: Difference between revisions
→Passing an argument by value: new section |
No edit summary |
||
Line 1: | Line 1: | ||
== Ternary assignment preferred == | |||
Regarding 2.10 "Avoid using obscure and unfamiliar coding styles", the example shows ternary assignment as "BAD"; that is, obscure and unfamiliar to most PICK programmers. I actually prefer to use ternary assignment instead of multi-line IF-THEN-ELSE logic. Ternary assignment helps to avoid the error where the variable name is mis-typed in the ELSE clause. | Regarding 2.10 "Avoid using obscure and unfamiliar coding styles", the example shows ternary assignment as "BAD"; that is, obscure and unfamiliar to most PICK programmers. I actually prefer to use ternary assignment instead of multi-line IF-THEN-ELSE logic. Ternary assignment helps to avoid the error where the variable name is mis-typed in the ELSE clause. | ||
Revision as of 14:20, 15 May 2020
Ternary assignment preferred
Regarding 2.10 "Avoid using obscure and unfamiliar coding styles", the example shows ternary assignment as "BAD"; that is, obscure and unfamiliar to most PICK programmers. I actually prefer to use ternary assignment instead of multi-line IF-THEN-ELSE logic. Ternary assignment helps to avoid the error where the variable name is mis-typed in the ELSE clause.
Passing an argument by value
Regarding 5.7 "Variables passed to subroutines can be passed by value", scalar variables can be wrapped in parentheses to pass by value, but an array element cannot. Calling FMTPHONE((CM.REC(CM$PHONE))) will pass a pointer reference to the array element, not a copy of its value, so the array element's value may be changed by the subroutine/function.
A better way to ensure an argument is passed by value is to prepend or append an empty string.
CALL FMTPHONE("":CM.REC(CM$PHONE))
This can be made more explicit with an equate:
EQU BYVAL LIT \ "": \ CALL FMTPHONE(BYVAL CM.REC(CM$PHONE))