"Duck typing" etymology? [closed] - duck-typing

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
Is there a story behind the name ''duck typing'', I've heard ''if it looks like a duck, and sounds like a duck, let's call it a duck'' (or something like that), but why a duck? Why not ``if it looks like a _ and sounds like a _, let's call it a _''.
It sounds like a Flying Circus sketch, but I don't remember it. Is there a story behind the name?

Duck typing is a phrase borrowed from the much older "walk like a duck". The latter has been around far longer than the programming idea it describes. See answerbag.com

http://groups.google.com/group/comp.lang.python/msg/e230ca916be58835?hl=en&
Alex is involved... ;)

This is not really a programming question, but my guess: Ducks walk funny and they quack. This is amusing enough to turn it into a figure of speech. :-)

Quoting Wikipedia's article on Duck Typing:
The name of the concept refers to the duck test, attributed to James
Whitcomb Riley, which may be phrased as follows: "When I see a
bird that walks like a duck and swims like a duck and quacks like a
duck, I call that bird a duck."
...and from the same page...
Alex Martelli made an early (2000) use of the term in a message
to the comp.lang.python newsgroup. He also highlighted
misunderstanding of the literal duck test, which may indicate that the
term was already in use:
"In other words, don't check whether it IS-a duck: check whether it
QUACKS-like-a duck, WALKS-like-a duck, etc, etc, depending on exactly
what subset of duck-like behaviour you need to play your
language-games with."

No, the analogy is that if a variable looks like an integer (for example), and acts as an integer, it must be an integer (type).
Duck typing means 'no explicit predeclaraction of type'.

Related

Is there another way to write tables in Inform 7?

