[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

open classes and language extensibility

Martin DeMello

2/27/2008 6:04:00 AM

I was pondering the whole "monkeypatching" debate, and I realised that
disallowing modification of core classes removes an extremely
important property of the language - the ability to have extension
code you write be "on par" with the base language. This is often
touted as one of the big advantages of lisp and forth, and it would be
a shame to lose it in ruby. For instance, lets say your code relied
heavily on rot13. If you couldn't add a #rot13 method to String
because String was a core class, you'd be forced to say rot13(string),
or even worse, Util.rot13(string). You'd end up with expressions like
rot13(string.capitalize.squeeze), where it is very clear which methods
come from "base ruby" and which are yours.

http://debasishg.blogspot.com/2007_01_01_ar... is a good read
on the subject:
---------------------------------------------------------------
With a Lisp implementation, we can have a natural extension of the
language through a macro

dolist (x '(1 2 3)) (print x) (if (evenp x) (return)))

and the moment we define the macro, it blends into the language syntax
like a charm. This is abstraction through syntax construction.

And, the Java counterpart will be something like :

// ..
Collection<..> list = ... ;
CollectionUtils.dolist(list,
new Predicate() {
public boolean evaluate() {
// ..
}
});
// ..

which provides an object oriented abstraction of the same
functionality. This solution provides the necessary abstraction, but
is definitely not as seamless an extension of the language as its Lisp
counterpart.
---------------------------------------------------------------

martin

12 Answers

Joel VanderWerf

2/27/2008 7:46:00 AM

0

Martin DeMello wrote:
> I was pondering the whole "monkeypatching" debate, and I realised that
> disallowing modification of core classes removes an extremely
> important property of the language - the ability to have extension
> code you write be "on par" with the base language. This is often
> touted as one of the big advantages of lisp and forth, and it would be
> a shame to lose it in ruby. For instance, lets say your code relied
> heavily on rot13. If you couldn't add a #rot13 method to String
> because String was a core class, you'd be forced to say rot13(string),
> or even worse, Util.rot13(string). You'd end up with expressions like
> rot13(string.capitalize.squeeze), where it is very clear which methods
> come from "base ruby" and which are yours.

Fully agree. Also, a method like Util.rot13(string) is defined in a
pretty bland namespace, so it is really almost as "global" as
String#rot13. How qualified would it have to be to be safe?

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Jari Williamsson

2/27/2008 8:00:00 AM

0

Martin DeMello wrote:
> I was pondering the whole "monkeypatching" debate, and I realised that
> disallowing modification of core classes removes an extremely
> important property of the language - the ability to have extension
> code you write be "on par" with the base language. This is often
> touted as one of the big advantages of lisp and forth, and it would be
> a shame to lose it in ruby. For instance, lets say your code relied
> heavily on rot13. If you couldn't add a #rot13 method to String
> because String was a core class, you'd be forced to say rot13(string),
> or even worse, Util.rot13(string). You'd end up with expressions like
> rot13(string.capitalize.squeeze), where it is very clear which methods
> come from "base ruby" and which are yours.

I think this statement is incorrect. You CAN create a string with a
#rot13 method, without adding that method to the core class.


Best regards,

Jari Williamsson

Martin DeMello

2/27/2008 8:22:00 AM

0

On Tue, Feb 26, 2008 at 11:59 PM, Jari Williamsson
<jari.williamsson@mailbox.swipnet.se> wrote:

> I think this statement is incorrect. You CAN create a string with a
> #rot13 method, without adding that method to the core class.

Well, you can add it individually to any given string, but I fail to
see how this affects my argument.

martin

J. Cooper

2/27/2008 8:36:00 AM

0

Martin DeMello wrote:

> because String was a core class, you'd be forced to say rot13(string),

> martin

Welcome to PHP :)
--
Posted via http://www.ruby-....

David E. Powell

1/7/2013 1:39:00 AM

0

On Jan 5, 3:51 pm, Transition Zone <mogu...@hotmail.com> wrote:
> On Jan 3, 6:18 pm, Ignoramus9117 <ignoramus9...@NOSPAM.9117.invalid>
> wrote:
>
> > On 2013-01-03, Joe AutoDrill <autodr...@yunx.com> wrote:
>
> > > Guns and their projectiles are closely matched items.
>
> > > What if the bullet is in the pocket of the shooter and is thus warm and
> > > the gun is outside and at a fairly cold temperature of zero Fahrenheit.
>
> > > ...Do the tolerances get too close and the potential for a jammed
> > > projectile increase significantly?
>
> > > Where do the temperature differences start to matter presuming a slug or
> > > solid projectile is used?
>
> >  Sounds like a great time for an experiment, let us know.
>
> Its more of a physics question. Even so, I'd think that way, way back
> in the 1300's when Edward III started using guns against Scotland,
> they would have found some type of way to account for those
> differences, right?  Certainly, afterwards.
> (so I think your experiment is 700 years late)

With old smoothbore muskets, there was a little "rattle room" I would
guess. Hence the wadding between the powder and the ball. Did the
musketeers ever patch their bullets like some riflemen did later on?

Keith W

1/7/2013 9:35:00 AM

0

Transition Zone wrote:
> On Jan 3, 6:18 pm, Ignoramus9117 <ignoramus9...@NOSPAM.9117.invalid>
> wrote:
>> On 2013-01-03, Joe AutoDrill <autodr...@yunx.com> wrote:
>>
>>> Guns and their projectiles are closely matched items.
>>
>>> What if the bullet is in the pocket of the shooter and is thus warm
>>> and the gun is outside and at a fairly cold temperature of zero
>>> Fahrenheit.
>>
>>> ...Do the tolerances get too close and the potential for a jammed
>>> projectile increase significantly?
>>
>>> Where do the temperature differences start to matter presuming a
>>> slug or solid projectile is used?
>>
>> Sounds like a great time for an experiment, let us know.
>
> Its more of a physics question.

Simple engineering as it happens. Rifled guns either use
a slug of softer metal than the barrel or have a jacket or
driving band of softer metal such as copper that engages
with the rifling. That way the tolerances are less important

> Even so, I'd think that way, way back
> in the 1300's when Edward III started using guns against Scotland,
> they would have found some type of way to account for those
> differences, right? Certainly, afterwards.
> (so I think your experiment is 700 years late)

Early guns used projectiles that were at best an approximate
fit. Many used stone cannon balls or even just bags of junk
such as old nails, bits of scrap etc that were given the fancy name
langrage shot. Basically if you could fit it down the muzzle
you could fire it.

Keith


Keith W

1/7/2013 9:48:00 AM

0

David E. Powell wrote:
> On Jan 5, 3:51 pm, Transition Zone <mogu...@hotmail.com> wrote:
>> On Jan 3, 6:18 pm, Ignoramus9117 <ignoramus9...@NOSPAM.9117.invalid>
>> wrote:
>>
>>> On 2013-01-03, Joe AutoDrill <autodr...@yunx.com> wrote:
>>
>>>> Guns and their projectiles are closely matched items.
>>
>>>> What if the bullet is in the pocket of the shooter and is thus
>>>> warm and the gun is outside and at a fairly cold temperature of
>>>> zero Fahrenheit.
>>
>>>> ...Do the tolerances get too close and the potential for a jammed
>>>> projectile increase significantly?
>>
>>>> Where do the temperature differences start to matter presuming a
>>>> slug or solid projectile is used?
>>
>>> Sounds like a great time for an experiment, let us know.
>>
>> Its more of a physics question. Even so, I'd think that way, way back
>> in the 1300's when Edward III started using guns against Scotland,
>> they would have found some type of way to account for those
>> differences, right? Certainly, afterwards.
>> (so I think your experiment is 700 years late)
>
> With old smoothbore muskets, there was a little "rattle room" I would
> guess. Hence the wadding between the powder and the ball. Did the
> musketeers ever patch their bullets like some riflemen did later on?

The wadding was usually rammed home AFTER the ball simply
to stop the ball rolling out of the barrel. The introduction of
paper cartridges meant that loading involved

tearing open the cartridge with your teeth,
priming the pan,
pouring the rest of the powder down the bore
ram home the ball and paper (which acts as wadding)

Patching really only had a value with rifled guns. In real combat
use the major problem that riflemen and musketeers had was that
the barrel became fouled with black powder residue and until
cleaned it became impossible to ram home the powder and ball.

In the Napoleonic era armies used skirmishers armed with
rifles to pick off officers and NCO's at range but the mass
engagements involved musket fire where firing five rounds a
minute at a wall of men 50 yards away was more important
than accuracy.

Keith


Gunner Asch

1/7/2013 10:28:00 AM

0

On Mon, 7 Jan 2013 09:34:45 -0000, "Keith W"
<keithnospoofsplease@demon.co.uk> wrote:

>Transition Zone wrote:
>> On Jan 3, 6:18 pm, Ignoramus9117 <ignoramus9...@NOSPAM.9117.invalid>
>> wrote:
>>> On 2013-01-03, Joe AutoDrill <autodr...@yunx.com> wrote:
>>>
>>>> Guns and their projectiles are closely matched items.
>>>
>>>> What if the bullet is in the pocket of the shooter and is thus warm
>>>> and the gun is outside and at a fairly cold temperature of zero
>>>> Fahrenheit.
>>>
>>>> ...Do the tolerances get too close and the potential for a jammed
>>>> projectile increase significantly?
>>>
>>>> Where do the temperature differences start to matter presuming a
>>>> slug or solid projectile is used?
>>>
>>> Sounds like a great time for an experiment, let us know.
>>
>> Its more of a physics question.
>
>Simple engineering as it happens. Rifled guns either use
>a slug of softer metal than the barrel or have a jacket or
>driving band of softer metal such as copper that engages
>with the rifling. That way the tolerances are less important
>
>> Even so, I'd think that way, way back
>> in the 1300's when Edward III started using guns against Scotland,
>> they would have found some type of way to account for those
>> differences, right? Certainly, afterwards.
>> (so I think your experiment is 700 years late)
>
>Early guns used projectiles that were at best an approximate
>fit. Many used stone cannon balls or even just bags of junk
>such as old nails, bits of scrap etc that were given the fancy name
>langrage shot. Basically if you could fit it down the muzzle
>you could fire it.
>
>Keith
>

Ayup. And of course they were all smoothbore, so one simply put
enough padding, straw or even dirt on top of the powder, then dumped
in the projectile(s)

Think of them as large shotguns. A shotgun can and occasionally DOES
fire a slug.

Gunner

The methodology of the left has always been:

1. Lie
2. Repeat the lie as many times as possible
3. Have as many people repeat the lie as often as possible
4. Eventually, the uninformed believe the lie
5. The lie will then be made into some form oflaw
6. Then everyone must conform to the lie

peter skelton

1/7/2013 12:52:00 PM

0

"Keith W" wrote in message
news:uRwGs.446971$kX.127353@fx18.am4...

David E. Powell wrote:
> On Jan 5, 3:51 pm, Transition Zone <mogu...@hotmail.com>
> wrote:
>> On Jan 3, 6:18 pm, Ignoramus9117
>> <ignoramus9...@NOSPAM.9117.invalid>
>> wrote:
>>
>>> On 2013-01-03, Joe AutoDrill <autodr...@yunx.com> wrote:
>>
>>>> Guns and their projectiles are closely matched items.
>>
>>>> What if the bullet is in the pocket of the shooter and
>>>> is thus
>>>> warm and the gun is outside and at a fairly cold
>>>> temperature of
>>>> zero Fahrenheit.
>>
>>>> ...Do the tolerances get too close and the potential
>>>> for a jammed
>>>> projectile increase significantly?
>>
>>>> Where do the temperature differences start to matter
>>>> presuming a
>>>> slug or solid projectile is used?
>>
>>> Sounds like a great time for an experiment, let us know.
>>
>> Its more of a physics question. Even so, I'd think that
>> way, way back
>> in the 1300's when Edward III started using guns against
>> Scotland,
>> they would have found some type of way to account for
>> those
>> differences, right? Certainly, afterwards.
>> (so I think your experiment is 700 years late)
>
> With old smoothbore muskets, there was a little "rattle
> room" I would
> guess. Hence the wadding between the powder and the ball.
> Did the
> musketeers ever patch their bullets like some riflemen did
> later on?

>The wadding was usually rammed home AFTER the ball simply
to stop the ball rolling out of the barrel. The introduction
of
paper cartridges meant that loading involved

>tearing open the cartridge with your teeth. . .

Hence the requirement that French soldiers have at least one
upper and one lower tooth (I am not making this up).



pyotr filipivich

1/8/2013 7:26:00 AM

0

Gunner <gunnerasch@gmail.com> on Mon, 07 Jan 2013 02:28:09 -0800 typed
in rec.crafts.metalworking the following:
>On Mon, 7 Jan 2013 09:34:45 -0000, "Keith W" wrote:
>>Transition Zone wrote:

snip

>>> Even so, I'd think that way, way back
>>> in the 1300's when Edward III started using guns against Scotland,
>>> they would have found some type of way to account for those
>>> differences, right? Certainly, afterwards.
>>> (so I think your experiment is 700 years late)
>>
>>Early guns used projectiles that were at best an approximate
>>fit. Many used stone cannon balls or even just bags of junk
>>such as old nails, bits of scrap etc that were given the fancy name
>>langrage shot. Basically if you could fit it down the muzzle
>>you could fire it.
>
>Ayup. And of course they were all smoothbore, so one simply put
>enough padding, straw or even dirt on top of the powder, then dumped
>in the projectile(s)
>
>Think of them as large shotguns. A shotgun can and occasionally DOES
>fire a slug.

"Best Dollar eighty I ever spent." Billy the Kid (iirc) after
using a deputy's own double barrel shotgun, which had been loaded with
dimes, to shoot his way out.

And there was a Great White Hunter, who stunned a Cape Buffalo
with the contents of the change purse (shillings, mostly). Stunned
it, but long enough for him and the rest of the beaters, etc, to get
up the tree. Where they waited a very long time.

tschus
pyotr

--
pyotr filipivich
Question for the gun Control advocates, "Do you agree with
this statement?"
"I would rather have a society without guns, even if it
means that people cannot defend themselves against murder
(with other weapons), rape, robbery, and assault. I would
rather make everyone defenseless than have to endure the
mass shootings that occasionally occur. If that means that
many more people, (particularly the old, the weak, and the
infirm) are subjected to these violent crimes, then so be
it. They'll just have to suffer more. I do claim the power
to dictate whether or not others are able to defend themselves."