mIRC Homepage
Posted By: LostShadow The use of { }'s. - 15/08/07 06:07 PM
Sorry, I never really got into the reason of "not" using { }'s.

The way I learned to use { } was for cases like..:
stuff {
if (statement) { command }
if (statement) { command }
if (statement) { command }
}

And the case to not use { } would be..

stuff {
if (statement) command
}

Since mIRC's been sometimes freezing, and I have to Ctrl Break over and over, I figured I should add a { } for every if (statement) command?

-Neal.
Posted By: RoCk Re: The use of { }'s. - 15/08/07 06:12 PM
I find myself using brackets only if there will be more than 1 command...

Code:

if (something) {
  command1
  command2
  command3
}



but if only one command I don't use them...

Code:

if (something) command1



As for your stuff alias, don't forget to use elseif so every line is not processed...

Code:

stuff {
  if (something) command
  elseif (something) command
  elseif (something) command
}

Posted By: Riamus2 Re: The use of { }'s. - 16/08/07 12:09 AM
Apparently, using {}'s when not needed will slow down your scripts to a *very* small degree. In the majority of cases, you will not be able to notice the slower speed even with dozens of scripts loaded. So, in my personal opinion, I think it's better to stick to a standard syntax for everything rather than going back and forth all of the time. I'll use {}'s even when it's all one command on a single line except in rare cases. But that's just me. As long as you only have a single command being done, the {}'s are not necessary unless the code is ambiguous (you can't easily tell what is part of the IF or whatever command and what is being done after).

Originally Posted By: RoCk
As for your stuff alias, don't forget to use elseif so every line is not processed...


Well, that depends on what your script is doing. smile
Posted By: LostShadow Re: The use of { }'s. - 16/08/07 12:22 AM
Originally Posted By: RoCk

Code:

stuff {
  if (something) command
  elseif (something) command
  elseif (something) command
}



Uh, I was comparing that between..

This:

Code:

stuff {
  if (something) { command }
  elseif (something) { command }
  elseif (something) { command }
}

Posted By: Horstl Re: The use of { }'s. - 16/08/07 12:42 AM
I do second Riamus2's opinion ("opinion" as in most cases, it's a matter of personal preference or style).
I'm putting virtually all brackets, be it { } arround commands or ( ) arround conditions, no matter how simple or complex the condition/command part is.

There had been much talk about speed issues - issues that will
rarely matter in practise...

Imho, the most univocal style is the best: best for others who want to understand that particular piece of code, and best for oneself - everyone who wanted to modify a script he has written a jear or so ago will know what I mean. wink

© mIRC Discussion Forums