More than Just Code - A Deep Lake
In reply to my prior blog about coding style, some folks have asked the question: can't you create a tool to reformat REBOL code into whatever style the user desires?
Sure, you can write a tool to output REBOL in any format you want. You can output the entire program as a single line or put every word on a separate line. However, only you the writer can give meaningful "hints" within the written form. A tool cannot do that.
Here is a good example. Suppose I write:
if time > 10:00 [ wakeup user ]
which some users may choose to rewrite it this way:
if time > 10:00 [ wakeup user alert "Time to work" ]
But, what if the "then block" is a variable itself, defined as:
action: [ wakeup user alert "Time to work" ]
Would you write this:
if time > 10:00 action
if time > 10:00 action
I would guess that you would prefer to write this last line because the action block is part of the full expression.
Now, what if I wrote a line you were less familiar with:
run script except on conditions
This is a valid REBOL line, but you do not immediately know the relationship of the words within this expression. Suppose the word 'conditions is itself a block. The expanded expression is:
run script except on [ sundays at noon mondays after 10:00 fridays before 9:30 ]
This style helps clarify what's going on, but some of you may say "sure, but the word 'on also clarifies that the block follows". That is true, but you are relying on the relationship between the English language and your script to know that fact. What if instead of 'on the designer used the word 'expedite.
run script except expedite conditions
Now if you saw:
run script except expedite
would you know that a block might follow it? Do you want to rely only on the English interpretation of words, or do you want to provide additional hints?
Of course, how you write code is ultimately your choice alone. REBOL, as a context dependent language, is perhaps the most freeform computing language ever invented. But therein lies the importance of good coding style. You can write actual working programs using an alien dialect (as show here on REBOL.org by the legendary Jeff Kreis, see note) or you can write them to be as clear as possible. It's your choice.
After all, when you create REBOL programs you are ultimately writing them for two readers. One is the REBOL interpreter that executes your code. The other is the human who wants to understand your code. And, perhaps that human reader is you... a few months or years after you've written the code.
Every little comment and every little hint helps.
Updated 30-May-2023 - Copyright Carl Sassenrath - WWW.REBOL.COM - Edit - Blogger Source Code