Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #24823

Re: Request for comments on a first forth program

Newsgroups comp.lang.forth
Date 2013-07-27 20:16 -0700
References (5 earlier) <f2ba9703-0fec-42bf-a25a-d56ab5cc089d@googlegroups.com> <87fvv3c9xt.fsf@pestilenz.org> <912b40eb-9435-4b53-a32f-3fd868fdedad@googlegroups.com> <877ggddbb7.fsf@pestilenz.org> <rKmdnecYscprum_MnZ2dnUVZ_rydnZ2d@supernews.com>
Message-ID <dd0b840e-962d-4e42-89bd-69aab331fb52@googlegroups.com> (permalink)
Subject Re: Request for comments on a first forth program
From hughaguilar96@yahoo.com

Show all headers | View raw


On Friday, July 26, 2013 12:40:37 AM UTC-7, Elizabeth D. Rather wrote:
> On 7/25/13 9:34 PM, Christian Kellermann wrote:
> > hughaguilar96@yahoo.com writes:
> > Ok, I am still a bit confused about this though. How does INIT differ
> > from RESET-GAME and/or INIT-PLAYER which sets these? Arguably #robots
> > only gets reset in RUN but this has been quite convenient when testing…
> 
> Your init words were fine. Hugh probably didn't read far enough to see them.

You are duplicating code. What if your boss walks into your office and says: "Using my brilliant leadership skills, I have determined that the game should allow 4 teleports rather than 3." --- now you have to make the change in two places rather than just one.

It is best to have one word, call it whatever you want, that initializes everything to a known configuration.

Anyway, like I said, this is a minor point.

> >> I still think that the
> >> best way to simplify your program is like this:
> 
> >> 1.) Use structs to reduce the amount of data that you have on the
> >> stack. For example, a struct for a point that contains X and Y
> >> coordinates, rather than putting the X and Y data directly on the
> >> stack.
> 
> >> 2.) Use an array definer. You currently implement several arrays
> >> manually, which tends to clutter up your source-code. You don't want
> >> low-level code, such as array access, intermingled with your
> >> application code --- factoring out the low-level code helps make your
> >> application code shorter and easier to read.
> 
> > For larger code bases this may be true but I think this is
> > overdoing it for this little program. Also while a REQUIRE or INCLUDE
> > from a library makes this program shorter to read it becomes more
> > difficult to understand as I would have to read the included source code
> > part first, as people already had to do with the RANDOM word I used.
> 
> > In general I tend to agree though, abstraction is good…
> 
> I agree with you. This is a simple program, and only needs simple data 
> structures.

What is good for large programs is also good for small programs. With small programs you can fudge it and still get your program to work, but if you make a habit of this, you will plateau at a fairly basic level and never graduate to writing large programs. Also, remember the maxim that I quoted previously: "Large programs that work started out as small programs that worked." Most large programs started out as small programs and then they evolved from there, but this only works if the small programs were written using the same good practices that are required for large programs. 

Also, I'm recommending that you use structs and array-definers. These are simple data-structures. 

Even if I was recommending that you use associations or something else complicated, if that were the appropriate data-structure, then you should use it --- the complication is under the hood, so using it doesn't complicate your program at all. My associations are pretty complicated internally, but the interface is quite simple (only slightly more complicated than the interface to the linked lists, as there are a few more features).

> >> If you don't yet know how to implement structs or arrays, or definer
> >> words in general, then you can use what I have provided in the novice
> >> package. The point of the novice package is to allow people to get
> >> started on writing programs, without requiring them to first implement
> >> a lot of low-level support code. Later on you will likely develop your
> >> own package of low-level code, but that is not something that you want
> >> to get bogged down in right now.
> 
> > …but I like to implement my own abstractions which I fully know and
> > understand. To abstract things you first have to know the inner workings
> > then you can forget about them for a while. But I guess know I am
> > preaching to the choir.
> 
> Very good practice.

That would be a very good practice, if he had actually done it. LOL

Don't get bogged down in implementing low-level support code like this when you are just starting out. First, get your feet wet by writing application programs. The purpose of the novice package is to let you do this. You can work your way up from simple programs like this to pretty large programs, just using the novice package. Later on, when you have some experience, then you can write your own package comparable to the novice package --- but you aren't going to be able to write code comparable to the novice package without several years of experience --- so don't rush it.

Note that Elizabeth Rather and the entire Forth Inc. staff have NEVER written anything comparable to the novice package. None of those books from Forth Inc. mention structs at all, and structs are pretty basic. If you spend upwards of $500 on SwiftForth, you don't get any support for writing applications --- you are still exactly where you are right now, wondering how to abstract out data-structures --- or, worse, ignoring the problem and just manually coding this low-level stuff (arrays!) inside of your application programs, as you did in this robot-game program.

