Class as Syntactic Sugar of Functions in Python

More explanation coming up, but essentially I’ve tried to define classes with functions in Python for a couple times already, but this time I have something that looks pretty good.

To use it, you just have to provide the class name and instance variables and methods:

make_class(
<class_name>, 
{'__init__': <...>, 'instance_variable_or_method': <...>})

Essentially I used decorators to allow users to define functions that take in self as the first argument but call those functions without self. Also note, the init doesn’t have to return anything just like regular Python. The client code starts at line 22.

Screen Shot 2019-04-08 at 12.39.18 AM.png

 
0
Kudos
 
0
Kudos

Now read this

Clojure

Stuff I wanna write in the future about Clojure: 4 core data structures, 1 interface => composability of functions => higher code reuse cheap immutability from the core functions (b/c structural sharing) => easy to write pure... Continue →