Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!news-1.dfn.de!news.dfn.de!news.informatik.hu-berlin.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Paul E. Bennett" Newsgroups: comp.lang.forth Subject: Re: Request for comments on a first forth program Followup-To: comp.lang.forth Date: Fri, 19 Jul 2013 19:36:17 +0100 Organization: Hidecs Consultancy Lines: 67 Message-ID: References: <87wqomga80.fsf@pestilenz.org> Reply-To: Paul_E.Bennett@topmail.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7Bit X-Trace: individual.net XjrDpFn1WIVwJI/CzwgAdQi37clqgDqSWUYimrLLnY/XvHIuSz Cancel-Lock: sha1:qQUm3CulpU7x2HrX09OJchYJMQY= Mail-Copies-To: Paul_E.Bennett@topmail.co.uk User-Agent: KNode/0.99.01 Xref: csiph.com comp.lang.forth:24612 Christian Kellermann wrote: > Dear group readers, > > I have been re-reading my books on Forth lately and decided to get into > learning it finally. One of the first results have been attached to this > article and I would like to hear your criticism about it. (If this is a > faux pas on this list please ignore this request). > > It's a small and silly implementation of the BSD game robots. You ("@") > have to escape some robots ("R") and win by luring them into holes > ("*"). > > I have used GNU Forth to get started, mostly because I don't know any > forth system well enough (besides a little dabbling with amforth) to > judge any of the existing systems. > > Things that did surprise me: > > * Working with the stack is not hard at all > * Debugging Forth words has been easier than anticipated. I did not use > the gforth debugging facilities though. > * A bad choice of data structures is punished more heavily in forth due > to unnecessary stack juggling involved than in other programming > languages. > > What I don't like in my program: > > * The word names are probably way too verbose for forthers. Comming from > scheme I am quite accustomed to lengthy names and could not help it so > far. > * Redundant code due to my ignorance of the forth metaprogramming > facilities. I need to read up on these. > * Unclear when to use cells or bytes as an access unit for accessing > buffers. > * What's the preferred coding style for longer words? Or is this a sign > that my word is too convoluted and should be refactored? > * The access words for the values seem too verbose, are these even > necessary? Look on your first attempt as the prototype and use it to write a better specification. [%X] > : #moves+ #moves 1+ to #moves ; > : #moves- #moves 1- to #moves ; Have a look at +! as a useful word that sometimes enables you to simplify things a bit. I would also suggest that on the next version you write what you expect each word to do as a glossary style comment before you write the code. This is a more Literal style of construction and helps in that the code becomes better documented than just relying on the stack pictures and the word's name for a clue. That way, when you look at the code in the future on you will have a greater speed of understanding what you were trying to do. -- ******************************************************************** Paul E. Bennett............... Forth based HIDECS Consultancy Mob: +44 (0)7811-639972 Tel: +44 (0)1235-510979 Going Forth Safely ..... EBA. www.electric-boat-association.org.uk.. ********************************************************************