Originally Posted By: argv0
Helpful as this may be, I'm not sure I see the duplication of one extra word as a "major" shortcoming. The difference between a hypothetical $calias and $ctimer/$sockname is that the latter two can be specified to have dynamic names-- aliases cannot, so "hardcoding the name" is really no more hardcoded than it already is. In any case, this seems more like a band-aid on a much greater problem you've alluded to with your example, that problem being the weak state of error handling support in mIRC.

The concept of DRY is more about keeping away from having to repeat code indefinitely. Deciding between writing something exactly once versus exactly twice is not exactly a serious concern to most people. To follow through with your example, the duplication of the term "blabla_blabla" would only become a point of contention if you were to rename the alias name altogether. Of course, most likely if you renamed an alias you would be spending far more time searching through code finding references to the call as compared to the one extra change inside the alias body (the one you're most likely to see). Having this one extra duplication, as annoying as it may seem, is actually not all that error prone. Using your suggested $calias identifier, the example would turn into:

Code:
alias bl_alias1 {
  if ($insufparscheckaliasname($calias,8,$1-)) { return }
  ...
}
alias bl_alias2 {
  if ($insufparscheckaliasname($calias,8,$1-)) { return }
  ...
}
alias bl_alias3 {
  if ($insufparscheckaliasname($calias,8,$1-)) { return }
  ...
}
...

In the end, if we scale the example up, it doesn't really look all that much cleaner from the original example. As you can see, the real eye-sore is that check to begin with, and we still have a lot of repeated code. This is where I start failing to see the benefit of the suggested identifier. You either duplicate a line with a different alias name, or you duplicate the entire line, but really in both cases you're still duplicating the entire line. You could almost say that having to write out the alias name almost justifies the duplication of that error checking line, though I won't take it that far.

'Cleaner code'?
Did I say that the purpose of this feature request was 'cleaner code' as in 'cosmetics'?
No.
You seem to have missed what I ment.
I will try explaining again.
The purpose is to have less code writing/debugging/code maintaining work.
Code:
alias blacklist_add {
  if ($pcc($calias,6,$1-)) { return }
  ...
}
alias blacklist_remove {
  if ($pcc($calias,3,$1-)) { return }
  ...
}
alias serverlist_add {
  if ($pcc($calias,7,$1-)) { return }
  ...
}
alias serverlist_get {
  if ($pcc($calias,4,$1-)) { return }
  ...
}
...

compared to
Code:
alias blacklist_add {
  if ($pcc(blacklist_add,6,$1-)) { return }
  ...
}
alias blacklist_remove {
  if ($pcc(blacklist_remove,3,$1-)) { return }
  ...
}
alias serverlist_add {
  if ($pcc(serverlist_add,7,$1-)) { return }
  ...
}
alias serverlist_get {
  if ($pcc(serverlist_get,4,$1-)) { return }
  ...
}
...


If I have to write a new alias, I can copy an existing line and only need to change the number of required parameters.
And this is not 'repeated code' as such, this is a location-bound (every alias has its own amount needed parameters) condition that checks an identifier. Repeated code is code that isn't location bound, so can be moved to an alias that is given parameters representing the location bound remainder.

That's why I proposed an identifier returning the aliasname the code belongs to, or even better, an identifier (like $ctimer) that on the called place that returns the name of the alias that called it.
Then it looks like this:
Code:
alias blacklist_add {
  if ($pcc(6,$1-)) { return }
  ...
}
alias blacklist_remove {
  if ($pcc(3,$1-)) { return }
  ...
}

alias serverlist_add {
  if ($pcc(7,$1-)) { return }
  ...
}
alias serverlist_get {
  if ($pcc(4,$1-)) { return }
  ...
}
...

and
Code:
alias pcc {
  if ($1 <= $numtok($2-,32)) { return 0 }
  RE Insufficiƫnt $+($v2,/,$1) parameters passed to alias $calias
  return 1
}


Last edited by RRX; 10/05/09 11:18 AM.