If ....... Then

If 1 = 1 _ ' I often use 
  And 2 = 2 _ ' multiline conditional
  And (3 = 3 _ ' statements as they
  Or 4 = 4) Then ' are easy to document
  s = "Bingo" ' and I can place a break point here
End If
8 Likes

How API2 was hard to follow for you then !

Forgetting Then is nice since you get a reminder at run time.

Using API2 is far more difficult since the words are different (and I do not talk about the syntax).

Wording that differently can be:
ommiting a Then is my error and Xojo is very kind with me to remind me to add it.
some error reporting are so !obvious that you have to waste your time shaking your head trying to understand where the error can be / what change to do to remove the error…

BTW: are you ready for a brand new extensive change (again) in Xojo ?

Not if it is for the sake of change, but now we have gone the path of modernizing the language with API 2.0, I would prefer optimizing it a bit further and leaving the good old (visual)basic practices.

1 Like

Until the next major changes comes…

But optimization are welcome (app size shrink down for example)…

Yes, that’s right. If you only have one simple expression, you don’t need the keywords like “Then”.

But since I use more complex expressions, I don’t want “Then” to be removed!

1 Like

What I think it’s ugly code:

x = x + 1

why not:

inc(x)

Of course I know I can write functions like this myself, but that’s not what makes things easier.

In PHP, Java, C++ and many other languages, there’s x++ or ++x, as well as x-- or --x.
These operators are called increment and decrement.

And now I think we’re straying off the original topic.

4 Likes

And how do you write:
x = x + 7

?


inc(x)
inc(x)
inc(x)
inc(x)
inc(x)
inc(x)
inc(x)
1 Like

With an optional second parameter:
inc(x, 7)

But it is nonsense to call a function to add, sub etc. This takes away the compiler’s ability to optimize the code.

Which one is easiest to understand, to write, etc. ?

x = x + 7
inc(x, 7)

I tend to say: the former.

The statement I wanted to make is that if we go the way of changing keywords / syntaxes, there is still a lot more that can be done based on the same thoughts. And I can’t help feeling that the team would like to get rid of the well-known (visual) basic style.

The Xojo November 2021 states:
Xojo 2021 Release 3 is currently in pre-release testing. This exciting new release adds the new API 2.0 Desktop controls, marking the completion of our transition to API 2.0.

DataObject.column(SelectedColumn) = DataObject.column(SelectedColumn) + 7

Inc( DataObject.column(SelectedColumn), 7 )

1 Like

Not if such “function” is not a real function, but a meta-function, like a macro, that the compiler solves in place, without calls, using just CPU registers in a load, increment (or add if using extra parameter), and store inline.

1 Like

Is that increment 7 times, or add 7 to the number?
If the former, you can only add integers
Also you would need at least matching decrement and other operators
Dec(… ?
Mult(… ?

For me

X = X+7
and
X = X * 56.3
is perfectly OK and a lot more understandable

3 Likes

It is the fastest option the processor can get. As used in the Pascal language.

https://www.freepascal.org/docs-html/rtl/system/inc.html

https://www.freepascal.org/docs-html/rtl/system/dec.html

Apparently you don’t know Ruby [then].

In Ruby all of the following are equivilent.

if a == 3 then
  a = 1
else
  a = 2
end
if a == 3
  a = 1
else
  a = 2
end
if a == 3 then a = 1 else a = 2 end
a = if a == 3 then 1 else 2 end
a = a == 3 ? 1 : 2

An if expression’s conditional in Ruby is separated from code by the reserved word then, a newline, or a semicolon. So there is a “keyword” or “key char”, also in Ruby.

Translation, please.

1 Like