Groups | Search | Server Info | Login | Register
Groups > comp.lang.forth > #23623
| From | rickman <gnuarm@gmail.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Programming Style |
| Date | 2013-06-11 23:10 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <kpg5jc$ol0$2@dont-email.me> (permalink) |
| References | (1 earlier) <d714a5f9-974c-471f-97bd-624ea69d60df@googlegroups.com> <kp4pru$asq$1@dont-email.me> <1e754e31-4d33-4a6c-bd23-a422c1abf9bd@googlegroups.com> <kp5lbe$ikn$1@dont-email.me> <3_udnWcsbop34CvMnZ2dnUVZ_uWdnZ2d@supernews.com> |
On 6/10/2013 9:31 PM, Elizabeth D. Rather wrote: > (name) is a common naming convention for a word that exists principally > as a factor of name. It's often useful to do this sort of factoring > because the lower-level word can be tested independently, and you might > want multiple high-level wrapper words. Thank you, I'll try to remember that and use it. I may do a rewrite of the code I am currently working with. The file is over 1000 lines and I believe it can be greatly simplified, if nothing else, by just tossing out extraneous words that were branches of the thought tree that are due for pruning. As I proceed I should reread some of my Forth books, if I can find them, paper books are hard for me to manage these days. I'll use the above convention when it seems to make sense. Is it common to include test code in with the definitions being tested? Most of my work these days is in VHDL where I generate a separate test bench file to test each module of code which is in its own file. Makes for a lot of files and a lot of projects in the simulator, a real mess in many ways. The tools also can generate dozens of intermediate files if not hundreds for each project. The waveform files can be many MBs too which tends to eat up my hard drive. In some ways I much prefer coding in Forth, but I get paid a lot more for my VHDL work. Or I should say, I get paid, period. My Forth work is for myself at this point. I think there is too much competition in the embedded market for the most part. I would find it hard to get much traction I think. > A couple of things to think about concerning your code here: > > * Remember that IF doesn't need a well-formed flag. So, you can use, > say, the results of a subtraction directly, without need for a 0= (if > the logic of the IF is the other way around). Yes, I'm well aware of that. I prefer to organize IF structures with the small clause on the top, so it is easy to skip over to read the ELSE clause. But this is a habit of writing *big* code and I should be keeping my Forth code small to make it more easily testable. I still find it hard to break things down so finely and still have the words seem like a useful function. > * Often you can do away with flags altogether. Rather than have all your > logic lead to passing out a flag that some other word needs to test and > do 'this' or 'that', you can just do 'this' or 'that' in the word. When the testing code detects errors, the next guy up the food chain needs to know so the rest of the testing can be skipped. No point in continuing a test if it is already corrupted. I'm thinking about a global variable for these errors. It can be set from anywhere and everyone can check it so it doesn't need to be passed around. I'm still trying to be a purest at Forth and not using variables for anything that doesn't require it which so far is almost nothing. I think I save the handle of the telnet port and some info for the COM port. Then there is a string buffer or two. Not so much. Otherwise the code is not complex. It is just a long list of operations that have been broken down into bite size pieces in a modular manner. It was when I started dealing with the errors that it got messy. One of the places that bit me without returning flags is a section of code that has to make four measurements and return all of the results. There is an input parameter which needs to go to each of the four measurements. So I first dup it to the return stack for the first measurement call and copy it back for the second and third measurement call, then do the R> for the final one. Trouble was when I added the code to detect an error in the measurement word and exit this word, I forgot the parameter on the return stack. Maybe a local would have been better for that? Do locals need to be released/decommissioned when exiting a word? > * As others have suggested, use THROW as a way of handling your error. > Again, just THROW when you know you need to, don't pass flags around > telling someone else to THROW. I have to meet with the fab house this week to get the test fixtures working. I also need to find and fix the comms bug that is causing all the trouble (likely in the FPGA). Then I will have more time to work on the software part of things and a chance to read up on throw and catch. Just reading the ANS standard I don't even get what they do really. Thanks, -- Rick
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar
Programming Style rickman <gnuarm@gmail.com> - 2013-06-09 14:33 -0400
Re: Programming Style Paul Rubin <no.email@nospam.invalid> - 2013-06-09 11:42 -0700
Re: Programming Style rickman <gnuarm@gmail.com> - 2013-06-09 15:22 -0400
Re: Programming Style "WJ" <w_a_x_man@yahoo.com> - 2013-06-09 19:16 +0000
Re: Programming Style rickman <gnuarm@gmail.com> - 2013-06-09 15:36 -0400
Re: Programming Style Roberto Waltman <usenet@rwaltman.com> - 2013-06-09 22:17 -0400
Re: Programming Style rickman <gnuarm@gmail.com> - 2013-06-22 09:53 -0400
Re: Programming Style humptydumpty <ouatubi@gmail.com> - 2013-06-10 00:31 -0700
Re: Programming Style rickman <gnuarm@gmail.com> - 2013-06-10 11:08 -0400
Re: Programming Style humptydumpty <ouatubi@gmail.com> - 2013-06-10 11:09 -0700
Re: Programming Style rickman <gnuarm@gmail.com> - 2013-06-10 18:56 -0400
Re: Programming Style "Elizabeth D. Rather" <erather@forth.com> - 2013-06-10 15:31 -1000
Re: Programming Style rickman <gnuarm@gmail.com> - 2013-06-11 23:10 -0400
Re: Programming Style albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-06-10 08:32 +0000
Re: Programming Style rickman <gnuarm@gmail.com> - 2013-06-10 11:12 -0400
Re: Programming Style albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-06-10 17:22 +0000
Re: Programming Style Mark Wills <markrobertwills@yahoo.co.uk> - 2013-06-11 01:01 -0700
Re: Programming Style Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2013-06-11 15:51 +0100
Re: Programming Style rickman <gnuarm@gmail.com> - 2013-06-12 11:14 -0400
Re: Programming Style "Elizabeth D. Rather" <erather@forth.com> - 2013-06-14 13:03 -1000
Re: Programming Style rickman <gnuarm@gmail.com> - 2013-06-14 19:22 -0400
Re: Programming Style "Elizabeth D. Rather" <erather@forth.com> - 2013-06-14 16:54 -1000
Re: Programming Style rickman <gnuarm@gmail.com> - 2013-06-15 12:14 -0400
Re: Programming Style "Elizabeth D. Rather" <erather@forth.com> - 2013-06-15 11:57 -1000
Re: Programming Style anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-06-17 16:12 +0000
Re: Programming Style rickman <gnuarm@gmail.com> - 2013-06-17 23:08 -0400
Re: Programming Style Hannu Vuolasaho <hannu.vuolasaho@nospam.tut.fi.invalid> - 2013-06-11 18:42 +0000
Re: Programming Style "Ed" <invalid@invalid.com> - 2013-06-12 12:00 +1000
Re: Programming Style "Elizabeth D. Rather" <erather@forth.com> - 2013-06-11 17:07 -1000
Re: Programming Style "Ed" <invalid@invalid.com> - 2013-06-13 14:21 +1000
Re: Programming Style "Elizabeth D. Rather" <erather@forth.com> - 2013-06-12 18:35 -1000
Re: Programming Style "Ed" <invalid@invalid.com> - 2013-06-13 16:56 +1000
Re: Programming Style "Elizabeth D. Rather" <erather@forth.com> - 2013-06-12 21:03 -1000
Re: Programming Style "Ed" <invalid@invalid.com> - 2013-06-14 10:20 +1000
Re: Programming Style "Elizabeth D. Rather" <erather@forth.com> - 2013-06-13 15:46 -1000
Re: Programming Style "Ed" <invalid@invalid.com> - 2013-06-15 23:27 +1000
Re: Programming Style Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-06-15 10:53 -0500
Re: Programming Style Mark Wills <markrobertwills@yahoo.co.uk> - 2013-06-14 01:34 -0700
Re: Programming Style anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-06-14 12:12 +0000
Re: Programming Style albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-06-14 15:13 +0000
Re: Programming Style "Ed" <invalid@invalid.com> - 2013-06-17 21:25 +1000
Re: Programming Style anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-06-17 15:37 +0000
Re: Programming Style Elizabeth D Rather <erather@forth.com> - 2013-06-17 08:17 -1000
Re: Programming Style albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-06-17 19:47 +0000
Re: Programming Style anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-06-18 08:12 +0000
Re: Programming Style Alex McDonald <blog@rivadpm.com> - 2013-06-17 12:59 -0700
Re: Programming Style rickman <gnuarm@gmail.com> - 2013-06-17 23:33 -0400
Re: Programming Style Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-06-19 19:50 -0700
Re: Programming Style Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-06-20 03:08 -0500
Re: Programming Style Alex McDonald <blog@rivadpm.com> - 2013-06-20 01:55 -0700
Re: Programming Style Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-06-20 05:10 -0500
Re: Programming Style Bernd Paysan <bernd.paysan@gmx.de> - 2013-06-20 13:02 +0200
Re: Programming Style anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-06-20 15:40 +0000
Re: Programming Style "Elizabeth D. Rather" <erather@forth.com> - 2013-06-20 07:21 -1000
Re: Programming Style albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-06-20 09:50 +0000
Re: Programming Style rickman <gnuarm@gmail.com> - 2013-06-14 18:50 -0400
Re: Programming Style "Ed" <invalid@invalid.com> - 2013-06-16 00:31 +1000
Re: Programming Style Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-06-15 10:59 -0500
Re: Programming Style albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-06-13 10:48 +0000
Re: Programming Style "Elizabeth D. Rather" <erather@forth.com> - 2013-06-13 07:44 -1000
Re: Programming Style albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-06-15 16:31 +0000
Re: Programming Style albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-06-12 11:10 +0000
Re: Programming Style mhx@iae.nl (Marcel Hendrix) - 2013-06-12 20:51 +0200
Re: Programming Style anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-06-12 15:06 +0000
Re: Programming Style "Ed" <invalid@invalid.com> - 2013-06-13 14:54 +1000
Re: Programming Style "Elizabeth D. Rather" <erather@forth.com> - 2013-06-12 20:43 -1000
Re: Programming Style anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-06-14 12:45 +0000
Re: Programming Style rickman <gnuarm@gmail.com> - 2013-06-14 16:39 -0400
Re: Programming Style "Elizabeth D. Rather" <erather@forth.com> - 2013-06-14 11:37 -1000
Re: Programming Style Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-06-11 18:23 -0700
Re: Programming Style "Elizabeth D. Rather" <erather@forth.com> - 2013-06-15 08:45 -1000
csiph-web