REBOL for COBOL programmers |
WORKING-STORAGE SECTION
Date written: October 3, 2012 This explains the REBOL equivalent of the WORKING-STORAGE SECTION (if there is one). COBOL WORKING-STORAGE SECTIONIn COBOL, every variable that is not part of a file must be defined in the WORKING-STORAGE SECTION. Basically, there are two kinds of variables, those that are independent of any others, and those that are part of a structure. For example: WORKING-STORAGE SECTION. 77 CONSOLE-INPUT PIC X(100) 01 CUSTOMER-RECORD. 03 CUSTOMER-ID PIC X(10). 03 CUSTOMER-NAME PIC X(30).We won't go into detail because you know what this is, and this is COBOL-to-REBOL documentation and not the reverse. The point is, you MUST define data names. You can't NOT do it. The REBOL equivalentIn REBOL, any word is defined at the time it is used, if does not exist already. You do NOT have to pre-define words, it seems to be bad REBOL style to do it, and, because words ARE defined when first referenced, there can be bad effects to pre-defining if you make subtle spelling errors where two words are so close in spelling that you overlook the difference. So there is no REBOL equivalent to the WORKING-STORAGE SECTION. However, you MAY fake a working storage area. You may fake the pre-defining of words. All you have to do is set a word to an initial value at some convenient place in your script. For example, you could code ;; Working storage CONSOLE-INPUT: "" CUSTOMER-ID: "" CUSTOMER-NAME: "" Keeping in mind that you are not required to do the above, what would be the reason for doing so? Documentation, organization, come to mind. If you are used to laying out all the data names you will need in your program, it might be comforting to continue to do that. So go ahead. Group all your words in one area of your program and label it as the working storage area. It probably is a little less "efficient," but consider what "efficent" really means. How "efficient" is it if you come back to a program months later and can't find some data item, or remember what it is used for. If "pre-defining" data items by setting them to initial values just so that they can appear in a central, locatable, spot in your program is helpful, why not do it? "Efficiency" in terms of the smallest and fastest program is not some great god. There are other design goals that could be considered more important, like clarity, maintainability. |