Author Topic: Just a Code Sample: EXIT SUB  (Read 1202 times)

0 Members and 1 Guest are viewing this topic.

Offline CharlieJV

  • Newbie
  • Posts: 89
Just a Code Sample: EXIT SUB
« on: February 13, 2022, 04:03:48 pm »
Code: QB64: [Select]
  1. declare sub EvalInput(This$)
  2. '
  3. getinput: input "enter some alphanumeric text: "; a$
  4. call EvalInput(a$)
  5. goto getinput
  6. '
  7. sub EvalInput(This$)
  8.         if len(This$) > 4 then
  9.                 print This$
  10.         else
  11.                 print "min length of 5 condition not met; hard exit"
  12.                 EXIT SUB
  13.         end if
  14.         print "processing continued to normal subroutine end"
« Last Edit: February 13, 2022, 11:29:30 pm by CharlieJV »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Just a Code Sample: EXIT SUB
« Reply #1 on: February 13, 2022, 04:18:35 pm »
This is QB64 man! You don't have to Declare Sub nor "Call" Subs. :)

The IDE doesn't even cap Declare Sub, interesting...

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
Re: Just a Code Sample: EXIT SUB
« Reply #2 on: February 13, 2022, 04:45:36 pm »
This is QB64 man! You don't have to Declare Sub nor "Call" Subs. :)

The IDE doesn't even cap Declare Sub, interesting...

That sure is a lot of liberty, but where is the justice?

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: Just a Code Sample: EXIT SUB
« Reply #3 on: February 13, 2022, 04:48:03 pm »
That sure is a lot of liberty, but where is the justice?

If the weather at your home is like mine, all you have to do is look outside.  We didn't get any snow from this last storm.  It was all just ice.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline CharlieJV

  • Newbie
  • Posts: 89
Re: Just a Code Sample: EXIT SUB
« Reply #4 on: February 13, 2022, 08:43:22 pm »
I probably should have mentioned.  Cognitive disabilities over here, so you're likely to find all kinds of strangeness in any of my code samples.

In particular, aside from general program structure: verbosity, because the visual cues are helpful "anchors", or points of reference.

Well, there is also me trying to maintain a certain degree of cross-compatibility as I try to get BASIC Anywhere Machine as reasonably possible compatible with QB64...


I'm a big fan of QB64.  For the benefit of other QB64 newbies/enthusiasts, please do point out whatever is unnecessary and/or generally bad practice for other folk.

Offline Bert22306

  • Forum Regular
  • Posts: 206
Re: Just a Code Sample: EXIT SUB
« Reply #5 on: February 13, 2022, 10:41:44 pm »
This is QB64 man! You don't have to Declare Sub nor "Call" Subs. :)

FWIW, while I agree that having to declare all subs at the top was a bloody nuisance, "Call subfoo" is, IMO, way more readable, than just naming the sub. Especially when others need to read and understand your code.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: Just a Code Sample: EXIT SUB
« Reply #6 on: February 13, 2022, 10:59:34 pm »
FWIW, while I agree that having to declare all subs at the top was a bloody nuisance, "Call subfoo" is, IMO, way more readable, than just naming the sub. Especially when others need to read and understand your code.

There was one big advantage to declaring a SUB up top: The actual Sub could then go anywhere in the code!

Declare Sub foo

CLS
PRINT "Hello";
foo
SUB foo
   COLOR 4 'Red color
END SUB
PRINT " World!"
END

The above runs just fine in QB45 and earlier, with the Declare setting the stage so the program knows references to foo are going to be addressing the Sub, letting you place it anywhere in your code after that.

Where this became especially helpful was in creating libraries, where you could then include the SUB with the declare, place it at the top of your code, and only need one $INCLUDE file.

QB64 doesn't work like this however, so our subs go into a .BM file and dims/types into a .BI, requiring us to have 2 $Include statements.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
Re: Just a Code Sample: EXIT SUB
« Reply #7 on: February 14, 2022, 10:58:19 am »
There was one big advantage to declaring a SUB up top: The actual Sub could then go anywhere in the code!

Declare Sub foo

CLS
PRINT "Hello";
foo
SUB foo
   COLOR 4 'Red color
END SUB
PRINT " World!"
END

Not exactly.
if you tried typing that in the QB45 IDE verbatim, you would receive an error;
  [ You are not allowed to view this attachment ]  
Granted after becoming radioactive I only have a half-life!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: Just a Code Sample: EXIT SUB
« Reply #8 on: February 14, 2022, 11:06:45 am »
Not exactly.
if you tried typing that in the QB45 IDE verbatim, you would receive an error;

The IDE moves SUBs to their own workspace.  Try to compile the program from the command line instead.  😉

QB45 has no issues with it, if you write the code in notepad or another editor.  It's just the IDE that's picky about separating the code.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline tomxp411

  • Newbie
  • Posts: 28
Re: Just a Code Sample: EXIT SUB
« Reply #9 on: February 14, 2022, 01:54:33 pm »
FWIW, while I agree that having to declare all subs at the top was a bloody nuisance, "Call subfoo" is, IMO, way more readable, than just naming the sub. Especially when others need to read and understand your code.

Not really. While it can be used as a signal that the following symbol is a subroutine, it's mostly a waste of space. Its only syntactic purpose is to allow a function-style syntax when a value is not being returned. ie: CALL OpenFile(filename) as opposed to OpenFile filename.

More to the point: a SUB is really a new command. From the developer's standpoint, you're literally adding a new command to the language when adding a subroutine. In fact, most languages rely on this and don't have any internal commands, other than basic flow control. In C, for example, there's not even a PRINT statement. Instead, the printf() function is a library routine and not actually part of the language itself.

If it helps you in your own work, there's nothing particularly wrong with using CALL, but if you're working with other people, you'll probably find that it's not recommended. Microsoft still includes the CALL statement, but their documentation now says to use it only in specific circumstances, such as when an identifier starts with a character that is not a letter.




Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
Re: Just a Code Sample: EXIT SUB
« Reply #10 on: February 14, 2022, 06:02:15 pm »
So everyone's getting on-board with OPTION _EXPLICIT but DECLARE is a waste of space..