Because I'm having some of these bad habits mentioned until now I would like to explain my impassionate use of it.
Sometimes people have a reason to do some things in a more compact manner or in a somewhat superfluous manner:
(1) Concatenating script lines with semicolon can be a good practice
I use to do this as often as I can and my reason is:
My eyes are not best and I use to have a big textsize. But I can read scripts very fast. Sometimes I have to rotate my monitor to get an *overlook* about scripts from others. For example ...
... this takes a quarter height of a scripteditor screen:
put item 1 of a into a1
put item 2 of a into a2
put item 3 of a into a3
Now compare to this line:
put item 1 of a into a1; put item 2 of a into a2; put item 3 of a into a3
Compact and readable with double speed. I have to read the first part of this line in order to know what fills up the rest of the line. For important parts of the script I always start a new line or mark it, as you do.
Or take a switch with N cases:
Code: Select all
switch k
case 1
action1
break
case 2
action2
break
...
end switch
and now scroll down Nx3 lines. What's so important in a "break" to have its own line? I know how a switch works and if I use one where some cases are without break then the breaks are important and have their own line. Else I have for each case ONE line (if not too long):
Code: Select all
switch k
case 1; do action1; break
case 2; do action2; break
...
end switch
Very compact and I have to scroll down N lines only.
Last example (I use this often when I create an image by script)
Code: Select all
set script of img 1 to "on mouseDown;grab me;end mouseDown"
One line. Very clear, always the same.
(2) When to use "the" and when avoid it?
The use of "the" is optional, as mentioned above. Very good. So I can use it (almost always) this way:
Whenever I GET a property, I use "the":
get the property of btn 1,
whenever I SET a property, I avoid "the":
set property of btn 1 to myString.
In other words,
using "the" with a property is for me a mnemonic that I have a
return value (may be empty).
Avoiding "the" sets for me an association, that I have a
result value (may be empty).
This is a well-considered logic that makes my scripts very fast readable for me, faster than having to read a lot of superfluous "the".
The recommendation to use always "the" is certainly of educational type and not because the engine slows down without it. (At least with my tests there is a difference of < 1 millisecond with 1 million repeats.)
Let me now praise one thing that not enough people here are using:
(3) Please set superfluous parentheses!
(a) Math operators (incl. "or", "and", "not") have a very clear precedence order. It is for people who are used to do math easy to read a rather complicated expression in correct order. For some other people, who have their mental strength in other fields, it is VERY important that one sets and that they set superfluous parentheses, simply to make it better understandable. And this can speed up the engine measurably (I tested also), the engine loves a clear structure.
(b) Moreover to write (expression), that is parentheses around an expression, in order to ensure the evaluation of expression, is a mostly superfluous, but also valuable style. For example:
"set hilite of me to (the mouse is down)"
is as soon as got one time much clearer and 'cause and effect' better understandable then
"if the mouse is down then set hilite of me to true; else set hilite of me to false"
Applying my last point to (part of ) the thread gives:
Code: Select all
on mouseUp
put (1 + the label of the target) into tNr
repeat with x = 2 to the num of grps of this cd
set visible of grp x of this cd to (x is tNr)
end repeat
end mouseUp