Page 2 of 2
Re: Don't know what's wrong with my code
Posted: Tue Nov 04, 2014 4:40 pm
by jacque
The example of the "then" you mentioned isn't what Richard meant, I don't think. The OP wrote that correctly. If I'm reading Richard's mind right, this what we mean, and does not occur in this thread:
Code: Select all
if someCondition is true
then
doX
else if otherThing
then
doY
end if
It runs fine without error. But it looks weird.
Re: Don't know what's wrong with my code
Posted: Tue Nov 04, 2014 5:10 pm
by [-hh]
Oh I see. This shows that my statement "semicolon is equivalent to cr in scripts" is wrong! This should read:
Semicolon is equivalent to cr after "complete" statements in scripts. For example a semicolon after "then" is wrong.
Because your example is so short I would write this as
Code: Select all
if someCondition is true then doX; else if otherThing then doY
I'm bad *half* to the bone ...
[Edit. Divided my last statement by two after the answer of jacque to this post.]
Re: Don't know what's wrong with my code
Posted: Tue Nov 04, 2014 6:02 pm
by jacque
You could write that all in one line and it wouldn't error even without the semicolons. Your rule may need revision.
I write one-line if clauses frequently.
Re: Don't know what's wrong with my code
Posted: Tue Nov 04, 2014 7:01 pm
by dunbarx
All those weird variants were explicitly offered for sale in HC. Readability be damned. They were fraught with peril, though, and only a few were ultimately considered "acceptable". Some would not indent, though they would compile.Some, that really seemed OK, if nested into other if-then constructions, would not compile unless broken out fully:
if soAndSo then
whatever
else
whateverelse
end if
I never understood why, but learned long ago that if I just expanded, the overall handler would compile and work.
Craig
Re: Don't know what's wrong with my code
Posted: Tue Nov 04, 2014 7:28 pm
by jacque
dunbarx wrote:
I never understood why, but learned long ago that if I just expanded, the overall handler would compile and work.
I had a disagreement with XXX at a conference once about that. He wrote all if/else clauses in standard structure no matter how short they were. I do that mostly too but I also use one-liners sometimes if they're short enough. The other structures aren't reliable for the reasons you mention. Mark Waddingham once explained what the rules were for compilation but I've lost the reference, and so I just remember that the safest thing, as you say, is to write them in fully expanded format.
So we're back to standard structures, and all that.
Re: Don't know what's wrong with my code
Posted: Tue Nov 04, 2014 8:00 pm
by [-hh]
Who is that obscure developer "XXX". Tried to find him with Google. The result was unbelievable. Can't imagine this was part of a conference.
Re: Don't know what's wrong with my code
Posted: Tue Nov 04, 2014 8:05 pm
by jacque
LOL! That's funny. And knowing him quite well, I am very sure that any Google search you did would not include him.

Re: Don't know what's wrong with my code
Posted: Tue Nov 04, 2014 9:17 pm
by FourthWorld
jacque wrote:The example of the "then" you mentioned isn't what Richard meant, I don't think. The OP wrote that correctly. If I'm reading Richard's mind right, this what we mean, and does not occur in this thread:
Code: Select all
if someCondition is true
then
doX
else if otherThing
then
doY
end if
It runs fine without error. But it looks weird.
Because it
is weird.
We nearly had a food fight at our local LiveCode user group over this issue. It's serious stuff.
