Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!uakari.primate.wisc.edu!sdd.hp.com!mips!pacbell.com!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!pitt!willett!ForthNet From: ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: Formatting Forth source code Message-ID: <2752.UUL1.3#5129@willett.pgh.pa.us> Date: 13 May 91 11:56:49 GMT Organization: (n.) to be organized. But that's not important right now. Lines: 64 Category 2, Topic 13 Message 19 Wed May 08, 1991 R.CAVANAUGH [BobC] at 23:38 MDT In keeping with the spirit, here is my prefered way of formatting: ( F - PC dialect ) \ Modified query to select maximum number of input : nquery ( n -- ) tib swap expect \ get digits from in stream span @ #tib ! \ store number of inputs >in off \ reset input pointer ; \ General purpose routine to \ input a number from the user : get-num ( #digits base -- dnum flag ) \ flag - true for valid base @ >r ! \ save current base, load new ." ?" \ prompt for input nquery \ get <= #digits from input bl word \ convert to counted str ?uppercase \ if hex, make sure upper number? \ convert string to number r> base ! \ restore old base ; - Notes 1. If my words require detailed stack diagrams at each line, I feel I need to rethink how I am doing it. Input stack condition and output I feel should be sufficient 2. Each line should be functionally related, i.e. I would put " 1 junk +! " as one line as incrementing a variable is really one action, whereas " something-to-test n = if do-if-true else do-if-false then " is the way I like to structure conditionals. I can take a ruler (or the col indicator on my editor) and see the subdivisions of the algorithm. 3. I am a strong proponent of line-by-line comments, as to what you are trying to do. I find this helps me a great deal when I come back to code (in any language) n years later and try to reuse or modify it. The flow of how I thought out what I was doing rings bells, and I have found aids my collegues in understanding and maintaining the code. I find the effort required pays later. - Bobc ----- This message came from GEnie via willett. You *cannot* reply to the author using e-mail. Please post a follow-up article, or use any instructions the author may have included (USMail addresses, telephone #, etc.). Report problems to: dwp@willett.pgh.pa.us _or_ uunet!willett!dwp