mIRC Home    About    Download    Register    News    Help

Print Thread
The use of { }'s. #182849 15/08/07 06:07 PM
Joined: Jan 2004
Posts: 509
L
LostShadow Offline OP
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
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.

Re: The use of { }'s. [Re: LostShadow] #182850 15/08/07 06:12 PM
Joined: Dec 2002
Posts: 2,016
R
RoCk Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,016
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
}


Re: The use of { }'s. [Re: RoCk] #182872 16/08/07 12:09 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
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


Invision Support
#Invision on irc.irchighway.net
Re: The use of { }'s. [Re: RoCk] #182875 16/08/07 12:22 AM
Joined: Jan 2004
Posts: 509
L
LostShadow Offline OP
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
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 }
}


Re: The use of { }'s. [Re: LostShadow] #182881 16/08/07 12:42 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
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