Ruby-dev summary 18458-18504

Hi all,

Sorry to post so late. This is a summary of ruby-dev ML
in these days.

---- ruby-dev #18458-18504 (2002-10-05 … 2002-10-12) ----

[ruby-dev:18471] How about String#clear?

YANAGAWA Kazuhisa proposed a method String#clear. The
method set the string empty, like Array#clear for Array.
It can be defined in Ruby as follows:

class String
  def clear
    replace ""
  end
end

[ruby-dev:18465] warning for outer local variable assignment by block parameter

Tanaka Akira proposed warning for outer local variable assignment
by block parameter.

(ex.)
i = 0
foo.each{|i| ## <= warning

GOTO Kentaro doubted if it is not the rare conditions, but Matz
thinks that the frequency is not much for the risk, so it will
be implemented.

[ruby-dev:18482] mem leak?

WATANABE Tetsuya pointed out that in 1.7.3(at 10/10 morning)
a script which uses large objects consumes huge memory and it
leads pageout.

Akira Tanaka suggested that GC should be triggered when
the amount of the allocated memory is more than two times
of the memory which used by live objects.

Nobuyoshi Nakada made a patch ([ruby-dev:18487]) and commited
it.

TAKAHASHI ‘Maki’ Masayoshi E-mail: maki@rubycolor.org

… as inspired by how gc is exactly done in Lua, perhaps? :slight_smile:

Regards,

Bill

···

===========================================================================
TAKAHASHI Masayoshi maki@rubycolor.org wrote:

Akira Tanaka suggested that GC should be triggered when
the amount of the allocated memory is more than two times
of the memory which used by live objects.

Nobuyoshi Nakada made a patch ([ruby-dev:18487]) and commited
it.

  i = 0
  foo.each{|i| ## <= warning
    .....

GOTO Kentaro doubted if it is not the rare conditions, but Matz
thinks that the frequency is not much for the risk, so it will
be implemented.

Well, because I've a modified version which test this, here the result for
the scripts in the distribution of ruby

I've removed test.rb (which is probably a special case)

pigeon% for i in `ls **/*.rb`

do
ruby -c $i | grep -v OK
done

ext/syslog/test.rb:69: warning: shadowing variable `param'
ext/tk/lib/tk.rb:1420: warning: shadowing variable `elem'
ext/tk/lib/tk.rb:1531: warning: shadowing variable `conf'
ext/tk/lib/tk.rb:1590: warning: shadowing variable `conf'
ext/tk/lib/tk.rb:3718: warning: shadowing variable `slot'
ext/tk/lib/tk.rb:3718: warning: shadowing variable `value'
lib/cgi-lib.rb:173: warning: shadowing variable `x'
lib/cgi-lib.rb:187: warning: shadowing variable `x'
lib/debug.rb:328: warning: shadowing variable `b'
lib/debug.rb:614: warning: shadowing variable `n'
lib/debug.rb:804: warning: shadowing variable `th'
lib/fileutils.rb:303: warning: shadowing variable `dir'
lib/fileutils.rb:433: warning: shadowing variable `r'
lib/fileutils.rb:434: warning: shadowing variable `w'
lib/getopts.rb:108: warning: shadowing variable `opt'
lib/getopts.rb:108: warning: shadowing variable `val'
lib/getopts.rb:111: warning: shadowing variable `opt'
lib/getopts.rb:111: warning: shadowing variable `val'
lib/matrix.rb:598: warning: shadowing variable `i'
lib/matrix.rb:657: warning: shadowing variable `i'
lib/mkmf.rb:300: warning: shadowing variable `dir'
lib/net/http.rb:732: warning: shadowing variable `res'
lib/net/http.rb:751: warning: shadowing variable `res'
lib/net/protocol.rb:613: warning: shadowing variable `line'
lib/net/protocol.rb:668: warning: shadowing variable `i'
lib/net/protocol.rb:683: warning: shadowing variable `i'
lib/optparse.rb:85: warning: shadowing variable `k'
lib/optparse.rb:85: warning: shadowing variable `v'
lib/optparse.rb:240: warning: shadowing variable `s'
lib/optparse.rb:241: warning: shadowing variable `s'
lib/optparse.rb:255: warning: shadowing variable `s'
lib/optparse.rb:257: warning: shadowing variable `s'
lib/optparse.rb:414: warning: shadowing variable `o'
lib/optparse.rb:415: warning: shadowing variable `o'
lib/optparse.rb:416: warning: shadowing variable `o'
lib/optparse.rb:418: warning: shadowing variable `o'
lib/optparse.rb:911: warning: shadowing variable `o'
lib/optparse.rb:943: warning: shadowing variable `o'
lib/optparse.rb:1065: warning: shadowing variable `arg'
lib/optparse.rb:1145: warning: shadowing variable `arg'
lib/optparse.rb:1189: warning: shadowing variable `el'
lib/optparse.rb:1209: warning: shadowing variable `k'
lib/optparse.rb:1235: warning: shadowing variable `opt'
lib/optparse.rb:1368: warning: shadowing variable `s'
lib/racc/parser.rb:194: warning: shadowing variable `tok'
sample/cal.rb:40: warning: shadowing variable `d'
sample/cal.rb:110: warning: shadowing variable `m'
sample/philos.rb:50: warning: shadowing variable `i'
sample/test.rb:105: warning: shadowing variable `a'
[...]
sample/test.rb:991: warning: shadowing variable `i'
win32/resource.rb:53: warning: shadowing variable `icons'
pigeon%

Some of these shadowings are volontary.

Guy Decoux

If this is now considered “bad style”, why was it allowed at
the beginning? I thought that the current semantics were the
result of a trade-off between expressive power/performance and
inability-to-shoot-yourself-in-the-foot.

matz’s latest proposal clearly showed that he thought that assigning
to an external variable was justified in some occasions, and now he’s
kinda saying that it should be avoided???

···

On Wed, Oct 16, 2002 at 06:48:45AM +0900, TAKAHASHI Masayoshi wrote:

Hi all,

Sorry to post so late. This is a summary of ruby-dev ML
in these days.

[ruby-dev:18465] warning for outer local variable assignment by block parameter

Tanaka Akira proposed warning for outer local variable assignment
by block parameter.

(ex.)
i = 0
foo.each{|i| ## <= warning

GOTO Kentaro doubted if it is not the rare conditions, but Matz
thinks that the frequency is not much for the risk, so it will
be implemented.


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Those who don’t understand Linux are doomed to reinvent it, poorly.
– unidentified source

Hi,

···

At Wed, 16 Oct 2002 14:50:10 +0900, ts wrote:

Some of these shadowings are volontary.

At least, yes for lib/optparse.rb.


Nobu Nakada

matz's latest proposal clearly showed that he thought that assigning
to an external variable was justified in some occasions, and now he's
kinda saying that it should be avoided???

Well, the latest that I know is [ruby-talk:52440] where there is

[...]
  * variables assigned by ":=" should be local to the block (or
    possibly local to the nearest compound statements).

  * if ":=" assignee is already defined in outer scope, it should be
    warned (no -w needed, probably), and outer variable is shadowed
    hereafter.

  * all local variables in block parameters (e.g. var in |var|) should
    be treated as if they are assigned by ":=". other types of
    variables in block parameter should be warned.
[...]

This mean that you have a warning in this case.

Guy Decoux

Hi,

If this is now considered “bad style”, why was it allowed at
the beginning? I thought that the current semantics were the
result of a trade-off between expressive power/performance and
inability-to-shoot-yourself-in-the-foot.

Because I was stupid. This is bad manner.

matz’s latest proposal clearly showed that he thought that assigning
to an external variable was justified in some occasions, and now he’s
kinda saying that it should be avoided???

I think I just said “it’s possible”. But it doesn’t mean it is
encouraged. And I’m saying it should be avoided.

						matz.
···

In message “Re: ruby-dev summary 18458-18504” on 02/10/16, Mauricio Fernández batsman.geo@yahoo.com writes:

Some of these shadowings are volontary.

Obviously the original example will produce a warning:

i = 0
foo.each{|i| ## <= warning

But can’t we still do:

i = 0
foo.each { |i_|
i = i_
}

without losing too much?

Paul

···

On Wed, Oct 16, 2002 at 02:50:10PM +0900, ts wrote:

At least, yes for lib/optparse.rb.

lib/fileutils.rb also I think

  def copy_file( src, dest )
    st = r = w = nil

    File.open( src, 'rb' ) {|r|
    File.open( dest, 'wb' ) {|w|
        st = r.stat
        begin
          while true do
            w.write r.sysread(st.blksize)
          end
        rescue EOFError
        end
    } }
  end

Guy Decoux

Some of these shadowings are volontary.

[...]

  i = 0
  foo.each { |i_|
    i = i_
  }
without losing too much?

Read [ruby-talk:53308] you don't find something strange ?

Guy Decoux

···

On Wed, Oct 16, 2002 at 02:50:10PM +0900, ts wrote:

Speed :stuck_out_tongue:

···

On Wed, Oct 16, 2002 at 10:56:07PM +0900, Paul Brannan wrote:

On Wed, Oct 16, 2002 at 02:50:10PM +0900, ts wrote:

Some of these shadowings are volontary.

Obviously the original example will produce a warning:

i = 0
foo.each{|i| ## <= warning

But can’t we still do:

i = 0
foo.each { |i_|
i = i_
}

without losing too much?


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Even more amazing was the realization that God has Internet access. I
wonder if He has a full newsfeed?
– Matt Welsh

Read [ruby-talk:53308] you don’t find something strange ?

I find something strange (to me at least…):

Why needs first:
st = r = w = nil

and then shadows these variables? These variables are not used after the
block… (?)

Yes, it does look strange. Why bother assigning nil to r and w if the
value is just going to be thrown away?

Paul

···

On Wed, Oct 16, 2002 at 11:01:22PM +0900, ts wrote:

Read [ruby-talk:53308] you don’t find something strange ?

Read [ruby-talk:53308] you don’t find something strange ?

Yes, it does look strange. Why bother assigning nil to r and w if the
value is just going to be thrown away?

Paul

I believe that if the people who originally wrote the library code did it
again, their collected experience in Ruby would cause them to write them in a
better style.

These and the sample code deserve to be revisited, but it’s hardly as high
priority.

Gavin

···

From: “Paul Brannan” pbrannan@atdesk.com

On Wed, Oct 16, 2002 at 11:01:22PM +0900, ts wrote:

Hi,

In mail “Re: ruby-dev summary 18458-18504”

···

Carlos angus@quovadis.com.ar wrote:

Read [ruby-talk:53308] you don’t find something strange ?

I find something strange (to me at least…):

Why needs first:
st = r = w = nil

and then shadows these variables? These variables are not used after the
block… (?)

It is there just because for peephole optimization.
Pure local variables is faster than block local variables.

– Minero Aoki

Hi,

This looks to me like some performance fine tuning which is achieved
through some non-explicit language facility. Probably it is time to
consider something like what Pyrex has done for Python? (I.e., if we want
to increase performance, in my opinion, it is better to do it using some
explicit facility instead of creating some “rather confusing” code).

Also, the technique “pure local variables are faster than block local
variables” will seem inconsistent when (and if) we have explicit block
local variables in the future (such as using “:=”, “_var”, “local”, “;”,
etc.).

Regards,

Bill

···

============================================================================
Minero Aoki aamine@loveruby.net wrote:

Why needs first:
st = r = w = nil

and then shadows these variables? These variables are not used after the
block… (?)

It is there just because for peephole optimization.
Pure local variables is faster than block local variables.