[net.unix] DON'T EVER DO THIS!!!

ignatz@aicchi.UUCP (Ihnat) (08/01/85)

I won't mention what program this comes from; it's been posted to the
net, and (functionally) is quite interesting and enjoyable.  BUT--it
mysteriously broke the 'C' compiler on an Altos 586 running Xenix 3.0b,
and when I looked at it---well, you take a look.  DON'T *EVER* DO THIS!!
		 .
		 .
		 .
        while (--count &&

               (!(rand_mod(prob)) ||

                (obj = occupant[y=(curkl->posy+curkl->vely+YSIZE00)%YSIZE]

                               [x=(curkl->posx+curkl->velx+XSIZE00)%XSIZE]) &&

                (obj->type == Star ||

                 ((rand_mod(100) <= smarts) &&

                  !obj->vely && !obj->velx &&

                  (obj->image == 'o' ||

                   obj->image == 'O' ||

                   obj->image == 'X'

                  )

                 ) ||

                 (obj->type == Web &&

                  (curkl->image != 'T' ||

                   (count > 5 && obj->image ==

                    (curkl->vely?

                     (curkl->velx?

                      (curkl->velx==curkl->vely?

                       '\\'

                      :

                       '/'

                      )

                     :

                      '|'

                     )

                    :

                     '-'

                    )

                   )

                  )

                 )

                )

               )

              ) {

            if (massacre && curkl->image != 'T') {

                curkl->vely = rand_mod(7) - 3;

                curkl->velx = rand_mod(7) - 3;

            }

            else if (curkl->energy >= 2500 && curkl->image != 'T') {

                curkl->vely = rand_mod(5) - 2;

                curkl->velx = rand_mod(5) - 2;

            }

            else {

                curkl->vely = rand_mod(3) - 1;

                curkl->velx = rand_mod(3) - 1;

            }

        }

================================> *WHEW!* <==============================

freeman@spar.UUCP (Jay Freeman) (08/02/85)

[]

In article <536@aicchi.UUCP> ignatz@aicchi.UUCP (Ihnat) writes:

> [ ... ]  DON'T *EVER* DO THIS!!
>	 .
>	 .
>	 .
>     while (--count &&
>            (!(rand_mod(prob)) ||
>             (obj = occupant[y=(curkl->posy+curkl->vely+YSIZE00)%YSIZE]
>                            [x=(curkl->posx+curkl->velx+XSIZE00)%XSIZE]) && 
> [ ... ]

This all looks obvious to me ... except ... in the first line of code ...
I can never remember what the "--" operator is supposed to do ...  :-)
-- 
Jay Reynolds Freeman (Schlumberger Palo Alto Research)(canonical disclaimer)

lwall@sdcrdcf.UUCP (Larry Wall) (08/07/85)

[Warning: long quote--hit TAB in rn if not interested]

In article <536@aicchi.UUCP> ignatz@aicchi.UUCP (Ihnat) writes:
>I won't mention what program this comes from; it's been posted to the
>net, and (functionally) is quite interesting and enjoyable.  BUT--it
>mysteriously broke the 'C' compiler on an Altos 586 running Xenix 3.0b,
>and when I looked at it---well, you take a look.  DON'T *EVER* DO THIS!!
>		 .
>		 .
>		 .
>        while (--count &&
>               (!(rand_mod(prob)) ||
>                (obj = occupant[y=(curkl->posy+curkl->vely+YSIZE00)%YSIZE]
>                               [x=(curkl->posx+curkl->velx+XSIZE00)%XSIZE]) &&
>                (obj->type == Star ||
>                 ((rand_mod(100) <= smarts) &&
>                  !obj->vely && !obj->velx &&
>                  (obj->image == 'o' ||
>                   obj->image == 'O' ||
>                   obj->image == 'X'
>                  )
>                 ) ||
>                 (obj->type == Web &&
>                  (curkl->image != 'T' ||
>                   (count > 5 && obj->image ==
>                    (curkl->vely?
>                     (curkl->velx?
>                      (curkl->velx==curkl->vely?
>                       '\\'
>                      :
>                       '/'
>                      )
>                     :
>                      '|'
>                     )
>                    :
>                     '-'
>                    )
>                   )
>                  )
>                 )
>                )
>               )
>              ) {
>            if (massacre && curkl->image != 'T') {
>                curkl->vely = rand_mod(7) - 3;
>                curkl->velx = rand_mod(7) - 3;
>            }
>            else if (curkl->energy >= 2500 && curkl->image != 'T') {
>                curkl->vely = rand_mod(5) - 2;
>                curkl->velx = rand_mod(5) - 2;
>            }
>            else {
>                curkl->vely = rand_mod(3) - 1;
>                curkl->velx = rand_mod(3) - 1;
>            }
>        }
>================================> *WHEW!* <==============================

Me, oh, my.  My little skeleton in the closet has come marching out.  Blush.
Dave wouldn't say the name of the program, bless his heart, but they do say
confession is good for the soul.  The name of that program is warp, one of
my earlier efforts.  The earliest versions of warp were in, shudder, BASIC.
(Well, BASIC+, actually.)  C was such a breath of fresh air--I guess I went
wild or something...

The above doesn't look nearly so bad in pseudo-code:

	while (it's reasonable to think about changing enemy velocities)
		change enemy velocities;

Back when the only kind of enemies were Klingons, the thing was much simpler.
Then we added Romulans, Gorns, Tholians, planet munchers, web, Apollo,
homing and proximity torpedoes, difficulty levels, massacre mode, etc, and
it got a wee bit more complicated.  A brilliant example of stepwise
refinement, in fact.  :-)

One of these days when you guys stop pestering me about rn, I'll add the
Space Amoeba, unless warp turns into a Space Amoeba of its own accord...
Maybe I can retrofit a bit of wisdom into it at the same time.

Yah, don't *ever* do that.  (But if you do, have fun!)

Larry Wall
{allegra,burdvax,cbosgd,hplabs,ihnp4,sdcsvax}!sdcrdcf!lwall