TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Beefing up the Python Shell to build apps faster and DRYer

66 pointsby bjplessover 12 years ago

6 comments

stcredzeroover 12 years ago
To make this even more robust, steal a clever mechanism from Smalltalk -- the Change Log. Basically, all code changes and basically all of the manual manipulation of state was kept in a transactional log, so you could be as daring as you'd like with exploratory programming without the fear of losing any code. (Mandatory for Smalltalk, because all coding was interactive runtime exploratory programming.)<p>For iPython, you'd want to implement one change log per source file, so for a source.py file, there'd be a source.py.log file in the same directory. Runtime changes would first write a patch to the source.py.log file at parse/compile time. Then if you ever crash iPython after doing an hour of exploratory coding, iPython could reload your changes after the source.py file. (Actually, you'd want a little ui to come up, giving you the option of leaving off the last few changes, so you can omit something that causes a crash.)
评论 #5041285 未加载
klibertpover 12 years ago
There is also a wonderful extension to IPython, namely autoreload: <a href="http://ipython.org/ipython-doc/dev/config/extensions/autoreload.html" rel="nofollow">http://ipython.org/ipython-doc/dev/config/extensions/autorel...</a><p>I use it with level 1 and %aimport magic all the time and it's really sweet, especially with %ed. It probably does not work well with Django models however. You could use deep_reload: <a href="http://ipython.org/ipython-doc/stable/api/generated/IPython.lib.deepreload.html" rel="nofollow">http://ipython.org/ipython-doc/stable/api/generated/IPython....</a> but I'm not sure if it would be enough.
评论 #5040641 未加载
评论 #5040195 未加载
JulianWasTakenover 12 years ago
If your interpreter takes 3 seconds to start up there's something seriously wrong. Hopefully that's taking into account the human time to hit ^D and an up arrow, plus whatever time it takes to do all your imports or whatever. Assuming that was what was meant, then you probably really just want to learn about `python -i`.<p>I agree that the real solution here is "write unit tests", but even if you <i>like</i> an interactive interpreter, seriously, just restart it, it should take a half a second at most (and yes, reload() is broken by design, though sometimes it happens not to matter).
评论 #5039235 未加载
评论 #5039232 未加载
评论 #5039244 未加载
ianbover 12 years ago
I think doctest and a UI around the doctest concept (there have been a couple) is a better approach. There was one whose name I can't remember – r...something. Unfortunately it used wxWindows, and was a pain to install... native UIs suck.<p>But with a Doctest model you just develop a script, and if you change something rerun the script, starting where you left off (assuming the script reruns – if it doesn't then you probably want to start where it fails). You can extend the script without reloading still, but changing the past requires starting over... but it's just CPU cycles, assuming you aren't doing something computationally expensive. But even if so, you could have a kind of cross-session Pickling memoize function if you don't want to recalculate things.<p>These reloading tricks are fragile and break in weird ways, like it won't fix badly initialized data, or classes that can't be upgraded because of state changes. It leads ultimately to a distrust of the environment, until you throw your hands up and go back to the old restart-frequently model like everyone else. Recursive reloading certainly isn't new, but it's never satisfying.
tbatteriiover 12 years ago
seems a hard way to go to not write unit tests. FWIW, I use the shell too for exploratory coding but the moment that I find myself making changes and restarting the shell, chances are it's time to write it in a unit test.
评论 #5039040 未加载
juiceandjuiceover 12 years ago
Or, you know, you could try not reinventing the wheel and use emacs.
评论 #5039487 未加载
评论 #5041875 未加载
评论 #5040124 未加载