Debugging using Python Tutor

I would encourage anyone to use Python Tutor
to work through the algorithm tests and for general debugging.

You can even share sessions for pair programming.
https://www.youtube.com/watch?v=Z2TIjNArOK4

1 Like

Yes, it’s good and it supports more than one language (like JavaScript) but if I want to share some code set up to run in it then I have to have a [massive obnoxious URL like this one](http://pythontutor.com/javascript.html#code= function%20log(s)%20{%20console.log(s)%3B%20} Array.prototype.myFilter%20%3D%20function%20(callback,%20context)%20{ %20%20var%20filteredArray%20%3D%20[]%3B %20%20for%20(var%20i%20%3D%200%3B%20i%20<%20this.length%3B%20i%2B%2B)%20{ %20%20%20%20if%20(callback.call(context,%20this[i],%20i,%20this))%20{ %20%20%20%20%20%20filteredArray.push(this[i])%3B %20%20%20%20} %20%20} %20%20return%20filteredArray%3B }%3B var%20unfilteredArray%20%3D%20[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]%3B var%20filterCallback%3B%20//%20lets%20save%20this%20for%20later var%20filteredArray%20%3D%20unfilteredArray.myFilter(filterCallback%20%3D%20function%20(element,%20index,%20array)%20{ %20%20return%20element%20>%3D%20this.min%20%26%26%20element%20<%3D%20this.max%3B },%20{min%3A%205,%20max%3A%209})%3B //%20We%20get%20an%20array%20with%20what%20we%20specified. log(“filteredArray%20%3D%20”%20%2B%20Object.prototype.toString.call(filteredArray)%20%2B%20"%20"%20%2B%20filteredArray%20%2B%20"<br>")%3B function%20inRange(min,%20max)%20{ %20%20return%20function%20(element,%20index,%20array)%20{ %20%20%20%20return%20element%20>%3D%20min%20%26%26%20element%20<%3D%20max%3B %20%20}%3B } var%20closure%20%3D%20inRange(8,12)%3B log(“Generated%20closure%3A%20”%20%2B%20closure)%3B //%20Now%20we%20use%20it%20with%20array.myFilter() log(“Testing%20our%20closure%20callback%3A%20”%20%2B%20unfilteredArray.myFilter(closure)%20%2B%20"<br>")%3B //%20Notice%20we%20didn’t%20need%20a%20context%20object%20literal%20like%20{%20min%3A%208,%20max%3A%2012} //%20We%20can%20also%20do%20things%20this%20way.%20This%20is%20really%20cool%20ninja%20stuff. //%20It%20makes%20sense%20to%20do%20this%20when%20we%20don’t%20need%20to%20reuse%20our%20closure. //%20It%20will%20just%20get%20garbage%20collected%20since%20it’s%20not%20assigned%20to%20a%20variable. log(“Another%20filter%20with%20another%20closure%3A%20”%20%2B%20unfilteredArray.myFilter(inRange(9,14))%20%2B%20"<br>")%3B //%20This%20is%20really%20awesome%20because%20we%20didn’t%20have%20to%20screw%20around%20with%20passing%20a%20separate //%20context%20object!%20We%20just%20ignored%20the%20second%20argument%20to%20myFilter()%20because%20we%20didn’t //%20need%20it! //%20Now%20lets%20prove%20that%20myFilter%20works%20the%20same%20as%20the%20built%20in%20filter. log(“Use%20the%20closure%20with%20the%20built%20in%20filter()%3A%20”%20%2B%20unfilteredArray.filter(inRange(2,14))%20%2B%20"<br>")%3B //%20Well,%20hopefully%20you%20understand%20closures%20now%20and%20will%20be%20able%20to%20use%20them%20with%20anything //%20that%20needs%20a%20callback,%20especially%20things%20like%20map(),%20reduce(),%20filter(),%20etc. //%20But%20if%20you%20don’t,%20don’t%20worry.%20You’ll%20eventually%20get%20how%20this%20works. //%20Just%20remember%20that%20functions%20are%20actually%20objects. log("<b>See,%20look,%20functions%20are%20objects%20in%20JavaScript%3A</b>%20"%20%2B%20closure.toString())%3B log(“Here’s%20a%20property%20of%20our%20closure%20function%20object%3A<br>” %20%20%20%20%2B%20"<b>closure.length%3A</b>%20"%20%2B%20closure.length)%3B log(“closure.length%20is%20the%20number%20of%20arguments%20the%20function%20takes.<br>”)%3B //%20Here’s%20yet%20another%20way%20to%20do%20things.%20We%20can%20tell%20a%20function%20to%20"bind"%20a%20new%20’this’ //%20and%20return%20a%20sort%20of%20closure-like%20copy%20of%20itself. boundCallback%20%3D%20filterCallback.bind({min%3A%202,%20max%3A%204})%3B //%20boundCallback%20is%20now%20a%20function%20where%20its%20’this’%20%3D%20{min%3A%202,%20max%3A%204} log(“More%20fun%20with%20a%20bound%20callback%3A”)%3B log(unfilteredArray.filter(boundCallback))%3B log("")%3B //%20We%20could%20also%20do%20it%20like%20this%3A log(“Even%20more%20fun.%20”%20%2B%20flash%20%2B%20"This%20is%20off%20the%20chain."%20%2B%20endFlash)%3B log(unfilteredArray.filter(filterCallback.bind({min%3A%2011,%20max%3A%2013})))%3B &curInstr=25&mode=display&origin=opt-frontend.js&py=js&rawInputLstJSON=[])

And then it doesn’t work because markdown or something messes it up. I’ll be more impressed when I can share code like a codepen etc.

When pair programming, I have used JS Fiddle.