Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SELECT CASE, or something
#41
I come from Spaghetti realms as well, I coded in my ZX Spectrum from 1988 to 1993. I can read Aga's code as well and I think he's one of the best coders here, as well. But I could change my mind and benefit from the advantages that procedural approaches have over line_numbers-GOTO'ed-GOSUB'ed-non_block_IF'ed-etc approaches Tongue

This is code from a ZX Spectrum game I was coding this summer: this moves the enemies Tongue

Code:
2000 REM selectGFX
2010 LET aa=PEEK (dir+6): GO SUB 930
2015 IF PEEK (dir+7)=0 THEN GO TO 2050: REM left
2025 IF PEEK (dir+4)=1 THEN GO TO 2040
2030 IF p THEN LET f$="./": GO TO 2032
2031 LET f$="01"
2032 LET e$=",-": RETURN
2040 IF p THEN LET f$=":;": GO TO 2042
2041 LET f$="<="
2042 LET e$="89": RETURN
2050 IF PEEK (dir+4)=1 THEN GO TO 2070
2060 IF p THEN LET f$="45": GO TO 2062
2061 LET f$="67"
2062 LET e$="23": RETURN
2070 IF p THEN LET f$="@A": GO TO 2072
2071 LET f$="BC"
2072 LET e$=">?": RETURN
2100 REM ENEMIGOS-MOVER
2110 FOR i=1  TO 2
2111 LET dir=benem+16*px+80*py+(i-1)*8
2120 GO SUB 2000: REM selectGFX
2132 LET old=PEEK (dir+6)
2140 POKE dir+6,PEEK (dir+6)+PEEK (dir+7)-1
2150 IF PEEK (dir+6)=PEEK (dir+1)  OR PEEK (dir+6)=PEEK (dir+2)  THEN POKE dir+7, 1-(PEEK (dir+7)-1)
2155 IF PEEK dir  THEN GO TO 2200
2157 REM HORIZONTAL
2160 IF old<PEEK (dir+6)  THEN PRINT PAPER ps;  INK is;AT PEEK (dir+3)-1,PEEK (dir+6)-1;"a"; INK PEEK (dir+5);e$;AT PEEK (dir+3),PEEK (dir+6)-1; INK is;"a"; INK PEEK (dir+5);f$: GO TO 2180
2170 PRINT PAPER ps;  INK PEEK (dir+5);AT PEEK (dir+3)-1,PEEK (dir+6);e$; INK is;"a"; INK PEEK (dir+5);AT PEEK (dir+3),PEEK (dir+6);f$; INK is;"a"
2180 IF PEEK (dir+6)>=a-1 AND PEEK (dir+6)<=a+1 AND PEEK (dir+3)>=w-1 AND PEEK (dir+3)<=w+1 THEN LET vi=vi-1: GO SUB 701
2181 GO TO 2300
2200 REM VERTICAL
2210 IF old<PEEK (dir+6)  THEN PRINT PAPER ps;AT PEEK (dir+6)-2,PEEK (dir+3); INK is;"aa"; INK PEEK (dir+5);AT PEEK (dir+6)-1,PEEK (dir+3);e$;AT PEEK (dir+6),PEEK (dir+3);f$: GO TO 2230
2220 PRINT PAPER ps;AT PEEK (dir+6)+1,PEEK (dir+3); INK is;"aa"; INK PEEK (dir+5);AT PEEK (dir+6)-1,PEEK (dir+3);e$;AT PEEK (dir+6),PEEK (dir+3);f$
2230 IF PEEK (dir+6)>=w-1 AND PEEK (dir+6)<=w+1 AND PEEK (dir+3)>=a-1 AND PEEK (dir+3)<=a+1 THEN LET vi=vi-1: GO SUB 701
2300 NEXT i
2301 RETURN

That's Spaghetti, kiddo Big Grin

It's better to go procedural/structured 'cause it is easier to understand other languages, not just BASIC.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#42
Nath that may be spagetti code for you but i've seen such code in most of the older books published around in the 70s and 80s. Just because we have more structured languages now doesnt mean that the code in the older languages is spagetti =).
Reply
#43
Quote:But it has nothing to do with the Stack. It may be ugly and unreadable, but it ain't unefficient or dangerous.
I wasn't talking about the stack or the ASM clone of the code Tongue It's just unreadable to humans but for the computer, in ASM it is all the same, some jmps to a specified address, both with loops (DO, FOR, WHILE) and GOTOs.
Reply
#44
Quote:Nath that may be spagetti code for you but i've seen such code in most of the older books published around in the 70s and 80s. Just because we have more structured languages now doesnt mean that the code in the older languages is spagetti =).

That depends on what you call spaghetti code. I call it "spaghetti code" when the code looks like a plate of spaghetti: You follow a "run path" and it goes to line 10, keeps on to line 110, then it GOTOs to line 20, then it GOTOs to line 2000, having GOSUBed to line 6500... Like a plate of spaghetti, where every spaghetto is twisted, tied, and goes around other spaghetti. That's the metaphor I think the therm is based on Tongue

Therefore ol' 8 bits dialects of BASIC are spaghetti makers Tongue

Neo: I was replying to this concrete phrase:

Quote:GOTO: Spaghetti code (sometimes causing stack error as well)

You said that GOTO "sometimes causes stack error as well", but that will never happen as GOTOs doesn't touch the stack.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)