Search code examples
pythondebuggingsmalltalkpharo

Is it possible to have a similar workflow in Python as in Smalltalk (e.g. Pharo) or Common Lisp?


I quite like the incremental programming I can do in Smalltalk. You have a running program and you add to it as you flesh out your program. You can change methods and restart the stack with the changes applied to see what the new version does. While your program is running, you can inspect local state and change them.

Is something similar possible in Python? I have seen hints of such abilities, such as reload(), but I don't know enough about Python to understand exactly how its used. I have looked through some beginner Python books, but I didn't see any mention of this.


Solution

  • Some things won't be possible no matter what effort is put on Python. For example, while developing a web app, the Flask/Django/Gunicorn or whatnot webserver has to restart its process after a change in the sources. But in say Lisp, you start a web server in the REPL, and you just compile a function that for example adds a new route, and you can try it right away. No process was restarted, it's all more interactive.

    Another example is updating classes and instances. In Common Lisp, suppose you wrote a class and created some objects. Now you change the class definition, and the existing instances get (lazily) updated. For instance, a new slot is added, one is removed, etc. And we can even control how the update is done (by subclassing some generic functions).

    Attaching to a running and distant process in Python is doable, but the interactivity is much less, and the editing experience is also less ideal (a dumb python shell in the terminal by default VS a full blown Emacs where you can navigate the sources and re-compile functions in one keystroke (C-c C-c in Slime) (or in any other editor that can connect to a Swank server)).

    Running one given unit test is also straightforward and fast, there is no process to restart.

    References: