[#144186] Re: array of object insert polices — "Pe, Botp" <botp@...>

dave [mailto:dave.m@email.it] wrote:

14 messages 2005/06/01

[#144206] Implementing a Read-Only array — Gavin Kistner <gavin@...>

Right up front, let me say that I realize that I can't prevent

14 messages 2005/06/01

[#144224] Method Chaining Issues — "aartist" <aartist@...>

try this:

28 messages 2005/06/01
[#144231] Re: Method Chaining Issues — "Phrogz" <gavin@...> 2005/06/01

This is a FAQ, though no page on the RubyGarden wiki seems to address

[#144240] Re: Method Chaining Issues — Nikolai Weibull <mailing-lists.ruby-talk@...> 2005/06/01

Phrogz wrote:

[#144230] ternary operator confusion — Belorion <belorion@...>

I don't know if this is "improper" use of the ternary operator, but I

19 messages 2005/06/01
[#144233] Re: ternary operator confusion — "Phrogz" <gavin@...> 2005/06/01

true ? a.push(1) : a.push(2)

[#144257] Re: ternary operator confusion — "Marcel Molina Jr." <marcel@...> 2005/06/01

On Thu, Jun 02, 2005 at 01:40:23AM +0900, Phrogz wrote:

[#144263] Re: ternary operator confusion — Eric Mahurin <eric_mahurin@...> 2005/06/01

--- "Marcel Molina Jr." <marcel@vernix.org> wrote:

[#144453] RubyScript2Exe and GUI toolkits — Erik Veenstra <pan@...>

13 messages 2005/06/03

[#144487] Building a business case for Ruby — Joe Van Dyk <joevandyk@...>

Hi,

29 messages 2005/06/03

[#144535] ruby-dev summary 26128-26222 — Minero Aoki <aamine@...>

Hi all,

11 messages 2005/06/04

[#144579] Package, a future replacement for setup.rb and mkmf.rb — Christian Neukirchen <chneukirchen@...>

29 messages 2005/06/04

[#144672] newbie read.scan (?) question — "Bruce D'Arcus" <bdarcus.lists@...>

Hi,

16 messages 2005/06/06

[#144691] making a duck — Eric Mahurin <eric_mahurin@...>

Regarding duck-typing... Is there an easy way make a "duck"?

27 messages 2005/06/06

[#144867] ruby-wish@ruby-lang.org mailing list — dave <dave.m@...>

19 messages 2005/06/08
[#144870] Re: [PROPOSAL] ruby-wish@ruby-lang.org mailing list — "Robert Klemme" <bob.news@...> 2005/06/08

Austin Ziegler wrote:

[#144890] RubyStuff: The Ruby Shop for Ruby Programmers — James Britt <james_b@...>

Announcing the formal grand opening of Ruby Stuff: The Ruby Shop for

36 messages 2005/06/08

[#144966] python/ruby benchmark. — "\"</script>" <groleo@...>

I took a look at

78 messages 2005/06/09
[#144967] Re: python/ruby benchmark. — gabriele renzi <surrender_it@...> 2005/06/09

"</script> ha scritto:

[#144974] Re: python/ruby benchmark. — Lothar Scholz <mailinglists@...> 2005/06/09

Hello gabriele,

[#144977] Re: python/ruby benchmark. — Kent Sibilev <ksruby@...> 2005/06/09

Java is an order of magnitude faster than Ruby. The development of a

[#144980] Re: python/ruby benchmark. — Lothar Scholz <mailinglists@...> 2005/06/09

Hello Kent,

[#144983] Re: python/ruby benchmark. — "Ryan Leavengood" <mrcode@...> 2005/06/09

Lothar Scholz said:

[#145196] Re: python/ruby benchmark(don't shoot the messenger) — ptkwt@... (Phil Tomson) 2005/06/12

In article <9e7db91105061106485b68d629@mail.gmail.com>,

[#145207] Re: python/ruby benchmark(don't shoot the messenger) — Steven Jenkins <steven.jenkins@...> 2005/06/12

Phil Tomson wrote:

[#145212] Re: python/ruby benchmark(don't shoot the messenger) — Austin Ziegler <halostatue@...> 2005/06/12

On 6/12/05, Steven Jenkins <steven.jenkins@ieee.org> wrote:

[#145219] Re: python/ruby benchmark(don't shoot the messenger) — Steven Jenkins <steven.jenkins@...> 2005/06/12

Austin Ziegler wrote:

[#145223] Re: python/ruby benchmark(don't shoot the messenger) — Austin Ziegler <halostatue@...> 2005/06/12

On 6/12/05, Steven Jenkins <steven.jenkins@ieee.org> wrote:

[#145240] Re: python/ruby benchmark(don't shoot the messenger) — Steven Jenkins <steven.jenkins@...> 2005/06/12

Austin Ziegler wrote:

[#145241] Re: python/ruby benchmark(don't shoot the messenger) — Austin Ziegler <halostatue@...> 2005/06/13

On 6/12/05, Steven Jenkins <steven.jenkins@ieee.org> wrote:

[#145000] RDoc

Hi, I have a question. When I compiled ruby-1.8.2

13 messages 2005/06/09
[#145003] Re: RDoc — Eric Hodel <drbrain@...7.net> 2005/06/09

On 09 Jun 2005, at 13:55, Jesffffas Antonio Sfffe1nchez A. wrote:

[#145238] finding Hash subsets based on key value — "ee" <erik.eide@...>

Hi

17 messages 2005/06/12

[#145304] PDF::Writer 1.0 (version 1.0.1) — Austin Ziegler <halostatue@...>

= PDF::Writer

21 messages 2005/06/13
[#145411] Re: [ANN] PDF::Writer 1.0 (version 1.0.1) — Jason Foreman <threeve.org@...> 2005/06/14

No love from PDF::Writer on Mac OS X 10.4.1. I hope to get this fixed

[#145420] Re: [ANN] PDF::Writer 1.0 (version 1.0.1) — Austin Ziegler <halostatue@...> 2005/06/14

On 6/14/05, Jason Foreman <threeve.org@gmail.com> wrote:

[#145432] Re: [ANN] PDF::Writer 1.0 (version 1.0.1) — Jamis Buck <jamis@37signals.com> 2005/06/15

On Jun 14, 2005, at 5:11 PM, Austin Ziegler wrote:

[#145339] survey: what editor do you use to hack ruby? — Lowell Kirsh <lkirsh@...>

I've been having a tough time getting emacs set up properly with ruby

62 messages 2005/06/14

[#145390] Ruby and recursion (Ackermann benchmark) — ptkwt@... (Phil Tomson)

14 messages 2005/06/14

[#145586] How to make a browser in Ruby Tk — sujeet kumar <sujeetkr@...>

Hi

13 messages 2005/06/16

[#145636] Super-scalar Optimizations — "Phrogz" <gavin@...>

I was looking over the shoulder of a C++ coworker yesterday, when he

14 messages 2005/06/16

[#145677] Truth maintenance system in Ruby — "itsme213" <itsme213@...>

Anyone know of any kind of truth-maintenance system implemented in Ruby (or,

12 messages 2005/06/17

[#145720] Frameless RDoc template ('technology preview') — ES <ruby-ml@...>

Hi!

17 messages 2005/06/17

[#145779] Newbe questions... — "Chuck Brotman" <brotman@...>

In Ruby Is there a prefered (or otherwise elegant) way to do an inner &

17 messages 2005/06/18

[#145790] GC.disable not working? — Eric Mahurin <eric_mahurin@...>

From what I can tell, GC.disable doesn't work. I'm wanting to

37 messages 2005/06/18
[#145822] Re: GC.disable not working? — ts <decoux@...> 2005/06/19

>>>>> "E" == Eric Mahurin <eric_mahurin@yahoo.com> writes:

[#146024] evaluation of ruby — "Franz Hartmann" <porschefranz@...> 2005/06/21

Hello all,

[#145830] preventing instantiation — "R. Mark Volkmann" <mark@...>

What is the recommended way in Ruby to prevent other classes from creating

13 messages 2005/06/19
[#145831] Re: preventing instantiation — Gavri Fernandez <gavri.fernandez@...> 2005/06/19

On 6/19/05, R. Mark Volkmann <mark@ociweb.com> wrote:

[#145879] x==1 vs 1==x — Gavin Kistner <gavin@...>

I'm against _premature_ optimization in theory, but believe that a

19 messages 2005/06/20
[#145880] Re: x==1 vs 1==x — ts <decoux@...> 2005/06/20

>>>>> "G" == Gavin Kistner <gavin@refinery.com> writes:

[#145943] Chess Variants (II) (#36) — James Edward Gray II <james@...>

I don't want to spoil all the fun, in case anyone is still attempting

12 messages 2005/06/20

[#146038] 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — Michael Tan <mtan1232000@...>

Just new to Ruby since last week, running my same functional program on the windows XP(Pentium M1.5G), the Ruby version is 10 times slower than the Java version. The program is to find the prime numbers like 2, 3,5, 7, 11, 13... Are there setup issues? or it is normal?

47 messages 2005/06/21
[#146044] Re: 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — "Florian Frank" <flori@...> 2005/06/21

Michael Tan wrote:

[#146047] Re: 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — Jim Freeze <jim@...> 2005/06/21

* Florian Frank <flori@nixe.ping.de> [2005-06-22 05:40:14 +0900]:

[#146050] Re: 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — "Ryan Leavengood" <mrcode@...> 2005/06/21

Jim Freeze said:

[#146132] Re: 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — "Mark Thomas" <mrt@...> 2005/06/22

Florian Frank wrote:

[#146064] rubyscript2exe — Joe Van Dyk <joevandyk@...>

Hi,

14 messages 2005/06/21

[#146169] spidering a website to build a sitemap — Bill Guindon <agorilla@...>

I need to spider a site and build a sitemap for it. I've looked

17 messages 2005/06/22

[#146178] traits-0.4.0 - the coffee release — "Ara.T.Howard" <Ara.T.Howard@...>

15 messages 2005/06/22

[#146328] string to Class object — "R. Mark Volkmann" <mark@...>

How can I create a Class object from a String that contains the name of a class?

15 messages 2005/06/24

[#146380] Application-0.6.0 — Jim Freeze <jim@...>

CommandLine - Application and OptionParser

22 messages 2005/06/24

[#146391] ASP.NET vs Ruby on Rails — Stephen Kellett <snail@...>

HI Folks,

21 messages 2005/06/24
[#146457] Re: ASP.NET vs Ruby on Rails — "Dema" <demetriusnunes@...> 2005/06/25

Hi Stephen,

[#146425] speeding up Process.detach frequency — Joe Van Dyk <joevandyk@...>

Is there any way to speed up Process.detach? The ri documentation for

14 messages 2005/06/25

[#146483] I saw the beauty of Ruby Re: 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — Michael Tan <mtan1232000@...>

22 messages 2005/06/26
[#146504] Re: I saw the beauty of Ruby Re: 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — Brad Wilson <dotnetguy@...> 2005/06/26

For comparison, the port of your code to (less than elegant) C#.

[#146515] Re: I saw the beauty of Ruby Re: 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — Florian Gro<florgro@...> 2005/06/26

Brad Wilson wrote:

[#146485] Re: I saw the beauty of Ruby Re: 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — "Florian Frank" <flori@...> 2005/06/26

Michael Tan wrote:

[#146491] What do you want to see in a Sparklines Library? — Daniel Nugent <nugend@...>

This is sort of an interest gauging/feature request poll.

17 messages 2005/06/26
[#146506] Re: What do you want to see in a Sparklines Library? — Daniel Amelang <daniel.amelang@...> 2005/06/26

See what's already been done before you get too far.

[#146517] Re: What do you want to see in a Sparklines Library? — Daniel Nugent <nugend@...> 2005/06/26

Yup, seen the stuff on RedHanded, I was planning on writing a little

[#146562] RCM - A Ruby Configuration Management System — Michael Neumann <mneumann@...>

Hi all,

22 messages 2005/06/27

[#146630] yield does not take a block — Daniel Brockman <daniel@...>

Under ruby 1.9.0 (2005-06-23) [i386-linux], irb 0.9.5(05/04/13),

48 messages 2005/06/28
[#146666] Re: yield does not take a block — Daniel Brockman <daniel@...> 2005/06/28

Yukihiro Matsumoto <matz@ruby-lang.org> writes:

[#146680] Re: yield does not take a block — Yukihiro Matsumoto <matz@...> 2005/06/28

Hi,

[#146684] Re: yield does not take a block — Eric Mahurin <eric_mahurin@...> 2005/06/28

[#146779] Re: yield does not take a block — "Adam P. Jenkins" <thorin@...> 2005/06/29

Eric Mahurin wrote:

[#146700] Anything in new Eclipse for Rubyists? — "jfry" <jeff.fry@...>

Hey there, I know that a number of folks on the list use Eclipse as

14 messages 2005/06/28

[#146773] Programmers Contest: Fit pictures on a page — hicinbothem@...

GLOSSY: The Summer Programmer Of The Month Contest is underway!

18 messages 2005/06/29

[#146815] shift vs. slice!(0) and others — Eric Mahurin <eric_mahurin@...>

I just did some benchmarking of various ways to insert/delete

12 messages 2005/06/29

Re: Intellisense and the psychology of typing

From: Austin Ziegler <halostatue@...>
Date: 2005-06-01 17:26:39 UTC
List: ruby-talk #144241
On 6/1/05, Caleb Clausen <vikkous@gmail.com> wrote:
> Austin Ziegler wrote:
>> Type hints are primarily a documentation feature. Let me repeat
>> that for emphasis: it is a documentation feature. If an
>> optimizing Ruby compiler is able to take advantage of it --
>> great.
> And I still fail to see the semantic difference between the two.
> [...]

Type hints are just that: hints. They aren't restrictions. Type
declarations are restrictions. They aren't suggestions. They are
mandatory. It's that simple, and they're not -- and never have been
-- two different words for the same thing.

It is a huge semantic difference.

>> If not ... too bad.
> This sort of attitude is unnecessarily harsh. Whether you care or
> not about all the same things someone else might, the fact remains
> that the exact same mechanism that's needed for what you want
> (documentation) can provide the information needed by an
> optimizing compiler.

1. The information may be useful for documentation purposes, but not
   be useful for optimization. This is by design. If I say that my
   return type is aString, that will not help an optimizer.
2. It may be useful for optimization, but will also be useful for
   documentation. This is by design. If I say that my return type is
   String, that will help an optimizer.

Type declarations require #2 only. Type hints permit #1. #1 is the
only thing that Ruby should concern itself with, through one means
or another.

>> DO *NOT* USE POLS in your argument. It doesn't apply. Matz has
>> indicated that it's just so much crap.
> The principle of least surprise is a good principle in language
> design. Unfortunately, everyone is likely to see it subjectively:
> principle of my least surprise. Matz interprets it this way, thus
> for ruby, POLS really means POLMS (principle of least matz
> surprise).

Matz has requested that this term not be used in any case when
discussing Ruby. Therefore, Caleb, don't use it in an argument. I
don't particularly care what people find surprising in Ruby. Every
language will surprise you at some time, and most of the time it
will be pleasant in Ruby.

>> Oh, please *don't* try to lecture me on this stuff, Caleb.
> Well, Austin, I will certainly lecture you if you seem to require
> lecturing. (If that's waht you want to call it.) You made a logical
> error in your argument. You equated static typing and class-based
> typing. They are the same in most languages, but need not (and should
> not, in my opinion) be the same thing in a ruby static type system.

Seeing as Ruby does not have and should not have a static typing
system, I don't see where it would be incorrect. Having been through
this discussion many times, I think that it's quite clear that one
can't really have a meaningful type declaration system that isn't in
some way or another name-based. It might be through identifying
modules (e.g., EnumerableInterface or HashSemantics or
StringSemantics), but there has to be some short-hand way --
otherwise you're making this happen through runtime considerations
only (e.g., #respond_to?), and even that's not perfect because #[]
means something different for different classes, even though it's
similar.

>> 1. It looks like the stuff in other languages, but because Ruby
>> isn't statically typed (thank GHU for that), it won't have the
>> same meaning as it does in those languages.
> There are many dynamic languages with variable type declarations.
> Javascript and scheme leap to mind. There are many things in
> dynamic languages that don't have quite the same semantics as
> their equivalent in a static language, but the same or similar
> syntax nevertheless. Integer addition leaps to mind. Just because
> C also has integer addition, using +, does that mean that ruby
> must use some different syntax when adding integers, since it
> actually handles overflow?

You are incorrect here, at least regarding ECMAscript/Javascript.

  var foo = true

This does not declare foo as a Boolean variable. It sets the foo
variable to the Boolean value of true.

I don't know scheme. So, no, Javascript doesn't have variable type
declarations. It has variable declarations -- that are optional in
any case, IIRC.

>> 2. If it does have the same meaning in those languages, we're no
>>    longer talking about Ruby.
> Every time you change the language, it's no longer the same
> language, but so what?

Untrue. Every time you change the language, you can end up with a
variant of the language. However, type declarations -- especially
restrictive type declarations -- are contra-Ruby in the sense that
they add static, name-based typing to Ruby.

>> 3. It will encourage people to use it for the wrong reasons in
>>    the wrong way.
> I addressed this in my last message. You need to provide further
> evidence rather than just repeat the same thing again.

No, you didn't address it, and it doesn't need further evidence. But
just for you:

* Restrictive typing (especially name-based typing, and there is no
  meaningful type declaration that isn't name based) in Ruby is
  axiomatically wrong. (This is not just my opinion; it is widely
  held. See the recent discussions about homogeneous collections and
  see how most people in the Ruby community have suggested that it
  isn't the right way to think about the problem.)
* If restrictive typing is axiomatically wrong, a language feature
  that makes it possible is wrong.
* If an informational tool is made to look like a restrictive typing
  feature, then it is *also* wrong.

If you're not accepting the first point, then it's quite clear that
you're not going to agree with the follow-on points. But that first
point is the key.

>> 4. It becomes more than informational.
> I fail to understand what you mean by this word. A type
> declaration is informational. It informs a language tool what the
> expected type of a variable is. How is it more than that?

No, a type declaration is much more than informational. It is
declarative (rather obvious) and states a fact (see the definition
of declarative). Something that is informational is "A collection of
facts from which conclusions may be drawn."

The declaration is more restrictive than the hint.

>> The method signature is not related to the "duck type." If you've
>> used Ruby for any length of time, you recognise that as well. I'm
>> not Matz -- or even Dave Thomas -- but duck typing is,
>> ultimately, not *caring* about the type of object you're
>> provided. It's just using the type of object.
> I know what you say is gospel, but I think it's a bit of a
> simplification. Consider something like this:
> 
>   def process_it(file)
>     ...
>     file.read
>     ...
>     file.write
>   end

> I've given the parameter a name that makes it seem that only a
> File is possible, but we like to be able to pass other things, so
> long as they adhere to process_it's view of file's method
> signature. (In this case, read and write.) This is what is usually
> referred to as duck typing. You can't really pass any kind of
> object to process_it. You can't give it an Integer, or (sans some
> kind of help) a String. The set of types that can usefully be
> assigned to file are in practice quite limited.

But they are not able to be encapsulated simply or even declared.

> And it's relatively rare that you actually want file to be able to
> be any object. There are cases, but it seems more common that the
> set of types is limited. If it really is any object, you have to
> limit yourself to methods of Object inside process_it.

> We could have type declarations like this:
>   def process_it(file : IO|StringIO)
>     #declare file to be one of 2 types
>   end

Which immediately restricts the object to those types -- and ignores
mock objects. Allowing this form would be wrong for the reasons
documented above.

> or this:
>   def process_it(file : :read&:write)
>     ...
>   end
> The second form is what you'd want to use, mostly. It would
> declare that process_it takes a parameter that can read and write.
> No classes are mentioned in the declaration. Incidently, this
> part: :read&:write is exactly what java calls an interface. Notice
> how much smaller and cleaner it can be in ruby.

Disagree that I'd want to use that. First, it would mean that I
would need to document every method that I -- or a child class --
uses, otherwise someone might send me a file-like-object that can
#read and #write, but if I later add #seek to the method without
updating the requirements ... well, we're no better off than we are
now.

This is what I mean about the declaration being restrictive. You
have given me the false sense of security that all I need to provide
to #process_it is an object that is #read and #write capable. The
language might actually start placing those restrictions in place.
It's too damn bad if I've misrepresented this, or can't meaningfully
tell you what my child methods require. Whereas an rdoc hint can
tell you a lot more by suggesting what the input might be -- but
doesn't have to be.

Further, I don't see such #respond_to? declarations as being
remotely useful to an optimizing compiler. I could be wrong here,
but I just don't see it.

[...]

>> No, we can't. Interface declarations are simply wasted code time
>> and space. It's that simple.
> I'm sorry you feel that way, but I'm afraid you haven't convinced
> me. (Hint: a bald statement of fact, with no support, isn't
> sufficient.)

In Ruby, it's a waste of code time and space BECAUSE it provides
false and incomplete guarantees for no tangible benefit.

[...]
> Ruby is nice in that you don't have to lay out this protocol ahead
> of time, like in java. But sometimes you want to or need to
> anyway.

If you want to lay out the protocol, I see it as a solely
documentation issue, not a compiler issue.

>> Not at all. Self is an indication that my suggestion will work:
> I know next to nothing about self, so I'm speculating here. What
> you describe sounds like a slightly different kind of type
> inferencing -- profiler-driven inductive inferencing rather than
> static deductive inferencing. I can see that this could be a big
> performance gain.

That is what I described the first time around. I *did* emphasize
that it has to do more with long-running programs and a cache of
compiled code.

> But it only tells you which types a variable is likely to have,
> and does not reduce the total number of types that are possible. I
> think that the run-time consequence is likely to be more type
> checking than is necessary in a statically typed program.

Certainly there will be more -- but there are more already. But
there aren't as many Stupid Tricks then necessary (by the
programmers) as there are in statically typed languages to get
around the silly restrictions of static typing languages.

> Note that static typing can help optimize this type of profiler-
> driven optimization just a little bit more, by eliminating some of
> those checks. The difference in performance may not be that great,
> tho.

I don't think so. Consider a method #foo(bar). If bar is an Integer,
then the optimizer will compile #foo to operate optimally on Integer
values. When #foo is called with a String, then there will be a
cache miss and the compiler will recompile the method for String
values. When #foo is called with an Array, there will be a cache
miss, too.

There are further optimisations the compiler could theoretically
look for:

  def foo(bar)
    bar = bar.to_s
    :
  end

If it sees that bar is never used as anything but a string, then it
could compile the String version and then simply intercept non-
String calls with a call to the String version after an explicit
#to_s call.

> As far as the fancy IDEs, I'd personally be a bit more interested
> in knowing the total possible set of types, rather than the set of
> likely types. This is especially true of my favorite IDE feature:
> I like to be able to point to an identifier in my code and find
> its definition(s) or the other references to it.

I'll be honest; I haven't needed this for the most part in my Ruby
code. Part of this is because Ruby doesn't allow overloading (only
overriding). It's very useful in C++ and Java, but I haven't really
needed it in Ruby.

>> Static typing doesn't increase safety, ability to be analysed, or
>> anything else -- that doesn't help the compiler of said
>> statically typed language. There are side benefits from IDEs that
>> have been
> As a prospective writer of tools that need to analyse ruby, I can
> tell you that prospects look a lot brighter with a bit of static
> type information to help out. If you really think it's so easy,
> then tell me how you would do it. Really, I would love to read a
> monograph on how you do, say, find references/find definition in
> ruby, without any help or hints or declarations of variable types.
> Remember, you have to handle method_missing, too. A given
> definition of method_missing has to be found as a definition if it
> can be called from that particular point in the program, but not
> if it can't be called.

Actually, the IDE/tool stuff can be handled by discounting
#method_missing. It's a blip, in my experience. Not nonzero, of
course, but a blip nonetheless. I've only played a little with the
JEdit plugin, but it seems to be reasonably successful.

Generally, if someone is using an object that defines a nonstandard
#method_missing, well, you have a problem.

>> at what point in a class definition can you conclusively say that
>> it is -- or is not -- an Enumerable?
> Here you get at the big problem with variable type declaration in
> ruby. If types are defined in terms of on object's capabilites,
> then an object's type can change at runtime, as methods are added
> or removed in the object's class.

Precisely the big problem. I have some adaptive code that modifies
an object in realtime; if it doesn't find a method it wants on an
object, it adds it. Now, it adds it assuming that the object
received is a String-like object, but it adds it nontheless. (Well,
to be more accurate, it does it as an ordered sequence where
#[offset, length] will work.)

[...]

> Now, your example contains a bit of a twist that I haven't seen
> before. To be pedantic (as a program would have to be), I would
> say that the variable a is an Enumerable at both calls to inject.
> (After all, a.kind_of?Enumerable will return true.) Granted, at
> the first inject, it is not a useful Enumerable. We could call it
> an abstract Enumerable at that point.

And that, of course, is the problem. I have seen people want to
define an EnumerableInterface that you *also* have to include to
make a complete enumerable. This would define #each ... to throw an
exception if not overridden.

*sigh*

-austin
-- 
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca


In This Thread