Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coding Styles
#22
Code: (Select All)
IF Left$(user$,5) = "Steve" Then

    ...do stuff

    GOTO end_check

END IF



IF Left$(user$,4) = "Jack" Then

    ...do stuff

    GOTO end_check

END IF



IF Left$(user$,2) = "Jo" Then

    ...do stuff

    GOTO end_check

END IF



...57 more unique cases to check and deal with...



end_check:

Instead of GOTO, I use a 'Faux Loop' for similar situations.

Code: (Select All)
 DO ' Faux Loop.
IF Left$(user$,5) = "Steve" Then
    ...do stuff
    GOSUB end_check
    EXIT DO
END IF
IF Left$(user$,4) = "Jack" Then
    ...do stuff
    GOSUB end_check
    EXIT DO
END IF
IF Left$(user$,2) = "Jo" Then
    ...do stuff
    GOSUB end_check
    EXIT DO
END IF
...57 more unique cases to check and deal with...
LOOP
END
end_check:
PRINT "We're done here."
RETURN

So 60 extra 'EXIT DO' statements, but copy/paste makes that a snap. 

This is more about style than optimization but I would have to ask myself, hmm 60 times, screw it, I'll use GOTO once in the code. I mean imagine if that WASN'T an option. That would suck. This it what I love about BASIC, little regulation and lots of options.

My dislike of using GOTO comes from my early Texas Instrument programming days when we needed to assign line numbers to every line of code. Change the line numbers when editing the code and it often blew up all the GOTO references, which then meticulously needed to be changed, as well. I'd also have to say GOTO statements were the #1 cause of spaghetti coding.

The few times I have used GOTO is in some very long routine where I want to circle back to something that just couldn't be done in a nested or recursive subroutine or if making my DO:LOOP nest meant many exits for parts of the routine that had nothing to do with what was coming down the pike. These types of situations put the spaghetti on the other foot!

-------------------

Like OldMoses, and I do like OldMoses, I also always use RESTORE and a label with all of my database calls. That really helps prevent database errors.

-------------------

JRace has a good point with combining math functions. I like the way doing that frees up space so I can see the next thing my code is doing, rather than jut all the calculations I know it needs to do.  I just, again, wish we had a COLOR LABELS option in the IDE. That would be way cool! Right now I'm doing a colon search... oh wait, that doesn't sound good... to find my labels.

Pete
Shoot first and shoot people who ask questions, later.
Reply


Messages In This Thread
Coding Styles - by Pete - 08-09-2024, 03:09 PM
RE: Coding Styles - by SpriggsySpriggs - 08-09-2024, 03:21 PM
RE: Coding Styles - by TerryRitchie - 08-09-2024, 05:29 PM
RE: Coding Styles - by Pete - 08-09-2024, 03:54 PM
RE: Coding Styles - by bplus - 08-09-2024, 04:03 PM
RE: Coding Styles - by SMcNeill - 08-09-2024, 09:03 PM
RE: Coding Styles - by Pete - 08-09-2024, 04:16 PM
RE: Coding Styles - by SpriggsySpriggs - 08-09-2024, 06:40 PM
RE: Coding Styles - by TerryRitchie - 08-09-2024, 07:52 PM
RE: Coding Styles - by Jack - 08-09-2024, 07:10 PM
RE: Coding Styles - by Jack - 08-09-2024, 07:19 PM
RE: Coding Styles - by Kernelpanic - 08-09-2024, 10:29 PM
RE: Coding Styles - by CharlieJV - 08-09-2024, 10:56 PM
RE: Coding Styles - by Kernelpanic - 08-09-2024, 11:21 PM
RE: Coding Styles - by CharlieJV - 08-09-2024, 11:27 PM
RE: Coding Styles - by Pete - 08-10-2024, 03:46 AM
RE: Coding Styles - by SMcNeill - 08-10-2024, 04:55 AM
RE: Coding Styles - by JRace - 08-10-2024, 09:41 AM
RE: Coding Styles - by SMcNeill - 08-10-2024, 10:43 AM
RE: Coding Styles - by OldMoses - 08-10-2024, 12:08 PM
RE: Coding Styles - by CharlieJV - 08-10-2024, 02:11 PM
RE: Coding Styles - by Pete - 08-10-2024, 02:55 PM
RE: Coding Styles - by bplus - 08-10-2024, 03:19 PM
RE: Coding Styles - by SMcNeill - 08-10-2024, 03:41 PM
RE: Coding Styles - by Pete - 08-10-2024, 04:28 PM
RE: Coding Styles - by SMcNeill - 08-10-2024, 11:08 PM
RE: Coding Styles - by Kernelpanic - 08-10-2024, 06:00 PM
RE: Coding Styles - by Pete - 08-10-2024, 07:30 PM
RE: Coding Styles - by TerryRitchie - 08-10-2024, 07:53 PM
RE: Coding Styles - by TempodiBasic - 08-11-2024, 12:46 PM
RE: Coding Styles - by Pete - 08-11-2024, 06:45 PM
RE: Coding Styles - by Kernelpanic - 08-19-2024, 06:35 PM
RE: Coding Styles - by quickbasic - 09-04-2024, 06:09 PM
RE: Coding Styles - by dano - 09-09-2024, 12:46 AM



Users browsing this thread: 2 Guest(s)