Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"5-line" engine
#17
Here's something to showcase why we should stay away from these line conjoinment programs:

Code: (Select All)
Screen _NewImage(80, 45, 0)
_FullScreen
_ControlChr Off
'_PrintString (1, 1), String$(3280, 219)  'unneeded as the screen is blank to begin with
'dx = 40                                  'unneeded as it's set inside the DO LOOP
'dy = 20                                  'as above
Randomize Timer
's = Int(200 + Rnd * (100 * (1 + Rnd * 4))) 'why use a line for this?
For d = 1 To Int(200 + Rnd * (100 * (1 + Rnd * 4))) 's can just be used here directly.
    m$ = m$ + Chr$(49 + Int(Rnd * 4))
Next d
px = 40
py = 20
'stand = 0  'no need for this, there's no usage of stand in the whole program
Do
    dx = 40
    dy = 20
    Color 7
    _PrintString (1, 1), String$(3280, 219)
    For c = 1 To Len(m$)
        _PrintString (dx, dy), "."
        Select Case Mid$(m$, c, 1)
            Case "1": dy = dy - 1
            Case "2": dx = dx + 1
            Case "3": dy = dy + 1
            Case "4": dx = dx - 1
        End Select
        'Select Case dy        '  all these lines can be consolodated into one simple IF
        '    Case 40, 1: dy = 20: dx = 40
        'End Select
        'Select Case dx
        '    Case 80, 1: dy = 20: dx = 40
        'End Select
        If dy = 40 Or dy = 1 Or dx = 80 Or dx = 1 Then dy = 20: dx = 40
    Next c
    Color 15
    _PrintString (px, py), Chr$(2)
    'Do
    '    _Limit 40
    '    kk$ = InKey$
    'Loop Until kk$ <> "": kk$ = UCase$(kk$)
    kk$ = UCase$(Input$(1))
    pxm = 0
    pym = 0
    Select Case kk$
        Case "W": pym = -1
        Case "S": pym = 1
        Case "D": pxm = 1
        Case "A": pxm = -1
    End Select
    'Select Case Screen(pym + py, pxm + px, 0) 'three lines easily consolodates down to a single line
    '    Case 219: pxm = 0: pym = 0
    'End Select
    If Screen(pym + py, pxm + px, 0) = 219 Then pxm = 0: pym = 0
    px = px + pxm
    py = py + pym
Loop Until kk$ = Chr$(27)

Now, this is the exact same program as the original, though it's been spread out and expanded to make it more easily readable to humans.  By keeping it human readable, what do we see here:

1) Unneeded screen clear of a blank screen.
2) Unneeded initialization of variables dx and dy.  The DO loop does this as the very first thing.
3) Unneed use of a variable we could insert directly
4) A completely stray and unused variable.  Why hasn't someone caught and removed this already?
5) 6 lines of SELECT CASE which can be broken down to one simple IF statement
6) 4 lines of a DO..LOOP that can be easily replaced with a single line INPUT$ statement
7) 3 more lines of SELECT CASE which can be easily broken down to one simple IF statement

Why 5 lines was chosen to compress this program down into, is a mystery to me.  Why not ten?  Or three?  Or one?   

But if the goal is to reduce it to the smallest size possible, then why does it have unneeded initialization?  Unused variables?

Does this help to highlight WHY I'm not a big fan of these sort of "Cram it all on one line" programs?  Like @blpus , I'm one of those folks who like to see how short a program can get and what can be accomplished in the fewest number of lines possible.   I just dont personally feel like using colons to cram everything onto a single line really counts.

After all, I've shortened the original code here by several commands.  Yet....  If this was a contest, the original would win over this one just because....  It uses more colons??
Reply


Messages In This Thread
"5-line" engine - by James D Jarvis - 02-06-2024, 02:13 PM
RE: "5-line" engine - by SMcNeill - 02-06-2024, 02:40 PM
RE: "5-line" engine - by James D Jarvis - 02-06-2024, 05:43 PM
RE: "5-line" engine - by bplus - 02-06-2024, 06:27 PM
RE: "5-line" engine - by GareBear - 02-06-2024, 10:42 PM
RE: "5-line" engine - by JRace - 02-07-2024, 01:30 AM
RE: "5-line" engine - by MasterGy - 02-07-2024, 02:31 PM
RE: "5-line" engine - by TerryRitchie - 02-07-2024, 02:46 PM
RE: "5-line" engine - by JRace - 02-07-2024, 05:25 PM
RE: "5-line" engine - by MasterGy - 02-07-2024, 08:27 PM
RE: "5-line" engine - by GareBear - 02-08-2024, 12:00 AM
RE: "5-line" engine - by SMcNeill - 02-08-2024, 12:15 AM
RE: "5-line" engine - by JRace - 02-08-2024, 03:43 AM
RE: "5-line" engine - by GareBear - 02-08-2024, 01:27 PM
RE: "5-line" engine - by SMcNeill - 02-08-2024, 05:13 PM
RE: "5-line" engine - by MasterGy - 02-08-2024, 05:22 PM
RE: "5-line" engine - by SMcNeill - 02-08-2024, 06:03 PM
RE: "5-line" engine - by SMcNeill - 02-08-2024, 07:12 PM
RE: "5-line" engine - by MasterGy - 02-08-2024, 11:01 PM
RE: "5-line" engine - by GareBear - 02-09-2024, 02:35 PM
RE: "5-line" engine - by SMcNeill - 02-09-2024, 03:23 PM
RE: "5-line" engine - by madscijr - 02-10-2024, 12:25 AM
RE: "5-line" engine - by GareBear - 02-09-2024, 05:48 PM
RE: "5-line" engine - by bplus - 02-09-2024, 08:42 PM
RE: "5-line" engine - by MasterGy - 02-09-2024, 09:24 PM
RE: "5-line" engine - by MasterGy - 02-09-2024, 09:51 PM
RE: "5-line" engine - by SMcNeill - 02-09-2024, 10:36 PM
RE: "5-line" engine - by MasterGy - 02-09-2024, 11:55 PM
RE: "5-line" engine - by bplus - 02-10-2024, 12:04 AM
RE: "5-line" engine - by MasterGy - 02-11-2024, 01:28 AM
RE: "5-line" engine - by SMcNeill - 02-11-2024, 01:35 AM
RE: "5-line" engine - by MasterGy - 02-11-2024, 04:22 PM
RE: "5-line" engine - by johannhowitzer - 02-12-2024, 02:41 AM
RE: "5-line" engine - by James D Jarvis - 02-15-2024, 06:59 PM
RE: "5-line" engine - by Pete - 02-16-2024, 10:05 AM
RE: "5-line" engine - by Jack - 02-16-2024, 11:06 AM



Users browsing this thread: 11 Guest(s)