2 ms·
GOSUB/RETURN may be easier to explain, but of course it also doesn't cover many things that functions with local scope do. Explaining functions and recursion i
by int_19h 6y ago
GOSUB/RETURN may be easier to explain, but of course it also doesn't cover many things that functions with local scope do.
Explaining functions and recursion is tricky in general, but necessary for other things to make sense. There are ways to do so that might be more intuitive for a newbie to grasp. For Python specifically, take a look at https://thonny.org https://thonny.org - it's particularly well suited to forming a mental model of a running program, including function calls, in a very visual way.
- beagle3 6y agoOh, of course. GOSUB/RETURN are easier to explain, but only as a stepping stone towards functions; I like them because unlike functions+locals, which are much more "all or nothing" - whereas when I taught basic, I would start with "GOTO" which is trivial for everyone to understand; then go to GOSUB+RETURN, which is just a tiny bit harder, but still very capable - my complex gosub+return example was flood fill[0]: 9000 REM F=FOREGROUND COLOR, X AND Y ARE COORDINATES 9010 IF POINT(X,Y)=F THEN RETURN 9020 PLOT(X,Y,F) 9030 X=X+1 : GOSUB 9000 : X=X-2 : GOSUB 9000 : X=X+1 9040 Y=Y+1 : GOSUB 9000 : Y=Y-2 : GOSUB 9000 : Y=Y+1 9050 RETURN Which does recursion, visually, with only gosub/return, lets me touch on stack overflows (trying to fill too big an image would on most interpreters). I have never had the chance to teach BBC Basic, but if I did, even though it has PROCs and LOCALs, I would still go the GOTO -> GOSUB/RETURN route, and only then proceed to DEFPROC / LOCAL. [0] This would also be introduction to multiple statements - I would show this with one statement per line and multiple statements per line and discuss pros/cons