5 ms·
Online Python Tutor: Learn programming by visualizing code execution
- prezjordan 14y agoIs there a self-hosted option for this? I think this would be an excellent resource for my students, but I'm having trouble getting my examples to run. (memory overload?)
- bbx 14y agoLooks like the source is on GitHub: https://github.com/pgbovine/OnlinePythonTutor https://github.com/pgbovine/OnlinePythonTutor
- pgbovine 14y agoPlease email me examples that fail to run. It might be memory overload, or just other weird server crashes. (My alert dialog message isn't particularly informative.) Online Python Tutor isn't meant for running large examples. Think of it as a "digital whiteboard"; I don't think anyone would expect to visualize a 100,000-step program with tons of pointers on a whiteboard :)
- scott_s 14y agoPhilip, this is fantastic stuff. How have I not heard of your project before? Have I not been paying attention, or have you not shown it here before?
- ronyeh 14y agoI don't think Philip has posted this project on here before. His user name is: http://news.ycombinator.com/user?id=pgbovine http://news.ycombinator.com/user?id=pgbovine Another project he worked on that you may have seen on HN is the PhD Grind book (about getting a CS PhD from Stanford).
- flexie 14y agoOh man! This is useful. Thanks.
- nicpottier 14y agoUn-fucking-believable! This is exactly what I needed to help people visualize their code. I can't tell you how many beginners have a hard time figuring out how a program steps through their code and this is a huge win there. Huge thanks!
- jftuga 14y agoThis is really awesome. I am trying to teach my kids Python and this will be very helpful.
- MathProgramming 14y agoWhy would they simulate a linked list using tuples? It seems a bit contrived (or rather, not Pythonic) when lists are a built-in datatype.
- TeMPOraL 14y agoA quick way to emulate cons cells[1], which are good for explaining how linked lists work? [1] - http://en.wikipedia.org/wiki/Cons http://en.wikipedia.org/wiki/Cons
- pgbovine 14y agoYep, right on! I wanted to show off linked list recursion and render box-and-pointer diagrams like those seen in SICP.
- deleted 14y ago[deleted]
- johncoltrane 14y agoI saw it some months ago (1) but it didn't get much traction. And I failed to upvote it, shame on me. This is really good work. (1) http://news.ycombinator.com/item?id=3759858 http://news.ycombinator.com/item?id=3759858
- TeMPOraL 14y agoJust 5 days ago HN was all so negative about Bret Victor's visions[1] of how programming should be taught. And yet here we are, looking at a working example of one of the ideas he wrote about. [1] - http://news.ycombinator.com/item?id=4577133 http://news.ycombinator.com/item?id=4577133
- pgbovine 14y agoBret has certainly been an inspiration to lots of us who work in this field, but I still don't think this is an implementation of his vision. To truly implement his vision, someone would need to design a new programming language and environment. My motivation has been to ease the learning path for an existing popular language (Python).
- TuringTest 14y agoI have been thinking of such a language for several years. Now that life programming environments are getting traction, I might be able to bootstrap the process and program my ideated language on top of one of them. See this 2003 PhD thesis at MIT for two examples of existing languages designed to take full advantage of live programming environments. (Flogo I -graphical- and Flogo II -textual): http://llk.media.mit.edu/papers/ch-phd.pdf http://llk.media.mit.edu/papers/ch-phd.pdf Particularly interesting is Flogo II capability to mix the imperative and functional-reactive programming paradigms in the same code block, as parallel runtime processes; I hadn't seen that before.
- seanmcdirmid 14y agoChristopher Hancock's thesis is pretty good; flogo II plays around with this feature called "live text" where it embeds code exucution visualizations directly in the text of the code. I still haven't seen anyone pull that off again.
- TeMPOraL 14y agoTo clarify: I didn't mean that it was whole his vision, nor did I thought you was inspired by his recent text (someone mentioned in the other thread that your tool is around for months). But this is a living example of one of the ideas he discussed in his last essay (even if this example is independent of and older than the essay itself).
- csmatt 14y agoI'm sold. Great work! I advocate learning to program to non-programmers all the time (and typically suggest Python), but visualizing flow is hard to teach succinctly with words. I really think this type of visualization with accompanied explanation, where needed, will help quite a bit. Heck, I may use it for debugging at times in the future.
- DanielRibeiro 14y agoFormer discussion: http://news.ycombinator.com/item?id=3609263 http://news.ycombinator.com/item?id=3609263
- csmatt 14y agoI'm sold. Great work! I advocate learning to program to non-programmers all the time (and typically suggest Python), but visualizing flow is hard to teach succinctly with words. I really think this type of visualization with accompanied explanation, where needed, will help quite a bit. Heck, I may use it for debugging at times in the future.
- pgbovine 14y agoOh wow, woke up this morning to some great emails. Thanks, everyone! Here is some context behind the current incarnation of Online Python Tutor: https://plus.google.com/+ResearchatGoogle/posts/cseo9qi7LWq https://plus.google.com/+ResearchatGoogle/posts/cseo9qi7LWq
- maskedinvader 14y agothis is awesome, learning from visualizing how the code is executed IMO is a great way to learn to code. To add to that, its teaching python which I believe is already very easy to read and learn, brilliant. If this doesn't make it easy for young students learn programming for the first time then I don't know what will ! great job !
- njharman 14y agoIt's not exactly Python (or I'm doing something wrong). Which is very confusing / "dangerous" for people learning Python (They will learn it wrong and not have the xp/confidence to question tutor) locals() and globals() are undefined. Still crazy slick (if it were the early 90's I'd say "l33t") bit of coding.
- btown 14y agoIf you're learning Python and are using locals() and globals() as anything more than a debugging tool... I'd venture to say you are doing something wrong ;) In seriousness, any programmer will need to know that functions don't just magically appear... if they don't work, they'll need to know how to pull in some sort of library, or realize why those functions just don't make sense for the current environment (one could explain to a complete novice why it would be a security breach to allow I/O functions, for instance). Python is a language, not a standard library, just as C is C even if you don't #include <stdlib.h>.
- upthedale 14y agoLooks good. However, my big criticism of these sorts of visualisations is they seem to be entirely geared towards imperative programming. Has anyone seen similar visualisations for more functionally structured code? Oh, I see you can write your own code to be visualised. Here's a simple list comprehension: http://pythontutor.com/visualize.html#code=myList+%3D+range(10)%0Atotal+%3D+%5B2+*+x+for+x+in+myList+if+x+%25+2+%3D%3D+0%5D&mode=display&cumulative=true&py=2&curInstr=0 http://pythontutor.com/visualize.html#code=myList+%3D+range(... Not the most enlightening visual.
- agentultra 14y agoGenerators are similarly confusing to visualize... http://pythontutor.com/visualize.html#code=def+fib(n)%3A%0A++++i+%3D+0%0A++++a,+b+%3D+(0,+1)%0A++++while+i+%3C%3D+n%3A%0A++++++++yield+b%0A++++++++i+%2B%3D+1%0A++++++++a,+b+%3D+(b,+b%2Ba)%0A%0A++++++++%0Afor+x+in+fib(8)%3A%0A++++print+x&mode=display&cumulative=false&py=2&curInstr=0 http://pythontutor.com/visualize.html#code=def+fib(n)%3A%0A+...
- anonymous 14y agoIt does look a bit confusing, but it does step through the program in the order it executes. Unlike list comprehension, where it completely misses some instructions.
- lquist 14y agoCheckout DrRacket's debugger. Obviously not as well documented as this, but amazingly insightful.
- pgbovine 14y agoThe inherent limitation here is that Online Python Tutor is built upon a line-oriented single-step debugger (Python's bdb module), so there's no way for it to step inside of subexpressions (e.g., in your list comprehension example).
- DeepDuh 14y agoI still believe that imperative is the best paradigm to start programming. I.e. once you understand all the subtleties of for/while and branching, you can undertand a list comprehension as an abstraction on top of that, applicable for certain situations. In that light I think OP's tool is exactly what one needs to get going. A similar approach for those mounting towards FP would be certainly nice though, but it would have a completely different target demographic. Also it seems to me that languages like Haskell and F# are better for just learning FP.
- slykat 14y agoThis would have been really useful when I was learning Python on Udacity and was confused by the behavior of = and += on lists and tuples. This should definitely be integrated into Udacity and other learning platforms! Most instructors have to do this by hand in CS 101 lectures anyways.
- detox 14y agoA big plus for most people out there. I'm a visual learner myself. I've always had trouble in the early stages of learning because I didn't really realize I was a visual learner until later on. Also, college professors didn't give simple tips like you should draw out diagrams of what's happening in the code because that helped me out a lot.
- deleted 14y ago[deleted]
- pkandathil 14y agoHey guys, Isn't this the same as a debugger. Can people not learn from that?
- csense 14y agoInstalling PyDev in Eclipse is a few big hoops for a beginner to jump through. The Web version Just Works with a browser.
- btown 14y agoEven now, after almost 10 years of programming, I still wish my debuggers had arrows pointing to data structures in a nice GUI. Sometimes, you don't want to interrupt your train of thought to recall the gdb or pdb command you need, or to remember "was 0xAE32F542 the first node in the list or the second node?" And consider the WebKit debugger for Javascript: just by looking at the Scope Variables tag, it's not obvious to catch a bug where you did `x = y` rather than `x = deepClone(y)`. TL;DR I wish this was the same as a debugger, because then debuggers would be awesome.
- hackinthebochs 14y agoNot quite. The visualizations are great, but the ability to rewind and replay time is the critical piece here. How many times have you had to stop and restart debugging because you missed something critical?
- zerop 14y agoI used to browse this tutor on MIT earlier.. http://people.csail.mit.edu/pgbovine/python/tutor.html http://people.csail.mit.edu/pgbovine/python/tutor.html
- oellegaard 14y agoToo bad it stops at 300 steps, I would have loved to use it for my hand-ins at the university - still, pretty cool! I checked how it looked with MergeSort and it was pretty awesome, even though it didn't get far with 300 steps.
- jkf 14y agohttp://ec2-107-21-160-68.compute-1.amazonaws.com/crs-ltp/tutor.php#mode=edit http://ec2-107-21-160-68.compute-1.amazonaws.com/crs-ltp/tut... I think the tool of the course in coursera.org is the same.