alice-teacher Passing an object to a method doesn't appear to work completely in Alice 2.3.2

Don Slater dslater at andrew.cmu.edu
Mon Apr 15 14:46:11 EDT 2013


One way I have found to help students see this is to role play it… For example in this case, put the value of the variable on the board, and give three students one of the tasks each, and tell them to execute them at the same time. (one has to walk to the board to change it, one has to print what is one the board on another part of the board, one has to write what is on the board on a note card and hand it to another student (parameter passing).

Depending on the timing, you may get to illustrate collisions (part of the value on the board has been erased while the students are copying or displaying the value, etc).

Students instinctively understand doTogether, particularly on computers; they understand that they can be watching a YouTube video and the system will indicate that they have received mail at the same time. It may or may not be necessary, depending on their age and the course goals, that they understand the technical details about concurrency and threads. But they should be forced to think about what it really means to do separate things at the same time.

Re your second point concerning a knowledge base: That is a nut I have been trying to crack for some time now…It certainly is on our to do list; unfortunately, we have not yet figured out how to implement the "to do together list"… ;-)

All the best,
Don Slater


On Apr 15, 2013, at 2:27 PM, Marty Schultz <schultz_marty at hotmail.com> wrote:

> Don,
>  
> Thanks, once you mentioned it was the threading issue, it all made sense to me.
>  
> There’s no easy way to explain that to students at their level of programming understanding, and it’s probably nontrivial for Alice to detect that condition on-the-fly (unstable value within a variable).  Is there a forum or other repository for things like this – maybe a BEST PRACTICES or knowledge base?
>  
> Thanks.
>  
> From: alice-teachers-bounces+schultz_marty=hotmail.com at lists.andrew.cmu.edu [mailto:alice-teachers-bounces+schultz_marty=hotmail.com at lists.andrew.cmu.edu] On Behalf Of Don Slater
> Sent: Monday, April 15, 2013 2:19 PM
> To: Alice educators
> Subject: Re: alice-teacher Passing an object to a method doesn't appear to work completely in Alice 2.3.2
>  
> I asked Marty to send me a copy of his code… This is my reply him, but it demonstrates a problem using DoTogether which happens frequently, and is very difficult to overlook and track down.
>  
> See the attached screen shot, from the method "world.KeepScore":
>  
> The code of concern is this doTogether, in which you are (1) setting the value of the variable 'animalThatWasHit',  (2) printing that value, and (3) sending that value as a parameter, AT THE SAME TIME.
>  
> A do together generates separate, independent threads for each statement in the doTogether body, and so what is happening in one statement may or may not, depending on the timing, have any impact on the other threads, particularly if they are trying to use the same variable.
>  
> So it is not so much that the value reverts to paintball, but that you print as the value is being set. If you had printed it again, after the doTogether, you would have seen the correct result.
>  
> I dissolved the doTogether and got the following output after running the program:
>  
>             tiger
>             none
>             tiger
>             none
>             tiger
>  
> I hope that this helps… 
>  
> This is a very difficult bug to track down, one that even experienced Alice programmers. will make. It is easy to overlook (you did not even think to include the doTogether's in your pseudocode, and yet they are critical) and not think about.
>  
> Look at how different your pseudocode looks if you had written it this way
>  
> Method world.keepScore looks similar to:
>                         DoTogether
> 
>                 // precondition: Local variable animalThatWasHit (type=OBJECT, initial value set to paintball)
>  
>                 20 animalThatWasHit set value to world.whoGotHit
>                 20 print animalThatWasHit
>                 20 world.whenHit target=animalThatWasHit
>  
> All the best,
> Don Slater
>  
> <image001.png>
>  
>  
> On Apr 14, 2013, at 9:48 PM, Marty Schultz <schultz_marty at hotmail.com> wrote:
> 
> 
> Does anyone have a solution for this (I’ve included pseudo line numbers to make it clear):
>  
> Function world.whoGotHit (returns type OBJECT) ends with:
>                 10 print “world.whoGotHit”
>                 11 print tiger.name
>                 12 return tiger
>  
>  
> Method world.keepScore looks similar to:
>                 20 Local variable animalThatWasHit (type=OBJECT, initial value set to paintball)
>  
>                 22 animalThatWasHit set value to world.whoGotHit
>                 23 print animalThatWasHit
>                 24 world.whenHit target=animalThatWasHit
>  
> Method world.whenHit
>                 30 parameter target (type=OBJECT)
>                 32 print “world.whenHit”
>                 33 print target
>  
>  
> When I PLAY this program, the PRINT statements show:
>                 world.whoGotHit (from line number 10)
>                 tiger (from line number 11)
>                 the value of world.keepScore.animalThatWasHit is tiger (from line 23 – this is expected)
>                 world.whenHit (from line 32)
>                 the value of world.whenHit.target is paintball (from line 33- this seems WRONG – it should be “tiger”)
>  
> What appears to be happening is that even though the value of animalThatWasHit is “tiger” in the world.keepScore method, when the world.whenHit method is called, the value reverts back to the initial value, not the value shown in the parent (world.keepScore) method.
>  
>  
>  
>                
> _______________________________________________
> alice-teachers mailing list
> alice-teachers at lists.andrew.cmu.edu
> https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers
>  
> _______________________________________________
> alice-teachers mailing list
> alice-teachers at lists.andrew.cmu.edu
> https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20130415/82df94d8/attachment.html 


More information about the alice-teachers mailing list