Hacker News new | past | comments | ask | show | jobs | submit login
Online Python Tutor (mit.edu)
538 points by llambda on Feb 19, 2012 | hide | past | web | favorite | 45 comments

whoa what a pleasant surprise seeing my project on the HN front page this morning! just an FYI: this is a "demo-quality" project, not production-quality. it's probably not ready for HN-level traffic! please email me if you have more detailed suggestions or bug reports, thanks.

Have you seen this presentation by Bret Victor [0], as he touches on user experience in writing code? It seems like it might improve your product. :)

[0] http://vimeo.com/36579366

This is awesome.

Would be cool to see a version for a lower level language like C that would help people understand the stack and visualize pointer arithmetic.

If you found this awesome, Bret Victor will blow your mind (the coding tool is the third example): http://vimeo.com/36579366

Mind blown. Not just from the coding tools or the other examples, but the combination of those with a simple and powerful personal philosophy.

I can't believe the original link (submitted 5 days ago) has gotten so few views/points.

Thank you. This guy is unbelievable. He blows my mind every time he publishes something.

I want his editor.

I've emailed him asking for it! Gregory Bell asked him on twitter as well: https://twitter.com/#!/worrydream/status/169497569855143937

No response so far.

I don't think he will answer positively. It's only a demo and somehow I don't see him releasing an unfinished program. But I can imagine other people picking up his ideas.

Actually there is someone in the Vimeo comment thread who has started a live canvas editor(1) inspired by one of the demos.

Edit: (1)http://www.youtube.com/watch?v=TBUC-7D1LIc

great link! geez, this reminds me why i like to use web developer tools so much when i'm adjusting my CSS, HTML, and JS. honestly, a lot of my ideas come from real time editing. i love making small adjustments to my values and getting to see those take effect instantly.


This is simply amazing.

I hope this guy makes millions off his work. For something this revolutionary, he deserves it.

Amazing! His ideas and creative intensity are so refreshing.

Although I like these kind of tools, I doubt that they're useful to learn basic programming as they need a lot of prior knowledge to be present to already understand the visualization. For example, what is a stack or heap to a novice programmer? What will the effect of this visualization be on their construction of an operational understanding of basic programming language concepts? And these constructs, will they be helpful, have no effect, or even be detrimental for developing understanding of more complex programming structures?

On the other hand, in a more advanced course, say at university level, it might help to construct knowledge about how programming languages work internally and how this relates to their already existing understanding of basic programming constructs. So, as a teacher be sure to evaluate the effect of the educational tools you use. I know it is easy to use existing cool tools (and this one definitely belongs to that category), but what is its effect on your students' learning?

Having been a teaching assistant for intro programming classes targeted at non-CS majors, I disagree. You don't need to understand what a 'stack' or 'heap' is to understand what's going on and for this to be useful.

And even if it's too complicated to be useful for people on their own, being able to use something like this as a teaching aid would be very helpful. The number of people who have trouble grasping even what most of us consider very basic concepts like iteration over a list is astonishing. Trying to explain something you find trivially easy to someone who doesn't understand it at all is an exercise in frustration for both people. I usually resorted to doing a manual step-through on a whiteboard or piece of paper, but this is much nicer.

