Hacker News new | ask | show | jobs
by chickamade 6064 days ago
I'd say that name-based interface is indeed Pythonic.

> Any type that has the named methods [...] is said to implement the interface.

For instance, in the tutorial, the cat function takes a reader interface. fmt.Print and Println a type will output whatever its String() "method" output. This is what Python does, e.g. "print x" is eqv. to "print x.__str__()".

1 comments

That's not a Python thing - it was present in Smalltalk, for example.
Well, if you're looking for features that Python was the first language to have, then I don't think Python has any "Python things". Garbage collection is still Pythonic, nonetheless.
Is it really useful or meaningful to claim every feature that Python has is "Pythonic", though? Are dicts "Pythonic"? Awk had them a decade earlier. Is garbage collection "Pythonic"? Lisp had it long ago. Dynamic typing? Generators? Etc.

To my understanding (and admittedly, while I've been using Python since around 1.5, I've largely abandoned it for Lua), 'Pythonic' is usually used to refer to the clearly preferred way of doing something that may have multiple implementations - Python's community making explicit the observation of conventions such as "for (i=0; i<N, i++) {" in C.

Using a dict rather than an int-indexed list is Pythonic, for example, because that's just the way that it's done in idiomatic Python, and the community encourages having one preferred idiom for common tasks. I don't think the concept applies to language features such as garbage collection.