What sound does no duck make?

J

John Carter

Imagine a flock of ducks in the sky. Listen.
Now remove the ducks. Listen.

What is the sound of no duck quacking?

What should nil respond_to?



John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : (e-mail address removed)
New Zealand


Surprisingly enough, this email does not originate from a beetle.
 
L

Lyle Johnson

What is the sound of no duck quacking?

For that matter, if a duck quacks in the forest, and no one is there
to hear it, does it really make a sound?
What should nil respond_to?

I can't tell (based on the setup) if this is a serious question or
not. ;) But if it is a serious question, "nil" at least responds to
the instance methods defined for any Object, since "nil" is an
instance (*the* instance) of NilClass, and NilClass is derived from
Object.
 
L

Lionel Thiry

John Carter a écrit :
Imagine a flock of ducks in the sky. Listen.
Now remove the ducks. Listen.

What is the sound of no duck quacking?

What should nil respond_to?



John Carter

class Duck
def initialize(name)
@name = name
end
def quack
puts "#{@name} quacks!"
end
end

# imagine a flock of duck in the sky
duck_flock = [Duck.new("redhead"), Duck.new("mallard"), Duck.new("some duck")]

# listen
duck_flock.each do |duck|
duck.quack
end

# now remove the ducks
duck_flock.clear

# listen
duck_flock.each do |duck|
duck.quack
end

# what should nil respond to?
if duck_flock.empty?
puts "there are no nil's, what are you talking about?"
end

PS: you have read Head First Design Pattern didn't you? Good book, isn't it? But
it seems you missed page 598.
 
C

Cyent

For that matter, if a duck quacks in the forest, and no one is there
to hear it, does it really make a sound?


I can't tell (based on the setup) if this is a serious question or
not. ;) But if it is a serious question, "nil" at least responds to
the instance methods defined for any Object, since "nil" is an
instance (*the* instance) of NilClass, and NilClass is derived from
Object.

I was in the wilderness and there was nothing before me.

I told nothing to build me a castle.

Nothing happened.

When it had finished happening, there was still nothing there.

Now imagine, in another world, another universe....

I was in the wilderness and there was nothing before me.

I told nothing to build me a castle.

The world exploded with a NoMethodError and all died.

--
John Carter

The Cybernetic Entomologist - (e-mail address removed)

http://geocities.yahoo.com/cy_ent

I'm becoming less and less convinced of humans as rational beings.
I suspect we are merely meme collectors, and the reason meme is only
kept on to help count our change.
 
A

Ara.T.Howard

I was in the wilderness and there was nothing before me.

then something is wrong with my eye-glasses or my definition of wilderness
needs to be checked...
I told nothing to build me a castle.

then something is wrong with my mind and __i__ need to be checked
Nothing happened.

except cpu cycles
When it had finished happening, there was still nothing there.

which is clearly not what i expected

Now imagine, in another world, another universe....

I was in the wilderness and there was nothing before me.

I told nothing to build me a castle.

The world exploded with a NoMethodError and all died.

i noticed that telling nothing to build a castle was a logic error (the
__most__ difficult kind of error to debug) fixed it - and re-started a correct
program.

my 2 cts.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| renunciation is not getting rid of the things of this world, but accepting
| that they pass away. --aitken roshi
===============================================================================
 
R

Ryan Leavengood

John said:
Imagine a flock of ducks in the sky. Listen.
Now remove the ducks. Listen.

What is the sound of no duck quacking?

What should nil respond_to?

Imagine a large steel box with a small hole, through which you can push
a stick. Inside the box there is supposed to be a duck. This duck is
your dinner, and you are very, very hungry. But before you can open the
box to retrieve the duck for dinner, you have to use the stick and hole
to prove that there is a duck inside (by poking in...poor Mr. Duck.) If
poked the duck will quack rather loudly. But since this is a big box,
the duck can hide sometimes, so it won't always quack when you push in
the stick. Also the proof of duck existence is needed because opening an
empty box will release a deadly gas (it is a dangerous world.)

In addition, this is a smart box, and on the back, where you cannot see
or access it (the box is against a wall), there is a switch which turns
on "smart mode." In smart mode, an empty box will complain when you push
the stick in the hole. Unfortunately some clever guy thought this was
dumb, and he turned off smart mode ("eh, it is a waste of electricity"
was his logic.)

So you spend hours, poking and poking and poking, never really sure if
there is a duck inside, because the box just never told you it was
empty. Eventually you die of starvation, all because that clever guy
turned off that switch.

Ryan
 
J

James Britt

R

Ryan Leavengood

James said:
So is this, like, Schrödinger's Duck?

Hehehe, that thought did cross my mind as I wrote it. But alas my simple
Ruby NoMethodError metaphor isn't on the same plane as Quantum Physics
metaphors.

Ryan
 
L

Lionel Thiry

Ryan Leavengood a écrit :
Hehehe, that thought did cross my mind as I wrote it. But alas my simple
Ruby NoMethodError metaphor isn't on the same plane as Quantum Physics
metaphors.

Ryan

But it gives same headaches!
 
K

Kero

Imagine a flock of ducks in the sky. Listen.
Now remove the ducks. Listen.

What is the sound of no duck quacking?

What should nil respond_to?

nil.nil? => true
Object.new.nil? => false

and if your duck can not be false itself, code like this works:

if duck = flock.front_duck
duck.relocate_towards_end_of(flock) if duck.tired?
end

+--- Kero ----------------------- kero@chello@nl ---+
| all the meaningless and empty words I spoke |
| Promises -- The Cranberries |
+--- M38c --- http://httpd.chello.nl/k.vangelder ---+
 
J

John Carter

Having asked the question, and heard many replies let me summarise...

Imagine a flock of ducks in the sky. Listen.
Now remove the ducks. Listen.

What is the sound of no duck quacking?

What should nil respond_to?

Well, it turned out that there are several sorts of unduck making several
different unsounds.

There is the uninitialized unduck, which, when you ask it to quack
says, "You Nana! It was _your_ job to put a duck here and you DID NOT,
and now you asking it to Quack! Twit!"

Then there is the not applicable duck, which when you ask it to quack
says, "Sorry, it is just not appropriate nor ever will be appropriate
to have a duck in _this_ particular instance. Don't even try put a duck
in here, let alone ask it to quack."

Then there is the no duck, which when asked to quack (or anything else
for that matter) does nothing, and after having done nothing, leaves
you with nothing. Which was the only sort of nil I had in my rather
limited mind when I asked the question.



John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : (e-mail address removed)
New Zealand

We all live but seconds away from pain and death, yet we live as
though it wasn't even possible.

We are but one person amongst 6 billion, yet we live as though we,
personally, matter.

So, as you were saying... how real did you want me to get?
 
E

ES

Le 19/5/2005 said:
Having asked the question, and heard many replies let me summarise...



Well, it turned out that there are several sorts of unduck making several
different unsounds.

There is the uninitialized unduck, which, when you ask it to quack
says, "You Nana! It was _your_ job to put a duck here and you DID NOT,
and now you asking it to Quack! Twit!"

Then there is the not applicable duck, which when you ask it to quack
says, "Sorry, it is just not appropriate nor ever will be appropriate
to have a duck in _this_ particular instance. Don't even try put a duck
in here, let alone ask it to quack."

Then there is the no duck, which when asked to quack (or anything else
for that matter) does nothing, and after having done nothing, leaves
you with nothing. Which was the only sort of nil I had in my rather
limited mind when I asked the question.
Goose!

John Carter=20

E
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top