From: "trans. (T. Onoma)" Date: 2004-09-29T09:51:27+09:00 Subject: Re: Best name for "this method" ? On Tuesday 28 September 2004 02:44 am, Jim Haungs wrote: > I'll preface this with saying I don't know Ruby yet as well as I know > Smalltalk, so please correct any fine points I get wrong. > > In Smalltalk, the calling context is called "thisContext" because it > can be either a method or a block. And it returns an actual context > object, which are represented by a class in Smalltalk, but which are > not (as far as I can tell) reified in Ruby. > > So if you implemented it in Ruby, you'd have to decide whether it > referred to the block context or the enclosing method context, > and you'd have to invent a reification of the dynamic execution > context, as the method name by itself isn't very useful. > > I'd certainly think twice about adding it to the language. What you > explicitly leave out of a language is as important as what you put in. > > In 20+ years of reading and writing Smalltalk, I've hardly ever used > it or seen it used except for writing debuggers and similar tools that > deal with dynamic execution state. > > I wanted to include some statistics on its use in Smalltalk, but > unfortunately, it's not a true message send in VisualWorks; it's > inlined by the compiler. So you'd have to write some bytecode scanning > code to find where it's called (which might be fun!) Did anyone ever respond to you? If no, we's very sorry. Actually Ruby has something quite like thisContext called a Binding. At least I think they would be the same according to your description. (Yes, the Smalltalk name is probably better.) Bindings are a bit heavy weight (I think) for just getting the current method name. Although, it would be cool if Bindings had little to no cost, then we could use the heck out of em. Anyone know what the costs associated with Bindings are more exactly? T.