On Wednesday, January 29, 2003, 6:17:44 PM, Gavin wrote:

> On Wednesday, January 29, 2003, 5:04:51 PM, ahoward wrote:

>> (IO.readlines (path)).each do |line|
>>   export max = 0
>>   ...
>>   fields = line.split delim
>>   max = [max, fields].max
>>   ...
>> end

puts max    >>>> 42

>> what'dya think?


> There's obviously some support for this, but to me it's unnecessary.
> If I need to do code like that, I factor it into a method:

>   def find_max(...)
>     foo.bar.each do |quux|
>       ...
>       return max         # <- That, or ...
>     end
>     return max           #   ... that

>   max = find_max(...)

> I like small methods, and code like you've presented is a visual cue
> for me to refactor.

> None of this means the idea is without merit, though...

<random_raving>
  ...especially since I used to think that Java was readable enough if
  you keep the methods small. Then I realised that one method of Java
  is often one line of Ruby, because of things like #map. This export
  idea could be another good progression to reduce unnecessary
  methods.
</random_raving>

Could this be made a solution to the block parameter scoping problem?
(I don't remember any concrete decision on that.)  That is, make all
parameters local, and then use "export" to export the one(s) you want
to be visible from outside?

  b = 5
  foo { |b| ... }
  b                   # -> 5

  x = -9
  bar do |x|
    export x
    ...
  end
  x                   # -> something else, set within 'bar'

Since the latter code is rarely needed, this seems like a good
solution to me.

Gavin