Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coding Efficiency
#8
Since this is a topic on Coding Efficiency, I want to take a moment to point out how foolish it is to listen to anything Pete might say on such a subject.  After all, as he's illustrated countless times before, he STILL uses Inkey$ in his programs.   

Hahahahahahahaha!!    (Don't worry.  If any else of you do, I'm not laughing at you.  I just laugh at Pete. Tongue )

Let me take a moment to explain:

INKEY$ and _KEYHIT are the *exact*, 100% identical, no kidding, gosh darn same command -- with one *minute* difference:  one returns a string value, the other returns the ASCII numeric value of that string.

Inkey$ says "A", _KEYHIT says 65.
Inkey$ says CHR$(0) + CHR$(79), _KEYHIT says 19200.   <-- this is the exact same value if yo MKI$ or _CVI the values.

Keyhit simply returns the numeric value of Inkey$.   That's the only difference in the two commands.

BUT, it's inherently faster for several reasons:

1) Numbers are always faster than strings.  Strings come with overhead numbers just don't have.
2) When it comes to extended keypresses, there's a LOT less to process than with Inkey$.   
      IF User_Input = 19200 THEN.....
      IF User_Input$ = CHR$(0) + CHR$(79) THEN....

Compare the two IF statements above.  Take just a moment to analyze them in your head.  Which is OBVIOUSLY more efficient?
   IF number = number....   <--- single comparison of 2 numbers.  This isn't going to take long
   IF string = CHR$ function conversion of number to string, added to, CHR$ function conversion of number to string...

Umm...   I'm smart like Pete!  Me thinks the second method is better!  Me likes bananas and pew pew pistols and me brain is smaller than me hat!   Tongue

Pete's example code: 
Code: (Select All)
Do
    _Limit 30
    b$ = InKey$
    Select Case UCase$(b$)
        Case "A" To "Z"
            Print LTrim$(Str$(Asc(UCase$(b$)) - 64))
    End Select
Loop Until b$ = Chr$(27)

And Steve's exact same code:
Code: (Select All)
Do
    _Limit 30
    b = _KeyHit
    Select Case b And Not 32
        Case 27: System
        Case 65 To 90: Print _Trim$(Str$((b And Not 32) - 64))
    End Select
Loop

No UCASE$ needed -- the AND NOT 32 takes care of that.  No ASC conversion needed.  No string overhead.  Just nice efficient code.

Unlike Pete's.   Big Grin
Reply


Messages In This Thread
Coding Efficiency - by SMcNeill - 08-11-2024, 12:16 AM
RE: Coding Efficiency - by TerryRitchie - 08-11-2024, 01:21 AM
RE: Coding Efficiency - by SMcNeill - 08-11-2024, 03:25 AM
RE: Coding Efficiency - by CharlieJV - 08-11-2024, 01:29 AM
RE: Coding Efficiency - by Pete - 08-11-2024, 07:22 PM
RE: Coding Efficiency - by Dimster - 08-12-2024, 06:34 PM
RE: Coding Efficiency - by Pete - 08-13-2024, 09:46 PM
RE: Coding Efficiency - by SMcNeill - 08-13-2024, 11:11 PM
RE: Coding Efficiency - by Pete - 08-13-2024, 11:23 PM
RE: Coding Efficiency - by SMcNeill - 08-13-2024, 11:28 PM
RE: Coding Efficiency - by TerryRitchie - 08-14-2024, 01:21 AM
RE: Coding Efficiency - by Pete - 08-13-2024, 11:53 PM
RE: Coding Efficiency - by Pete - 08-14-2024, 03:38 PM
RE: Coding Efficiency - by SMcNeill - 08-14-2024, 04:26 PM
RE: Coding Efficiency - by mdijkens - 08-15-2024, 11:29 AM
RE: Coding Efficiency - by Pete - 08-15-2024, 03:20 PM
RE: Coding Efficiency - by Kernelpanic - 08-15-2024, 05:57 PM
RE: Coding Efficiency - by justsomeguy - 08-15-2024, 06:06 PM
RE: Coding Efficiency - by TerryRitchie - 08-16-2024, 03:21 AM
RE: Coding Efficiency - by justsomeguy - 08-16-2024, 07:09 AM
RE: Coding Efficiency - by Pete - 08-15-2024, 11:14 PM
RE: Coding Efficiency - by dano - 08-16-2024, 12:33 AM
RE: Coding Efficiency - by Pete - 08-16-2024, 12:35 AM
RE: Coding Efficiency - by SMcNeill - 09-11-2024, 01:55 AM
RE: Coding Efficiency - by Pete - 09-11-2024, 06:45 AM
RE: Coding Efficiency - by SMcNeill - 09-11-2024, 07:59 AM
RE: Coding Efficiency - by bplus - 09-11-2024, 01:51 PM
RE: Coding Efficiency - by SMcNeill - 09-11-2024, 02:01 PM
RE: Coding Efficiency - by bplus - 09-11-2024, 02:39 PM
RE: Coding Efficiency - by Pete - 09-11-2024, 02:48 PM
RE: Coding Efficiency - by dano - 09-12-2024, 01:41 PM
RE: Coding Efficiency - by Jack - 09-12-2024, 04:01 PM
RE: Coding Efficiency - by Kernelpanic - 09-12-2024, 08:13 PM
RE: Coding Efficiency - by Pete - 09-13-2024, 06:56 PM



Users browsing this thread: 27 Guest(s)