From: Matthew Kerwin <matthew@...>
Date: 2014-01-20T10:19:03+10:00
Subject: [ruby-core:59878] Re: [ruby-trunk - Feature #9428] Inline argument expressions and re-assignment

--001a11c36c50d654a104f05bd6ae
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

I'm -1 for this.

1. aesthetically: it puts some of the function's code outside the
function's body, which makes it harder to follow a function's execution
when reading code, and it makes the signature unnecessarily messy.

2. syntactically: none of the proposals you've given make enough sense, at
least for me personally to understand what they mean:

  def foo( arg.to_i )
  def foo( arg.to_i as arg )

Is the left-most 'arg' a local variable, or referring to self#arg, or
something else..?

> Ruby could auto-assign the passed argument to the first variable
encountered in the expression.

According to my understanding of the parser, any heretofore unseen
"bareword" tokens are interpreted as function calls, so there is no "first
variable encountered."  It works for optional positional parameters because
they have an equals sign in (and 'bareword =3D expression' is universally
lvar creation/assignment, in Ruby).

3. debugability: the 'def' line is a single line, however there's no real
limit to the number of parameters you can include in that line.  If each of
those parameters can include arbitrary expressions, well, I'd hate to have
to debug a "NoMethodError: undefined method ... for nil:NilClass" on that
line.  And if the answer to that is to split the 'def' line over multiple
lines, then why not just put the expressions on those multiple lines anyway=
?

4. orthogonality: what about non-optional keyword arguments?

For what it's worth, I'm not entirely *for* allowing arbitrary expressions
in optional parameters either, but in that case I can't think of a better
representation.  But if I ever seen anything more than a #[] call in a
default value I consider it Bad Form=99.

--=20
  Matthew Kerwin
  http://matthew.kerwin.net.au/

--001a11c36c50d654a104f05bd6ae
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-family:georgia,=
serif;color:rgb(7,55,99)">I&#39;m -1 for this.</div><div class=3D"gmail_def=
ault" style=3D"font-family:georgia,serif;color:rgb(7,55,99)"><br></div><div=
 class=3D"gmail_default" style=3D"font-family:georgia,serif;color:rgb(7,55,=
99)">
1. aesthetically: it puts some of the function&#39;s code outside the funct=
ion&#39;s body, which makes it harder to follow a function&#39;s execution =
when reading code, and it makes the signature unnecessarily messy.</div>
<div class=3D"gmail_default" style=3D"font-family:georgia,serif;color:rgb(7=
,55,99)"><br></div><div class=3D"gmail_default" style=3D"font-family:georgi=
a,serif;color:rgb(7,55,99)">2. syntactically: none of the proposals you&#39=
;ve given make enough sense, at least for me personally to understand what =
they mean:</div>
<div class=3D"gmail_default" style=3D"font-family:georgia,serif;color:rgb(7=
,55,99)"><br></div><div class=3D"gmail_default" style=3D"font-family:georgi=
a,serif;color:rgb(7,55,99)">=A0 def foo( arg.to_i )</div><div class=3D"gmai=
l_default" style=3D"font-family:georgia,serif;color:rgb(7,55,99)">
=A0 def foo( arg.to_i as arg )</div><div class=3D"gmail_default" style=3D"f=
ont-family:georgia,serif;color:rgb(7,55,99)"><br></div><div class=3D"gmail_=
default" style=3D"font-family:georgia,serif;color:rgb(7,55,99)">Is the left=
-most &#39;arg&#39; a local variable, or referring to self#arg, or somethin=
g else..?</div>
<div class=3D"gmail_default" style=3D"font-family:georgia,serif;color:rgb(7=
,55,99)"><br></div><div class=3D"gmail_default" style=3D"font-family:georgi=
a,serif;color:rgb(7,55,99)">&gt;=A0<span style=3D"font-family:arial,sans-se=
rif;font-size:13px;color:rgb(34,34,34)">Ruby could auto-assign the passed a=
rgument to the first variable encountered in the expression.</span></div>
<div class=3D"gmail_default" style=3D"font-family:georgia,serif;color:rgb(7=
,55,99)"><br></div><div class=3D"gmail_default" style=3D"font-family:georgi=
a,serif;color:rgb(7,55,99)">According to my understanding of the parser, an=
y heretofore unseen &quot;bareword&quot; tokens are interpreted as function=
 calls, so there is no &quot;first variable encountered.&quot; =A0It works =
for optional positional parameters because they have an equals sign in (and=
 &#39;bareword =3D expression&#39; is universally lvar creation/assignment,=
 in Ruby).</div>
<div class=3D"gmail_default" style=3D"font-family:georgia,serif;color:rgb(7=
,55,99)"><br></div><div class=3D"gmail_default" style=3D"font-family:georgi=
a,serif;color:rgb(7,55,99)">3. debugability: the &#39;def&#39; line is a si=
ngle line, however there&#39;s no real limit to the number of parameters yo=
u can include in that line. =A0If each of those parameters can include arbi=
trary expressions, well, I&#39;d hate to have to debug a &quot;NoMethodErro=
r: undefined method ... for nil:NilClass&quot; on that line. =A0And if the =
answer to that is to split the &#39;def&#39; line over multiple lines, then=
 why not just put the expressions on those multiple lines anyway?</div>
<div class=3D"gmail_default" style=3D"font-family:georgia,serif;color:rgb(7=
,55,99)"><br></div><div class=3D"gmail_default" style=3D"font-family:georgi=
a,serif;color:rgb(7,55,99)">4. orthogonality: what about non-optional keywo=
rd arguments?</div>
<div class=3D"gmail_default" style=3D"font-family:georgia,serif;color:rgb(7=
,55,99)"><br></div><div class=3D"gmail_default" style=3D"font-family:georgi=
a,serif;color:rgb(7,55,99)">For what it&#39;s worth, I&#39;m not entirely *=
for* allowing arbitrary expressions in optional parameters either, but in t=
hat case I can&#39;t think of a better representation. =A0But if I ever see=
n anything more than a #[] call in a default value I consider it Bad Form=
=99.</div>
<div class=3D"gmail_extra"><div><br></div>-- <br><div dir=3D"ltr">=A0 Matth=
ew Kerwin<br>=A0 <a href=3D"http://matthew.kerwin.net.au/" target=3D"_blank=
">http://matthew.kerwin.net.au/</a></div>
</div></div>

--001a11c36c50d654a104f05bd6ae--