jaytea commented on a Page, Demode  -  Sep 20, 2011

I dislike while-loops, unless they're needed.

i find this comment pretty disappointing. i'm not sure why, but i think it's because i've found your other comments to be quite sensible on the whole, and it pains me to see promising coders harbouring such irrational beliefs as this :P

you mentioned '$' up there as a method for iterating over a series of users, presumably passed as /demode nick1 nick2 etc. i assume your thought process was that since you have previously seen $'s ability to facilitate a loop through each $N, that it would be suitable here, requiring only slight changes to the original code. to understand why $ is not suitable, you probably have to understand exactly how it works. as mIRC evaluates your line of code and comes across $ used as an identifier, it replaces it with a marker (~$*) and continues to evaluate that line **to completion**. this means $len($*) becomes $len(~$) and evaluates to '4' before the internal loop has even begun. only when it's finished does mIRC go back and replace `~$ when performing the resulting command for each $N. what does this mean for us? clearly, we cannot use $ in an identifier since it will just be treated as `~$.

to overcome this, you may have seen the ol' /scon or /scid trick to, with the right escaping of code, set up a command that will be re-evaluated by /scon or /scid when the replacements have been made. 7-8 years ago, back when mIRC gurus bounced ideas off each other daily on mirc.com's forums, when i first saw this used i was amazed. i mean, all those times i'd cursed the heavens for tempting us with such a nifty little feature as $* but failing to make it usable for what i needed, and it turns out it WAS always possible, albeit in a round-about sort of way. shortly after the idea was proposed, it was promptly shot down on the grounds that re-evaluation of code could be disastrous in certain cases, and it was not worth using since we would constantly have to explain the caveat involved, which is not very easy for a beginner to comprehend. our simple while loop becomes a cacophony of symbols and constructs that leave one thinking 'wtf' and a disclaimer is added to explain, in our bizarre jargon, how the code has the potential to be devastating. not very beginner friendly, would you agree? :P

i might as well bring up $regsubex() loops while i'm at it. no sooner was mIRC 6.17 released than i realized $regsubex()'s enormous potential for replacing code. i say 'replacing' rather than 'improving' or 'optimizing' because quite often, neither of those things are achieved. $regsubex is such a powerful identifier that can be used in so many different ways that it's very easy to misuse. for example:

tokenize 32 $regsubex($str(a, $nick(#, 0)), /a/g, $nick(#, \n) $chr(32)) | commands with $*

vs.

var %i = 1 | while ($nick(#, %i)) { commands with $v1 | inc %i }

i see that a lot and it makes my stomach turn. the lengths people will go to to avoid using such a simple and convenient feature simply astounds me. the first example is much more limited, both by the line length limit on the return value of $regsubex() and by the type of commands you can later perform with $*; it's a complete mess, good luck explaining the logic to a beginner; it's slower, but only marginally so; it's longer, if you're into that kind of thing. it literally offers no benefit whatsoever over the while loop version.

what i wouldn't want to be guilty of, however, is depriving users of experiencing the awe that seeing these methods used for the first time inspires in the new scripter. to me, one version of code can be translated into the other systematically, with no thought or creativity required at this point.. but i can appreciate that they may be interesting to others. there's a LOT more to coding, even in the mIRC world, than the structure of your iterative procedures, and it is a real waste of effort to actively avoid what is so simple and straight forward

as always, sorry for the rant. i've been meaning to rant about this for a while :P

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.