Inform 7 tables are written using "tab separated values". Whenever a table contains text, it ends up looking like this:
Table of Aristotelian Questions
name difficulty text explanation follow-up
the opposite question easy "WHAT IS THE OPPOSITE OF [the subject]?[line break]" "SOMETIMES A GOOD WAY TO DESCRIBE SOMETHING IS BY TELLING[line break]WHAT IT IS NOT. THERE MAY OR MAY NOT BE A DIRECT[line break]OPPOSITE OF [the subject], BUT[line break]SEE IF YOU CAN THINK OF ONE.[line break][line break]FOR EXAMPLE, IF I WERE WRITING A PAPER ON SOLAR[line break]ENERGY, AN ANSWER TO THIS QUESTION MIGHT PRODUCE A[line break]LIST OF EARTH'S NATURAL ENERGY RESOURCES.[line break]" prompt A
the good consequences question easy "WHAT ARE THE GOOD CONSEQUENCES OF[line break][the subject]?[line break]" "WHAT GOOD WILL COME ABOUT FROM MANKIND'S CONCERN ABOUT[line break][the subject]?[line break][line break]FOR EXAMPLE, IF I WERE WRITING A PAPER ABOUT COLLEGE[line break]ACADEMICS, SOME OF THE GOOD CONSEQUENCES MAY BE A BETTER[line break]JOB IN THE FUTURE, A FULLER UNDERSTANDING[line break]ABOUT OUR WORLD, AND AN APPRECIATION FOR GOOD STUDY HABITS.[line break](STOP THE SNICKERING AND GET ON WITH AN ANSWER.)[line break]" prompt C
Is there another way to write the same table? (I'm imagining something sort of YAML-like.)
No, that's the only way to make a table in I7. But you can extract all of the text as constants:
Table of Aristotelian Questions
name difficulty text explanation follow-up
the opposite question easy Opposite question Opposite follow up prompt A
the good consequences question easy Good question Good follow up prompt C
Opposite question is always "WHAT IS THE OPPOSITE OF [the subject]?[line break]".
Opposite follow up is always "SOMETIMES A GOOD WAY TO DESCRIBE SOMETHING IS BY TELLING[line break]WHAT IT IS NOT. THERE MAY OR MAY NOT BE A DIRECT[line break]OPPOSITE OF [the subject], BUT[line break]SEE IF YOU CAN THINK OF ONE.[line break][line break]FOR EXAMPLE, IF I WERE WRITING A PAPER ON SOLAR[line break]ENERGY, AN ANSWER TO THIS QUESTION MIGHT PRODUCE A[line break]LIST OF EARTH'S NATURAL ENERGY RESOURCES.[line break]".
Good question is always "WHAT ARE THE GOOD CONSEQUENCES OF[line break][the subject]?[line break]".
Good follow up is always "WHAT GOOD WILL COME ABOUT FROM MANKIND'S CONCERN ABOUT[line break][the subject]?[line break][line break]FOR EXAMPLE, IF I WERE WRITING A PAPER ABOUT COLLEGE[line break]ACADEMICS, SOME OF THE GOOD CONSEQUENCES MAY BE A BETTER[line break]JOB IN THE FUTURE, A FULLER UNDERSTANDING[line break]ABOUT OUR WORLD, AND AN APPRECIATION FOR GOOD STUDY HABITS.[line break](STOP THE SNICKERING AND GET ON WITH AN ANSWER.)[line break]".

Code to calculate a certain arithmetic expression in assemlby [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Expression: z=a+b * b-(36/(b * b)/(1+(25/(b * b)))
I have no idea what data directives I should use and in what order I should write the code.
C = A + B for Z80 CPU:
ld a,A
ld b,B
add a,b ; a = C
C = A * B for 68000 CPU:
MOVE.W D0,A
MOVE.W D1,B
MULS.W D1,D0 ; D0 = C
et cetera ... check your target CPU instruction guide to see what arithmetic operations it does implement directly, and what operand types can be used for them, which registers you have available, and their data type...
Looks like you don't have to write universal math expression parser (this gets tricky quite quickly, once at high-school we had on programming competition the task to write exactly that, and at first we were like "what, a single task for 5h time, I will be done in 30min" ... then after 5h nobody's code passed the full test suite, best were around 80% correct).
So if only this particular expression should be calculated, you can "parse" it by hand, simplifying it down into particular steps involving only single operation and one of intermediate sub-results. Then just write that with your instructions, step by step, like you would calculate that by hand (also make sure you conform to the math expression calculation rules, you know which operations have priority over others? Parentheses override anything, then mul/div first, add/sub later, from left to right, but this is base school math stuff, so unless you are 10y.o., you shouldn't ask this).
If your CPU does not have instruction for division or multiplication, simply implement it by subtraction/addition in loop. It's very lame performance wise, but if you have to ask this question, then one can not expect you would even comprehend more advanced algorithm for these.

Strange code Amiga "++[>++++++<-]>.>+"

Does anybody recognize this?
+++++++++++<-]>.>+++++++++[>++++++++++++++
.-------------------------.+++++++++++++
I read, that it has something in common with Amiga.
How can I decode it?
That looks like Brainf*** to me
http://en.wikipedia.org/wiki/BrainF
Probably could look for a compiler and see what happens.
It is a "BrainF*ck" programming language. an esoteric programming language noted for its extreme minimalism. It is a Turing tarpit, designed to challenge and amuse programmers, and was not made to be suitable for practical use.1 It was created in 1993 by Urban Müller.

Mac hash function broken

I'm more or less attempting to determine crypography algoirthms and how they work. I'm a little confused on proving how one is trivial.
For example:
MAC(xbit_key,Message) = xbit_hash(Message) XOR xbit_key
Take a look at this for a general explanation and that for a good example. If it's still not clear, come back with a more specific question.

Hexgit number? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 14 years ago.
Improve this question
if digit is the name for a number on base 10, what would be the name for a number on base 16? Hexgit?
It's a "nibble" (i.e., half a byte).
http://en.wikipedia.org/wiki/Nibble
Digit. Simply a hexadecimal one.
Are you looking for an analogue to bit for binary digit? Hexgit wouldn't be my choice; it doesn't really roll off the tongue. As for the unit of storage, a hex digit represents a nibble's worth (or nybble).
define: digit
One of the elements that collectively form a system of numeration.
The word 'digit' can be used in any number system. The only exceptions are 'bit' which is really just short for 'binary digit' and 'trit' which is short for 'ternary digit'. (You can still call bits and trits 'digits', however.)
Still "digit", as long as you have 16 fingers ;-)
"Hexdigit" and "hex digit" are both in wide use in textbooks.
There isn't really a consensus, I don't think, but see Units of information for some options.
Personally, I'd just say "hex digit".
"Hexgit" would be a bad choice since "hex" formally suggests base six rather than 16.
"Hexdecit" would retain the 6+10 representation, but I would stick with "digit".

Resources