[REBOL] Re: To do or not to do?
From: rotenca:telvia:it at: 29-Nov-2001 18:58
Hi,
> I dunno, this sort of thing is a matter of taste as much as
> anything,
Yes, but it is almost like the difference between compiled / not compiled
code.
A string is like source code for Rebol. It must be compiled (loaded) and then
run (interpreted). A block is like compiled code: it must only be run
(interpreted).
If the overhead is not a problem, you can compile your C code every time you
run it :-) (it is not just the same thing, I must admit :-()
>but I reckon the original "makelayout" is an easier
> bit of code to follow and amend than the version below.
I disagree:
1) now your code is more readable than before (from a Rebol point of view)
2) now a reader can understand better which are the conversions you operate
But the code could be more clear if you separe the conversions from the
executing:
BoxColor: "Green"
LastField: "zz"
...
BoxColorW: get to-word BoxColor ; or BoxColorW: get load BoxColor
LastFieldW: to-set-word LastField ; or LastFieldW: to-set-word load LastField
The 'load func add an additional "internal check" (which is long to explain)
to the conversion of the string which both to-word and to-set-word escape.
Here you can check conversion errors and then use a layout block with compose
only for the set-word.
MakeLayout: does [ ;this name seems to me wrong, the func returns only a
block!
compose [
across
b: box to-pair reduce [MaxBoxWidth MaxBoxDepth] boxcolorw
return
c: box to-pair reduce [
to-integer MaxBoxWidth / 2 to-integer MaxBoxDepth / 3
]
boxcolorw + 150.150.150
(:lastfieldw) text "last field"
]
]
> The
> "compose" version needs several Rebol tricks (to-set-word,
> get to-word) that the (perhaps brain-dead and inelegant)
> "string 'em up" original doesn't.
It made it in an implicit mode. But it made many others not necessary
conversions of your string-code.
> (And I guess when I write code, the target audience I have in
> mind includes the maintenance programmer in 5 years time who
> is not an expert in either the system or the languages used
> but, nonetheless has to make modifications fast.)
In 5 years Rebol block will be the standard way to write code for beginners
:-)
To end, in your code:
b: box to-pair reduce [MaxBoxWidth MaxBoxDepth] (get to-word boxcolor)
...
((get to-word boxcolor) + 150.150.150)
can be
b: box to-pair reduce [MaxBoxWidth MaxBoxDepth] (to-word boxcolor)
...
(to-word boxcolor) + 150.150.150
> Colin
---
Ciao
Romano