REBOL for COBOL programmers
The trap in defining variables
Date written: February 10, 2015
This page restates the point that you don't have to define variables, and how that could catch you if you go ahead and to it anyway.
In COBOL you have to define every variable, in the DATA DIVISION. In REBOL that is not required. If you have bonded with the COBOL way, you might like to see all the words you will use laid out nicely in one spot. That can be helpful for organizing your thoughts and documenting things, be there is a danger that comes with that approach. For example, let's say your program looked like this artificial example (only relevant parts shown):
COMPUTER-MODEL: "" ;; input value from some source DISPLAY-MODEL: "" ;; value to be displayed somewhere else ... ;; enough code to make you forget how you spelled things ... ... ;; other code that changes the value of COMPUTER-MODEL either equal? COMPUTER-MODEL "" [ DISPLAY-MODE: "unknown" ;; note the autopilot mis-spelling ] [ DISPLAY-MODEL: COMPUTER-MODEL ] ... ... ;; other code that eventually displays DISPLAY-MODELIn this example, you used the value of COMPUTER-MODEL to decide how to set a value in DISPLAY-MODEL, but your fingers typeed the word MODEL as MODE because they were on autopilot. The word DISPLAY-MODE came into being at that time because that's how REBOL works. Later, when you displayed DISPLAY-MODEL, it might not be what you expected because when you thought you were setting it to "unknown" you actually were setting some OTHER word to "unknown." In COBOL, you would get a syntax error indicating that DISPLAY-MODE was undefined. In REBOL, the program works, but does not do what you expect.
This COBOL-like requirement for defining data names might be something that the designer of REBOL was trying to get away from. There are those who think that if there is something that you "have to" do, then you never should have to do it. For example, in COBOL, before you can read a file, you must OPEN it. But, if you ALWAYS have to OPEN it, and there never is an option for reading it WITHOUT OPENing it, then why can't the OPEN operation be implied and automatic?
As you write more REBOL code, there is a chance you get tired of pseudo-defining data names and drift away from it. If you look at REBOL code by those who know, you will see it is a lot shorter. It's also harder to read, at least for a beginner. You will have to decide which direction you want to go.