REBOL Technologies

A Note on Standard REBOL Source Style

Carl Sassenrath, CTO
REBOL Technologies
15-Jan-2005 18:26 GMT

Article #0102
Main page || Index || Prior Article [0101] || Next Article [0103] || Post Comments || Send feedback

Some people have asked me why does the standard style for REBOL scripts look like this:

foreach item list [
    if block? item [
        process item
    ]
]

and not like this:

foreach item list
[
    if block? item
    [
        process item
    ]
]

The answer is simple. The first example provides useful hints to the reader. It indicates that some expressions continue on the next line. The second example does not.

This is perhaps the most important rule of REBOL style. It is useful to provide a hint as to where functional expressions end. This is normally done at the end of the line.

Because REBOL is so freeform, this is a subtle point, but it is even more important in REBOL than other languages. That's because REBOL does not use expression terminators or separators (like the ; of C) -- a critical part of REBOL's code/data reflective design.

This style applies to back-to-back blocks as well, such as in:

validate item
checkout source item [
    process item
] [
    remove item
]

The above code shows that the CHECKOUT function continues over multiple lines to include two blocks as arguments to the function.

This code is less clear:

validate item
checkout source item
[
    process item
]
[
    remove item
]

There are some rare exceptions to the style rule - mostly when formatting data blocks. The rule is not cast in concrete (otherwise it would be enforced by the language, like in Python). Here is an example:

data: [
   name age email
   [
       "Bob Smith"
       24
       bob@example.com
   ]
   [
       "Tom Wright"
       42
       tom@example.com
   ]
]

Here the expression does not continue after the first line within the block. Each sub-block after the first three words is a separate data element. It is not the continuation of a functional expression.

I wrote the REBOL script style guide at the very beginning of REBOL because I was concerned that there would be too many variations in source format and make scripts less readable to each other.

But, in the end, you can write your REBOL script however you want. It is a freeform language. However, it is much easier for those of us in the REBOL community to read your scripts if you follow the standard style.

Some of you will probably write to me to tell me that I am wrong. That's ok. I've heard it all before. I did not establish the standard style without a lot of thought on it, as well as experience with dozens of other computer languages spanning over 25 years. And, regardless of any degree of logic, rationale or any other reason, it is still better as a community to have a single style for REBOL scripts.

Post Comments

Updated 19-Nov-2024   -   Copyright Carl Sassenrath   -   WWW.REBOL.COM   -   Edit   -   Blogger Source Code