Talk:Python (programming language)/Archive 8: Difference between revisions

Content deleted Content added
m Archiving 2 discussion(s) from Talk:Python (programming language)) (bot
m Archiving 2 discussion(s) from Talk:Python (programming language)) (bot
Line 369:
[[User:Wes.turner|Wes Turner]] ([[User talk:Wes.turner|talk]]) 21:19, 4 November 2014 (UTC)
: Wouldn't they be more convincing if they contained the word "Python"? [[User:Andy Dingley|Andy Dingley]] ([[User talk:Andy Dingley|talk]]) 21:44, 4 November 2014 (UTC)
 
== Influenced by Java? ==
 
The article lists Java as an influence and the citation just mentions decorators as being influenced by Java. That seems like a pretty small influence. Seems like there either needs to be a better citation or maybe Java (which evidently didn't appear until 4 years after Python) shouldn't be on the lengthy list of influences. [[Special:Contributions/50.46.176.46|50.46.176.46]] ([[User talk:50.46.176.46|talk]]) 05:14, 24 October 2014 (UTC)
 
:It seems to me pretty clear influence. Although Java didn't influence a lot in Python, it clearly influenced decorators. From the ref:
:"Guido took a list of proposals to EuroPython 2004 [7], where a discussion took place. Subsequent to this, he decided that we'd have the Java-style [10] @decorator syntax, and this appeared for the first time in 2.4a2"
:The ref is in a PEP, so it's pretty high-grade ref IMO.
:[[User:Peterl|peterl]] ([[User talk:Peterl|talk]]) 09:56, 5 November 2014 (UTC)
:: The trouble is that this is a ''very'' minor influence, yet the hive-mind at WP will probably now categorize Python as a "Java-based language".
:: Decorators didn't come from Java - they were long pre-existing before Java, and before most WP editors were born. What Python took from Java was a convenient syntactic style for representing decorators in source, no more. [[User:Andy Dingley|Andy Dingley]] ([[User talk:Andy Dingley|talk]]) 10:20, 5 November 2014 (UTC)
 
== Duck typing? ==
 
Is Python duck typed? re [https://en.wikipedia.org/w/index.php?title=Python_%28programming_language%29&curid=23862&diff=651243176&oldid=651236498]
 
IMHO, we should take this term out and burn it. The term "duck typing" is badly skunked: it so abused and misused that no-one knows what it means. Firstly few can define it and secondly (and most importantly) it's used to mean two contradictory things so frequently that no-one can ever communicate anything by its use.
 
"Duck typing" first became popular because Martelli in 2000 [https://groups.google.com/forum/?hl=en#!msg/comp.lang.python/CCs2oJdyuzc/NYjla5HKMOIJ] used it in reference to Python. However (as almost no-one remembers today) he used it ''in contrast'' to Python.
 
I can define "duck typing". I can even define "duck typing in Python". And if you tell me first whether you think Python is, or is ''not'' duck typed, then I can explain what it means and how Python is (or is not, whichever you favour) following it. The term just has no consistent definition, or a definition that can be in any way illuminating in an article on Python.
 
[[w:Duck typing]] is beyond hope, but also beyond AfD. However we should not spread the confusion or nonsense further than it has already gone. The term should never be used around Python coders. [[User:Andy Dingley|Andy Dingley]] ([[User talk:Andy Dingley|talk]]) 21:36, 13 March 2015 (UTC)
 
:Disagree. [[User:Peterl|peterl]] ([[User talk:Peterl|talk]]) 01:32, 15 March 2015 (UTC)
:: With what part? [[User:Andy Dingley|Andy Dingley]] ([[User talk:Andy Dingley|talk]]) 01:43, 15 March 2015 (UTC)
 
{{dedent}}
 
Hi. I'd like to interrupt and show this example.
 
<source lang=python>
class duck:
def quack(self):
print("Quaaaaaack!")
 
class human:
def quack(self):
print("Fine...quack...happy?")
 
class dog:
def bark(self):
print("BARK!BARK!")
 
class cat:
def meow(self):
print("Meeeeeeeow.")
 
for i in (duck(), cat(), human(), dog()):
try:
i.quack()
except:
print("A %s cannot quack." % i.__class__.__name__)
</source>
 
output:
Quaaaaaack!
A cat cannot quack.
Fine...quack...happy?
A dog cannot quack.
 
The above shows that <code>i</code> will act like a duck and <code>quack()</code> regardless of its class type and it will throw a graceful error if it cannot <code>quack()</code>. This leads me to believe that Python is pretty duck typed. I also disagree. --[[User:I8086|I8086]] ([[User talk:I8086|talk]]) 21:11, 15 March 2015 (UTC)
: Your example doesn't really illustrate the problem. We all know that this is how Python behaves. The question is, ''is this duck typing''? Per Martelli's original association of the term to a Python context, this ''isn't'' duck typing. Duck typing, following the spirit of the original expression "If it walks like a duck and quacks like a duck, then it's a duck" is based on judging a set of behaviours in order to assign an identity. This is not what Python does - Python ''avoids the need'' to deal with such identities, because behaviours (i.e. supported methods) are independent. In Python we just don't care about whether things ''are'' ducks or not, or even if they "can be treated as ducks", we simply work at the level of "Make it quack if it can", "Make it walk if it can" and then we leave it at that.
: The question here for this article is even simpler. If we recognise that "duck typing" is a useless term in software because there is no agreed meaning for it (can you cite a more authoritative source than Martelli?) and that the two meanings differ so far as to simply contradict each other, then does it help or hinder this article to include the term? [[User:Andy Dingley|Andy Dingley]] ([[User talk:Andy Dingley|talk]]) 22:54, 15 March 2015 (UTC)
 
:: Here's a definition straight from the [http://docs.python.org/3/glossary.html Python Documentation]:
 
:::A programming style which does not look at an object’s type to determine if it has the right interface; instead, the method or attribute is simply called or used (“If it looks like a duck and quacks like a duck, it must be a duck.”) By emphasizing interfaces rather than specific types, well-designed code improves its flexibility by allowing polymorphic substitution. Duck-typing avoids tests using type() or isinstance(). (Note, however, that duck-typing can be complemented with abstract base classes.) Instead, it typically employs hasattr() tests or EAFP programming.
 
:: This means you can call a method of any object while having EAFP (like the above example) in case you can't call that said method. So, along with that, I don't see why it should be removed; I find duck typing important. --[[User:I8086|I8086]] ([[User talk:I8086|talk]]) 01:11, 16 March 2015 (UTC)