Is anyone using meta-meta-classes / meta-meta-meta-classes in Python/ other languages?

前端 未结 5 644
北荒
北荒 2020-12-14 20:25

I recently discovered metaclasses in python.

Basically a metaclass in python is a class that creates a class. There are many useful reasons why you would want to do

5条回答
  •  一整个雨季
    2020-12-14 20:50

    During the History of Programming Languages conference in 2007, Simon Peyton Jones commented that Haskell allows meta programming using Type Classes, but that its really turtles all the way down. You can meta-meta-meta-meta etc program in Haskell, but that he's never heard of anyone using more than 3 levels of indirection.

    Guy Steele pointed out that its the same thing in Lisp and Scheme. You can do meta-programming using backticks and evals (you can think of a backtick as a Python lambda, kinda), but he's never seen more than 3 backticks used.

    Presumably they have seen more code than you or I ever has, so its only a slight exaggeration to say that no-one has ever gone beyond 3 levels of meta.

    If you think about it, most people don't ever use meta-programming, and two levels is pretty hard to wrap your head around. I would guess that three is nearly impossible, and the that last guy to try four ended up in an asylum.

提交回复
热议问题