I would discourage people from using this constantly, just because I think having a step-through debugger handy constantly will prevent you from developing necessary debugging skills. (The concept of wrapping something in print statements is another thing I take for granted that's not obvious to some people.) But I still don't see how something like this could be anything but a net positive.

> But I still don't see how something like this could be anything but a net positive.

The student will construct their own knowledge of programming by some learning process. This tool has an effect on that process, as has every tool. It could, for example, let some students construct an understanding of a variable that makes it harder to start learning about, say, memoization in dynamic programming. (This is just an conjectured example, mind)

I don't say it will, and I do have to say that the visualization given is quite nice and sound. But because we, as experienced programmers, like a tool because it visualizes how we think about programming and program execution, that does not mean that this is transferable in a similar way to novice programmers. As a high school computer science teacher I have been growing more and more worried about so called anti-didactic inversion in programming education. Especially at lower levels of education.

In programming education, we often use professional programming tools with professional programming languages and professional measures of programming quality. When students are learning to become professional programmers, this is a good idea. But is it as good an idea for teaching programming to those who do not want to become professional programmers. Or for those who are learning programming as a basic skill (like math, language, etc)?

Using this tool, a student would get a visceral sense for what the stack and heap are, from experience (even if nobody had mentioned those words before). e.g. "Pointers point at stuff on the heap."

Teachers and students have been drawing pictures like this on the blackboard, or on paper, for a long time. Many experienced programmers visualize these pictures in their imagination (unless they're implementing a familiar pattern). That can be tedious and error-prone. Why not let the computer show you what it's doing?

Many debuggers already show some of what this tool does, but I've never seen one quite like this.

Can you give an example of a "more complex programming structure" where this would be detrimental to understanding?

> Can you give an example of a "more complex programming structure" where this would be detrimental to understanding?

It is difficult to imagine what kind of knowledge novice learners will construct while using this tool. I could imagine, for example, that their operational meaning of a variable becomes that of consecutive boxes with values in them. Given that knowledge, how would such a student start to understand a variable in a closure? Will it fit their existing understanding of variables as boxes? Maybe it does, maybe it will not. Maybe they have to deconstruct their understanding of variables first to connect it to their budding understanding of a closure, building a deeper and more widely understanding of variable. Maybe this will be not too much of a problem. Maybe this becomes a hurdle. We don't know unless we try it out, of course.

Learning isn't an exact science. I think that dynamic representations like this one are very useful in teaching and learning. However, I would also argue to use these tools with care and conscience. Although it seems to fit our operational view of a program, that does not mean it is a good fit of a novice learner's operational view of a program. Whatever tools we use will influence that operational view. What I want to ask teachers is to evaluate and reflect on the best way and place (in space/time) to use these tools to make learning as optimal as possible.

I think if you tried to teach programming to two groups of people who had minimal programming experience, one using say the normal python interpreter and one using this tool, the latter group would acquire a better understanding of what is going on in less time.

The diagrams used here are similar in style and content to the environment diagrams used in SICP (Structure and Interpretation of Computer Programs), which is an introductory (and quite comprehensive) CS text. At Berkeley at least -- and I think MIT as well -- SICP is taught in a course taken by both majors and non-majors are taking CS courses.

MIT did away with SICP in its intro class a few ago. Quite a shame, but that's the subject of another post.

It is great that Hacker News has caught up with this -- Philip has done a great job with the Python Tutor. Next step: user-definable layout for display of different data types.

There was a paper on that sort of thing: Korn & Appel, "Traversal-based visualization of data structures". (It's online but I can't get the link out of the search result easily.)

As someone who went through Intro to CS courses. I must say that including the object oriented paradigm of Java in an intro class really confused me for a good three years. It wasn't until I learned how data was organized and executed inside a computer that it all became clear to me what programming really consisted of.

This tool is wonderful. It visualizes the inner workings of a computer very well and how it translates to code. I hope this teaching tool is used on students after they've learned some basic programming concepts and syntax.

Works great on iPad -- well done!

yea! Surprisingly!

The tool is awesome, but I wouldn't rely too much on the instruction bounds. For example, the greatest sums exercise (http://people.csail.mit.edu/pgbovine/python/question.html?op...) can be solved in six "steps" for all input lengths, while it's certainly no O(1) business.

  def maxPairSum(data):
    return sum(sorted(data)[-2:]) # one "step"

Actually, both your solution and theirs are not O(1). Theirs is n^2, while yours is n lg n due to the use of a sort function. The best way to do this would simply be to find the largest element, ignore that element and find the largest element again, which is O(n).

I do believe the GP's message was that the tutor told him his solution took one "step", which is not equivalent to O(1), because sorted() takes O(nlgn).

In other words, he was pointing out the limitations of the tutor program's analysis.

I'm perfectly aware, but can you take that approach and execute it in 6 "steps" for all data sizes?

Since the whole point of the exercise is "optimizing" maxPairSum so that it runs in 20 "steps" or less, I guess this slower solution is still more "optimized" - which was my whole point, after all. :)

(Please note 6 steps is the bare minimum - one for the function definition, one for preparing input, one for calling the function, one for calling the function, one for assigning function arguments, one for the actual function and one for returning from the function. You can't go shorter than this.)

Indeed, but it won't even accept the following O(n) solution. I get "(stopped after 20 steps to prevent possible infinite loop)" when submitting this:

  def maxPairSum(lst):
      if lst[0] > lst[1]:
          top, top2 = lst[:2]
          top2, top = lst[:2]

      for i in range(2, len(lst)):
          if lst[i] > top:
              top, top2 = lst[i], top
          elif lst[i] > top2:
              top2 = lst[i]

      return top+top2

In fact, that is the solution they give (if you click on the "hint" and "solution" links).

This is a fantastic tool. I love it.

On line #9 of the example program, the string "hello" is assigned to y. On line #12 another string "hello" is used. I don't know anything about the inner workings of Python, but I imagine that these strings would be stored on the heap and possibly 'interned' by the interpreter. Maybe this is being ignored for simplicity, or I am way off the mark.

Thanks a lot! I wish I had something like this for basic C++, my students would love it!

I need 4 lines to do the mergesort correction. What's the way that is expected here? I would do,

    if i = len(left):
    if j = len(right):

nevermind, sneaked a peek at the original code http://en.literateprograms.org/Merge_sort_(Python)

100% cpu usage on chrome 19.0.1042.0 canary 0% cpu usage on firefox 13.0a1 (2012-02-18) until foo/bar execution (100% cpu usage too)

Like it anyway. Great job

This should be insanely useful for someone new to Computer Science. I wish I had this during my undergrad career. Good job!!

Does anything like this exist for Javascript?

I'd love to see this in debugger form!

Where was the aliasing?

Was it y = x perhaps?

Really, really cool.

unicode breaks it

thanks! that's a known bug in my todo list

If you want to learn Python, MIT OCW Intro to Programming is probably the best resource there is: http://ocw.mit.edu/courses/electrical-engineering-and-comput...

I got through 20% of Learn Python the Hard Way, stopped for a number of months, and have now delved into a few of the linked lectures. Learn Python the Hard Way is already much more intuitive and simple to pick up (in a good way). http://learnpythonthehardway.org/

However, I think the lectures are complementary. :D

Registration is open for Startup School 2019. Classes start July 22nd.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact