程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Where did Pythons metaclass design come from?

編輯:Python

A veteran Python Core developers have suggested that we ( Click here to read ), You should widely learn the excellent features of other programming languages , Thus enhance Python Ability in related fields . In terms of metaprogramming , His suggestion is to learn Hy and Ruby. however , He also mentioned , He doesn't know which language to learn , Can deepen right Python Understanding of metaclass design .

This actually means ,Python The metaclass design of has great originality , Not from the mature design of which language !

Since I didn't learn it from other languages , that ,Python Where on earth did the metaclass thought of come from ?Guido Will not be “ Out of thin air ” Create a design ?

The following translation , The author is Guido van Rossum(Python The father of ), Written in 2013 year 10 month , That's the answer Python The origin of metaclasses :

original text :https://python-history.blogspot.com/2013/10/origin-of-metaclasses-in-python.html

translator : Cat under peas @Python cat

Statement : This translation is for the purpose of communication and learning , be based on CC BY-NC-SA 4.0 License agreement . For easy reading , There is a slight change in the content , All pictures are added by the translator .

python-ideas There was speculation in the newspaper Python Metaclass design is derived from Ruby. This is not the case . Since it is about the origin of language characteristics , I think I need to clarify the facts .

About metaclasses , I didn't get it Ruby Inspired by the ( Not in the future ). in fact ,Ruby Suffered Python Inspired by the .Mats Once told me , His inspiration is 20% come from Python, Yes 80% come from Perl, and Larry Wall Is his hero .

( Translation notes :Larry Wall yes Perl The father of language . He was in 2014 Visit to China in ,《 The programmer 》 The magazine did an exclusive interview , Recommended reading .)

I am here 1998 Wrote about Python Metaclass articles :http://www.python.org/doc/essays/metaclasses

Guido Meta essays

( Author note : That article 1998 The article in contains a fully functional Enum Realization , It has a lot to do with PEP-435 The same characteristics .)

The new class is just the second or third iteration of the idea .

I was inspired by a Book , namely Ira Forman and Scott Danforth Written 《Putting Metaclasses to Work》.

Douban is included
Amazon's price really scared me !

But even in Python In the original design (1990 year , Published on 1991 year ), type (type) Itself is an object . The type pointer in any object always points to a special object , The object “ data ” It's a bunch of... That implement the behavior of other objects C A function pointer , Be similar to C++ Virtual function table of .

The type of a type is always a special type object (The type of a type was always a special type object), You can call it meta type (meta-type), Because it is its own type .

At that time, I was right about Smalltalk Only vague understanding ; When I read about its metaclass design later , I'm surprised , Because it is related to Python or Ruby The metaclasses in are very different !

however ,Smalltalk Bytecode pair Python Bytecode has a great impact . I am here Adele Goldberg I read in a book with others , Seems to be 《Smalltalk-80: The Language and its Implementation》.

smalltalk book

( End of translation )

The above article is from Guido Of 《The History of Python》 series , This series is mainly about Python History of language and community development . I have translated the latest article in this series 《pgen Origin of parser 》, I planned to translate other articles one after another ……( Just once )……

Coincidentally, , Just after the translation of this article and looking up the data , I stumbled upon someone 2019 The series has been translated in the first half of ( He translated 25 piece , It just doesn't include the latest one I translated )! These translations , I've never read !

The translator also has official account number. , I read some articles curiously , I found that a lot of reading is only 10 How many? ! It seems that the translator didn't make much effort to operate , Just as a learning interest , Do things silently , No applause .

therefore , If you are right about Python If you are interested in history related content , I sincerely recommend your attention “ReadingPython”, View its history .( in addition , The translator is translating 《Python behind the scenes》 series , This is also one of my translation plans , And actually one 1.4 Half of the translation of 10000 words was put on hold for several months ……)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved