News for hackers. Stuff that matters.
Re:"Useless syntax sugar": Numbered block parameters in Ruby by dragonwriter on Wednesday October 11, 2023 @01:03PM (#37847109)
_1 takes two characters per use, single-character explicitly named variables take one character per use plus 3 per variable (4 for the first), counting spaces, so you save two characters (three for the first) if the variable is used once, minus one per additional use of a variable.

With only one variable, and sometimes with very simple expressions with more than one, you probably get a readability benefit by avoiding stuttering:

  { _1 + _2 }
reads a little better than:

  { |x, y| x + y }
But with any even slightly complex expression in the block, that goes from a benefit to a cost.

There are no comments on this comment yet.