Notifications
Clear all

[Closed] MXS Code Standards: Using of if/then vs. if/do

I don’t want debates here. Just it will be interesting to know how many mxs develoreprs using if…then vs. if…do in statement where ‘esle’ is not expected (follows)

15 Replies

the first question has to read as:

I always use ‘if…do’ if a statement doesn’t need ‘else’

ps. does anyone know how to edit poll questions?

I always use “if…do” if a statement doesn’t need “else”.

1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

Yep.
For one statement “if…do
For two statement “if…then…else
But if code requires more then two statements I rather use “case of” then “if…then…else if

my understanding is that if…do was created for implementing conditional statements in the listener.

I only use if…then in my scripts

I always use the “normal” if…then… Never used another language that had “if do” so I was never familiar with it, if then seems much more standardized and natural.

4 Replies
(@denist)
Joined: 11 months ago

Posts: 0

this is not really an argument for me. there are many other things in mxs that don’t have analog in another languages.
also most of languages that have if/then have ‘end if’, or any other notification for end of if/then statement. mxs doesn’t have it. that’s why i prefer to use ‘do’ in case where ‘then’ is not followed by ‘else’ .

(@denist)
Joined: 11 months ago

Posts: 0

give me please any example of a language that still in use and uses if/then without ‘end if’

(@kameleon)
Joined: 11 months ago

Posts: 0

Sorry I couldn’t figure out where you draw that conclusion from what I’ve said. Anyhow, end if?! I haven’t seen that in a while, C++, C#, Python, I don’t think any of those use it.

Regarding ‘for’ well, I guess there isn’t another way to do it without writing a bunch more lines of code so I’m okay with that. With the ‘if-clause’ we have options, and I prefer the one that’s more standard.

(@zhalktis)
Joined: 11 months ago

Posts: 0

Well, let’s see:
Delphi, Lua, io, Haskell, Chapel, CLIPS and in some cases COBOL, and a bunch of obscure ones.

If you drop the arbitrary no “endif” requirement – there are many “if…then” languages still actively in use.

However there are no languages that primarily use “if…do” instead of “if…then”. In many languages “do” is mostly reserved to while-loops or for-loops. Even C/C++ and C-inspired languages, which don’t have “if…then” and don’t require a “do” with a “while” loop; they have a “do-while” loop that is necessarily of the form: do{stuff} while(condition);

I prefer keeping it that way in maxscript for readability purposes. It’s just convenient to see “do” and instantly know you’re looking at a repeatable loop, while seeing “then” means you’re looking at a conditional. Readability of “else” seems to be mostly taken care of by proper indentation style.

“if…do…else” sounds just wrong…

i use “If…do” when “then” is not needed.

Is there any advantage to using “do” instead of “then” for single-case if statements?

For one thing, if you use “do”, then decide later to add an “else” clause, that’s more to edit (and to remember to edit).

Also, and I had to look it up since I haven’t touched it in decades, but I taught myself to program in the 80’s in Pascal, and it also uses “if-then-else” very much like maxscript. That’s how I’ve always thought about this control structure, even when using languages (most languages?) that omit the “then” or “do” between the expression and the block of code.

If I open a code and I find

"if..then"
  • I’m looking always for
"else"
 If I find  
"If..do"

then I know that there is no other condition that differs from this “if”.
When dealing with a lot of “ifs” I love also to use

 "case of"
 Instead of "for m in mm if..." I started to use  
"for m in mm where..."

… and i never saw a language that uses ‘where’ and ‘while’ in the ‘for’ loop. following the same logic – do we have not to use it?

I believe Dennis’ point is that most languages have no explicit then statement.
but rather just wrap the then-statement in brackets

if (condition)
{
    then-statement;
}
else
{
    else-statement;
}
Page 1 / 2