Hacker News new | ask | show | jobs
by arxanas 4862 days ago
The presentation incorrectly identified Python dictionaries as “lists”. It also identified actual Python lists as lists.

The presentation states that tuples are “immutable lists“ and that they ”should be homogeneous, but [this is] not enforced“. I disagree: tuples are meant to act as “records“ (as in a database or other set of data), which are neither lists nor homogeneous.

The presentation brought up multiple times filter and map. An article by Guido in 2005 [1] argued that these tools should be cut from Python 3. While they still exist, I am under the impression it is considered more Pythonic to use list comprehensions in the place of filter and map, as stated in the article.

Python not having define_method is misleading. One can define a method of a class as one would any attribute of the class [2]. However, it is far easier to dynamically define a method in Ruby than in Python, because lexical scoping is inherent to a Ruby block but not a Python loop.

Python not having method_missing is wrong. One can simply override __getattr__ and return the appropriate function [3].

[1]: http://www.artima.com/weblogs/viewpost.jsp?thread=98196

[2]: http://ideone.com/njXDzO

[3]: http://ideone.com/EB9MQ8

3 comments

> I disagree: tuples are meant to act as “records“ (as in a database or other set of data), which are neither lists nor homogeneous.

Indeed, hence `namedtuple` (named tuples extend tuples). The author got it exactly backwards: tuples are generally heterogenous, the (rare) cases of homogenous tuples are reflexive short lists and hope of a slightly cheaper creation cost.

The presentation incorrectly identified Python dictionaries as “lists”

From the context (I was there), that was obviously just a typo, probably carried over accidentally from a previous slide.

> it is far easier to dynamically define a method in Ruby than in Python

I don't know Ruby. But it's hard for me to imagine a syntax that could express any of several related operations which could reasonably be called "dynamically defining a method" in a "far easier" way than Python does. So please enlighten me, and the other "Pythonistas" who may be reading this article, as to exactly what this magical syntax is. (The clearest explanation would include some equivalent Python code or at least a plain-English explanation of what the Ruby code does -- the Ruby language's syntax has been a bit of a barrier to me.)