From: Robert Klemme Date: 2013-07-09T15:45:50+09:00 Subject: Re: A very half-baked idea: setting local variables --047d7bb03d36e0602704e10e8221 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Jul 9, 2013 at 1:14 AM, Matthew Kerwin wrote: > Hal Fulton wrote in post #1114777: > > > > Note that this wouldn't be a method call (like alias_method) but > > a keyword (like alias) unless "binding of caller" was permitted... > > which is another thing I've wanted but I suppose will never > > happen. > > > > Comments, questions, projectiles? > > Yeah, I agree with Robert, there's no need to dynamically create local > variables, just use a hash (dynamically created keys are fine). And my > initial gut response is: if you're writing that many variables on the > left hand side of an assignment, with a single array on the right, > there's probably something wrong with the architecture. > That situation frequently occurs when reading data e.g. from CSV files. If the file has that many columns it makes sense to have local variables for them to ease handling. OTOH then you probably use something like CSV.foreach "a.csv" do |foo, bar, baz, alpha, beta| puts "foo is #{foo}" end Or one defines a Struct and puts values in there instead of having them in an Array. My other counter-proposal is: hit enter. If the line is too long, > develop a syntactic signature for the pattern. For example: > > foo, bar, baz, alpha, beta, > gamma, fred, bill, joey = *values > > (i.e. lining up the rightmost column, so it's clear that all wrapped > lines lead to the single assignment operator). Still not great, but at > least the line isn't absurdly long, and you don't have to scan as far to > see the '=' > I like that approach. > Finally, as a bike-shedding nit-pick: if it were a keyword, convention > suggests there'd be no comma; and I think putting the destinations on > the right is a bit confusing. So if I had to choose, I'd go for: > > assign %I[a b c] values > > But again, that's a big "if", and all in all I'm not too keen on the > idea of dynamically creating local variables. I forgot to mention: I do not see the original issue as such a big one, so my general bias would be against going through some hoops just to avoid lengthy left hand sides. I don't have them that often and if I have it does not bother me that much. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ --047d7bb03d36e0602704e10e8221 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Tue, Jul 9, 2013 at 1:14 AM, Matthew Kerwin &l= t;lists@ruby-foru= m.com> wrote:
Hal Fulton wrote in post #1114777:
>
> Note that this wouldn't be a method call (like alias_method) but > a keyword (like alias) unless "binding of caller" was permit= ted...
> which is another thing I've wanted but I suppose will never
> happen.
>
> Comments, questions, projectiles?

Yeah, I agree with Robert, there's no need to dynamically create = local
variables, just use a hash (dynamically created keys are fine). =A0And my initial gut response is: if you're writing that many variables on the left hand side of an assignment, with a single array on the right,
there's probably something wrong with the architecture.

That situation frequently occurs when reading da= ta e.g. from CSV files. =A0If the file has that many columns it makes sense= to have local variables for them to ease handling. =A0OTOH then you probab= ly use something like

CSV.foreach "a.csv" do |foo, bar, baz, alpha, beta|
=A0 puts "foo is #{foo}"
end
Or one defines a Struct and puts values in there instead= of having them in an Array.

My other counter-proposal is: hit enter. =A0If the line is too long,
develop a syntactic signature for the pattern. =A0For example:

=A0 =A0 foo, bar, baz, alpha, beta,
=A0 =A0 =A0 =A0 gamma, fred, bill, joey =3D *values

(i.e. lining up the rightmost column, so it's clear that all wrap= ped
lines lead to the single assignment operator). =A0Still not great, but at least the line isn't absurdly long, and you don't have to scan as f= ar to
see the '=3D'

I like that= approach.
=A0
Finally, as a bike-shedding nit-pick: if it were a keyword, convention
suggests there'd be no comma; and I think putting the destinations on the right is a bit confusing. =A0So if I had to choose, I'd go for:

=A0 =A0 assign %I[a b c] values

But again, that's a big "if", and all in all I'm not too = keen on the
idea of dynamically creating local variables.

I forgot to mention: I do not see the original i= ssue as such a big one, so my general bias would be against going through s= ome hoops just to avoid lengthy left hand sides. =A0I don't have them t= hat often and if I have it does not bother me that much.

Kind regard= s

robe= rt

--
remember.guy do |as, often| as.yo= u_can - without end
http://blog.rubybestpractice= s.com/
--047d7bb03d36e0602704e10e8221--