Well oh Well, Python is stupid.... Very, very stupid

To my suprise live coding in Python its actually easier to what I expected
and almost the same, from user perspective to that of pharo.Minus the IDE
conveiniece of course.  But a pain in the hat to find the proper way to do
it.

I was reloading modules, was thining of implementing become to python ,
which basically means replacing references to old instance object with
references to new objects , then I thought that it would be more efficient
to just reference the new methods to the instances and after a TON of
testing I realized this is dead simple and for some reason python hides it
very well. All the above were completely unecessary.

Insance methods are referencing functions in the class object. Apparently
functions in a class are taken as class methods and functions with self as
first argument are considered instance methods. Which means I just copy
paste the code of the method to the debugger, and assign it back to the
existing live class and all instances are updated automagically. No need
for become, no need to update instances manually no need to even reload the
module. Similarly you can delete methods and add methods on the fly always
live. Renaming a method is basically deleting and assigning . Renaming the
class is the same. As is for class and instance variables. So anything can
change on the fly. Names are there for your pleasure, in the end all that
matters are the references.Its objects all the way down.

The equivelant of a python instance method defiition and live updae , the
python way, on Pharo would be

MyClass instanceMethodName:= myMessage firstArg:self arg2: foo1 arg3:
foo2....
|locals|
code stuff

and you python "call it" or message it

MyClass insanceMethodName arg2:foo1 arg3: foo2 , no need to use self when
calling it. Self is automatically passed because from the definition python
knows this is suppose to be an insance method.

or you could put a block after the assigment , because the name of the
message is assigned by the assignment anyway,  for class method you ommit
the first argument of self. Calling is the same. This replaces a method or
adds it if does not exist. All instances of that live class are immediately
poitining to the new method. So the class is basically a collection of
references.

So all I have to do now is to wrap the copy paste and assignment in a
single shortcut or button and I am ready to fly to live coding land. Days
wasted chasing my tail but at least I learned a lot about python objects
which are basically dictionaries objects (for variables) plus function
objects (for class and instance methods) wrap inside an object, or rather
referenced, called a class.

Storing the live state , similar to fuel, is supported by the pickle
library.

Why on earth python made it so hard something so simple to understand ? no
idea .I dont even need to make a live coding enviroment library as I
assumed, its already there, hiding under the cover too scared to come out.


Now I know why none or almost none does live coding in Python.

Reply via email to