Just to get an idea of how badly you have painted yourself into a corner, try this exercise: upgrade the program so that the size of the datum stored in the arrays is different from what it is now (add a color datum associated with each board position). Or upgrade it so there are more than one kind of robot that behave differently (some that actively chase you, and some that wander around aimlessly). Or upgrade it so there are more than one kind of hole (some shallow, so the robot can climb out in a few clock ticks). Because you have hard-wired so much information into your code, minor upgrades such as this will be horrendous to implement --- this is a small program that will NEVER evolve into a large program! 

As a second exercise, rewrite the program from scratch the way that I have described --- then pretend that your boss has walked into your office and demanded the upgrades described above, which you had not expected --- you will see that the upgrades are much easier to implement when the foundation is solid.

The world is full of bad Forth programmers --- don't be one of them! --- get into the habit of writing EVERY program in a professional manner, whether it is small or large. :-)

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Request for comments on a first forth program Christian Kellermann <ckeen@pestilenz.org> - 2013-07-19 11:39 +0200
  Re: Request for comments on a first forth program Ron Aaron <rambamist@gmail.com> - 2013-07-19 13:04 +0300
    Re: Request for comments on a first forth program rickman <gnuarm@gmail.com> - 2013-07-19 12:43 -0400
  Re: Request for comments on a first forth program Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-19 05:28 -0500
  Re: Request for comments on a first forth program m.a.m.hendrix@tue.nl - 2013-07-19 03:56 -0700
    Re: Request for comments on a first forth program m.a.m.hendrix@tue.nl - 2013-07-19 04:00 -0700
    Re: Request for comments on a first forth program rickman <gnuarm@gmail.com> - 2013-07-19 12:51 -0400
      Re: Request for comments on a first forth program Christian Kellermann <ckeen@necronomicon.my.domain> - 2013-07-20 21:28 +0200
        Re: Request for comments on a first forth program anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-22 15:43 +0000
          Re: Request for comments on a first forth program hughaguilar96@yahoo.com - 2013-07-24 20:00 -0700
            Re: Request for comments on a first forth program Christian Kellermann <ckeen@pestilenz.org> - 2013-07-25 10:37 +0200
              Re: Request for comments on a first forth program hughaguilar96@yahoo.com - 2013-07-26 00:00 -0700
                Re: Request for comments on a first forth program Christian Kellermann <ckeen@pestilenz.org> - 2013-07-26 09:34 +0200
                Re: Request for comments on a first forth program "Elizabeth D. Rather" <erather@forth.com> - 2013-07-25 21:40 -1000
                Re: Request for comments on a first forth program hughaguilar96@yahoo.com - 2013-07-27 20:16 -0700
                Re: Request for comments on a first forth program Christian Kellermann <ckeen@pestilenz.org> - 2013-07-29 10:09 +0200
                Re: Request for comments on a first forth program m.a.m.hendrix@tue.nl - 2013-07-29 04:14 -0700
                Re: Request for comments on a first forth program Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-29 07:49 -0500
                Re: Request for comments on a first forth program "Elizabeth D. Rather" <erather@forth.com> - 2013-07-29 15:32 -1000
                Re: Request for comments on a first forth program hughaguilar96@yahoo.com - 2013-07-31 17:50 -0700
                Re: Request for comments on a first forth program Christian Kellermann <ckeen@pestilenz.org> - 2013-07-31 13:23 +0200
                Re: Request for comments on a first forth program hughaguilar96@yahoo.com - 2013-07-31 18:05 -0700
                Re: Request for comments on a first forth program Christian Kellermann <ckeen@pestilenz.org> - 2013-08-01 12:53 +0200
                Re: Request for comments on a first forth program "Elizabeth D. Rather" <erather@forth.com> - 2013-08-01 09:58 -0500
                Re: Request for comments on a first forth program hughaguilar96@yahoo.com - 2013-08-01 20:42 -0700
                Re: Request for comments on a first forth program Brad Eckert <hwfwguy@gmail.com> - 2013-08-04 18:53 -0700
                Re: Request for comments on a first forth program "Elizabeth D. Rather" <erather@forth.com> - 2013-08-04 22:05 -0500
                Re: Request for comments on a first forth program hughaguilar96@yahoo.com - 2013-08-04 20:54 -0700
                Re: Request for comments on a first forth program hughaguilar96@yahoo.com - 2013-08-17 17:06 -0700
                Re: Request for comments on a first forth program Alex McDonald <blog@rivadpm.com> - 2013-08-05 05:50 -0700
                Re: Request for comments on a first forth program hughaguilar96@yahoo.com - 2013-08-17 17:45 -0700
                Re: Request for comments on a first forth program Christian Kellermann <ckeen@pestilenz.org> - 2013-08-05 22:14 +0200
                Re: Request for comments on a first forth program hughaguilar96@yahoo.com - 2013-08-06 21:11 -0700
                Re: Request for comments on a first forth program "Elizabeth D. Rather" <erather@forth.com> - 2013-08-01 01:04 -0500
    Re: Request for comments on a first forth program albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-19 18:06 +0000
      Re: Request for comments on a first forth program Christian Kellermann <ckeen@necronomicon.my.domain> - 2013-07-20 21:31 +0200
    Re: Request for comments on a first forth program Christian Kellermann <ckeen@necronomicon.my.domain> - 2013-07-20 21:24 +0200
      Re: Request for comments on a first forth program anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-22 15:32 +0000
  Re: Request for comments on a first forth program Alex McDonald <blog@rivadpm.com> - 2013-07-19 06:49 -0700
    Re: Request for comments on a first forth program Christian Kellermann <ckeen@necronomicon.my.domain> - 2013-07-20 21:34 +0200
  Re: Request for comments on a first forth program Mark Wills <markrobertwills@yahoo.co.uk> - 2013-07-19 07:19 -0700
    Re: Request for comments on a first forth program Christian Kellermann <ckeen@necronomicon.my.domain> - 2013-07-20 21:41 +0200
  Re: Request for comments on a first forth program "Elizabeth D. Rather" <erather@forth.com> - 2013-07-19 07:55 -1000
    Re: Request for comments on a first forth program Christian Kellermann <ckeen@necronomicon.my.domain> - 2013-07-20 21:47 +0200
      Re: Request for comments on a first forth program "Elizabeth D. Rather" <erather@forth.com> - 2013-07-20 11:15 -1000
    Re: Request for comments on a first forth program hughaguilar96@yahoo.com - 2013-07-20 20:09 -0700
  Re: Request for comments on a first forth program "Paul E. Bennett" <Paul_E.Bennett@topmail.co.uk> - 2013-07-19 19:36 +0100
    Re: Request for comments on a first forth program albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-20 12:36 +0000
      Re: Request for comments on a first forth program Christian Kellermann <ckeen@necronomicon.my.domain> - 2013-07-20 21:53 +0200
      Re: Request for comments on a first forth program Coos Haak <chforth@hccnet.nl> - 2013-07-21 02:02 +0200
        Re: Request for comments on a first forth program "Elizabeth D. Rather" <erather@forth.com> - 2013-07-20 17:18 -1000
      Re: Request for comments on a first forth program Ian Osgood <iano@quirkster.com> - 2013-07-23 16:07 -0700
    Re: Request for comments on a first forth program Christian Kellermann <ckeen@necronomicon.my.domain> - 2013-07-20 21:48 +0200
  Re: Request for comments on a first forth program stephenXXX@mpeforth.com (Stephen Pelc) - 2013-07-20 12:18 +0000
    Re: Request for comments on a first forth program Christian Kellermann <ckeen@necronomicon.my.domain> - 2013-07-20 21:57 +0200
      Re: Request for comments on a first forth program "Elizabeth D. Rather" <erather@forth.com> - 2013-07-20 11:24 -1000
    Re: Request for comments on a first forth program Christian Kellermann <ckeen@pestilenz.org> - 2013-07-22 15:53 +0200
      Re: Request for comments on a first forth program m.a.m.hendrix@tue.nl - 2013-07-22 08:06 -0700
        Re: Request for comments on a first forth program albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-22 19:35 +0000
          Re: Request for comments on a first forth program m.a.m.hendrix@tue.nl - 2013-07-23 00:41 -0700
          Re: Request for comments on a first forth program Christian Kellermann <ckeen@pestilenz.org> - 2013-07-23 12:00 +0200
            Re: Request for comments on a first forth program albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-23 12:10 +0000
              Re: Request for comments on a first forth program Christian Kellermann <ckeen@pestilenz.org> - 2013-07-23 14:19 +0200
              Re: Request for comments on a first forth program stephenXXX@mpeforth.com (Stephen Pelc) - 2013-07-24 09:27 +0000
            Re: Request for comments on a first forth program anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-23 13:44 +0000
  Re: Request for comments on a first forth program hughaguilar96@yahoo.com - 2013-07-20 20:02 -0700
    Re: Request for comments on a first forth program albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-21 03:36 +0000
      Re: Request for comments on a first forth program hughaguilar96@yahoo.com - 2013-07-20 22:28 -0700
        Re: Request for comments on a first forth program albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-21 10:31 +0000
    Re: Request for comments on a first forth program rickman <gnuarm@gmail.com> - 2013-07-20 23:41 -0400
  Re: Request for comments on a first forth program anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-22 15:36 +0000
  Re: Request for comments on a first forth program Lars Brinkhoff <lars.spam@nocrew.org> - 2013-07-23 12:22 +0200
    Re: Request for comments on a first forth program Christian Kellermann <ckeen@pestilenz.org> - 2013-07-23 13:44 +0200
      Re: Request for comments on a first forth program albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-23 12:26 +0000
    Re: Request for comments on a first forth program "Elizabeth D. Rather" <erather@forth.com> - 2013-07-23 07:10 -1000
    Re: Request for comments on a first forth program stephenXXX@mpeforth.com (Stephen Pelc) - 2013-07-24 09:30 +0000

csiph-web