For example, Python does not seem to have metaclasses.
Of course, this just does not mean creating a new metaclass for each class: it uses the same metaclass by default as the parent class, or type . The Python design philosophy, also known as “Zen of Python,” can be examined with import this at the prompt of the interactive interpreter; the applicable point here is second: "Explicit is better than implicit."
In Python 2.X, you specify a custom metaclass with the following syntax:
class sic: __metaclass__ = mymeta ...
In Python 3.X, more elegantly, you use the named-argument syntax:
class sify(metaclass=mymeta): ...
Smalltalk does not have the concept of generators.
Python generators are first-class (usually autonomous) functions, and Smalltalk does not have the concept of "autonomous" functions - it has methods inside classes. But it certainly has iterators - like classes, of course:
iterator := aCollection iterator. [iterator hasNext] whileTrue: [iterator next doSomething].
Since Smalltalk has first-class “code blocks” (Ruby took them from it), you iterate along with the other “control structures” by sending the code block to the appropriate method, and if you want, you can do that directly with the collection (think select: ):
aCollection select: [:item | item doSomething].
So, in Smalltalk (and Ruby) you send a block of code to iterate; Python does the opposite, iterating sends values to the surrounding "calling" code. It looks very different, but not "deeply" different at the end.
First-class code blocks mean that Smalltalk is not needed, and also does not have instructions and keywords of the "control structure", such as if or while : they can be executed by sending code blocks as arguments to the corresponding methods (for example, ifTrue: the Boolean method) . (Ruby selects keywords / operators in addition to first-class blocks of code, I would say that Python [[explicitly]] and Smalltalk [[implicitly]] both try, like C, to “suggest one way to execute the operation”, while Ruby more at Perl-ish school "There are many ways to do this").
And although both of them say that they are dynamically typed, I that Python does not do a dynamic method of sending. It is right?
No, it’s absolutely wrong - Python intensively implements a dynamic submit method, to the extreme values . Consider, for example:
for i in range(10): myobject.bah()
In Python semantics, it performs 10 searches for the bah method in myobject - in case the previous execution of the method caused myobject completely restructure itself inside, so its current bah method bah completely different from the previous one (maybe it's a very crazy thing for a programmer to rely on such furious dynamism, but Python supports it). Exactly because of this reason:
themethod = myobject.bah for i in range(10): themethod()
general manual optimization in Python code - does one dynamic search before the loop instead of 10 inside the loop, one for each leg (this is a case of "constant lifting", since the compiler is not allowed to perform "constant folding" according to the extreme Python rules for dynamic search - if only this will not prove that it is guaranteed to be harmless, and in practice such a proof is too complicated, so Python implementations are usually not bothered).
Python uses unified namespaces: methods are attributes of an object, like any other, except that they are called. This is why retrieving a method without calling it (known as the “associated method”), setting a reference to it in a variable (or copying it to a list or other container, returning it from some function), is simple and simple control, as in the above example with a constant climb.
Smalltalk and Ruby have separate namespaces for methods and other attributes (in Smalltalk, non-method attributes are not visible outside the object’s own methods), so “method extraction” and “calling the resulting object” require more introspective ceremony (but in some cases the general dispatch case can be simplified a little - in particular, the “just mentioning” method without arguments invokes it implicitly, whereas in Python, as in C, the call is explicitly performed by adding parentheses, while “just mentioning”, well ... " just mentions "him, elaya it available to any explicit operations, including call; -).