Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #47381
| From | Darin Murphy <murphy.darin@gmail.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: How could have I factored this better? |
| Date | 2016-05-20 22:15 -0400 |
| Organization | news.aioe.org |
| Message-ID | <nhogco$1fcb$1@gioia.aioe.org> (permalink) |
| References | <5e60dbda-f34b-4be0-bfac-d32ddc67062f@googlegroups.com> <871t4we4e3.fsf@jester.gateway.pace.com> <ytydnUY4KviMM6LKnZ2dnUU7-R_NnZ2d@supernews.com> <87wpmock1u.fsf@jester.gateway.pace.com> <tJ-dnU9xKegaL6LKnZ2dnUU7-TnNnZ2d@supernews.com> |
"Elizabeth D. Rather" <erather@forth.com> Wrote in message:
> On 5/20/16 2:49 PM, Paul Rubin wrote:
>> "Elizabeth D. Rather" <erather@forth.com> writes:
>>> I don't see that the locals contributed anything. In fact, this is
>>> shorter, and avoids the need for code to manage the locals frame.
>
> When you declare locals, a locals fram
>
>> I'm not sure what you mean about "code to manage the locals frame" but
>> yeah, your version of solid-box-stars should work ok. I'd take a little
>> issue with it only checking one of the args, since as you say, inputs
>> should be checked when they are supplied in the first place. Therefore,
>> those checks have the nature of assertions, that signal that something
>> has gone expectedly wrong. Checking just one of the args on the
>> observation that the other one is checked in another place in the code
>> is sort of ok since the other place is just 2 lines away. But in
>> general, we put assertions in code because experience tells us that our
>> observations and reasoning aren't always reliable. So if both of those
>> words have preconditions and we're into checking such things, it seems
>> ok to me to check in both places.
>
> To me, the question of whether to check the row length in stars or
> solid-box-stars depends on whether stars might be called from somewhere
> else. If it's only used by solid-box-stars, I agree, both args should be
> checked there. There's no point in checking twice, but there's no
> guarantee that you mightn't find a use for stars elsewhere. In other
> words, these decisions should be made in the context of the application
> design, although that's hard to do with these little examples.
>
> Cheers,
> Elizabeth
>
> --
> ==================================================
> Elizabeth D. Rather (US & Canada) 800-55-FORTH
> FORTH Inc. +1 310.999.6784
> 5959 West Century Blvd. Suite 700
> Los Angeles, CA 90045
> http://www.forth.com
>
> "Forth-based products and Services for real-time
> applications since 1973."
> ==================================================
>
Okay. Here's my factored version, using the suggests given:
: star ( -- ) ." *" ;
: stars ( n -- ) dup 1 < abort" value not a positive integer!" 0
do star loop ;
: solid-box-stars ( column row -- ) dup 1 < abort" value not a
positive integer!" 0 do dup cr stars loop drop ;
The reason I did 1 < because the problem in the book asked for a
box of stars and 0 in either place wouldn't create a box shape of
anything. For documentation purposes I should have broken up
solid-box-stars to look like this?
: solid-box-stars ( column row -- ) dup 1 < abort" value not a
positive integer!"
0 do dup cr stars loop drop ;
Just trying to learn good documentation and factoring as early as
possible, so they will become habits by the time I start working
on larger programs. Thanks again for all of the suggestions and
advice.
Take care now,
--
Darin Murphy
----Android NewsGroup Reader----
http://usenet.sinaapp.com/
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-20 13:09 -0700
Re: How could have I factored this better? rickman <gnuarm@gmail.com> - 2016-05-20 16:18 -0400
Re: How could have I factored this better? "Elizabeth D. Rather" <erather@forth.com> - 2016-05-20 10:25 -1000
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-20 13:39 -0700
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-20 21:33 -0400
Re: How could have I factored this better? "Elizabeth D. Rather" <erather@forth.com> - 2016-05-20 10:23 -1000
Re: How could have I factored this better? Paul Rubin <no.email@nospam.invalid> - 2016-05-20 15:44 -0700
Re: How could have I factored this better? "Elizabeth D. Rather" <erather@forth.com> - 2016-05-20 14:38 -1000
Re: How could have I factored this better? Paul Rubin <no.email@nospam.invalid> - 2016-05-20 17:49 -0700
Re: How could have I factored this better? "Elizabeth D. Rather" <erather@forth.com> - 2016-05-20 14:57 -1000
Re: How could have I factored this better? Paul Rubin <no.email@nospam.invalid> - 2016-05-20 18:34 -0700
Re: How could have I factored this better? "Elizabeth D. Rather" <erather@forth.com> - 2016-05-20 16:00 -1000
Re: How could have I factored this better? Paul Rubin <no.email@nospam.invalid> - 2016-05-20 20:08 -0700
Re: How could have I factored this better? "Elizabeth D. Rather" <erather@forth.com> - 2016-05-20 17:24 -1000
Re: How could have I factored this better? hughaguilar96@gmail.com - 2016-05-21 18:15 -0700
Re: How could have I factored this better? Albert van der Horst <albert@cherry.spenarnc.xs4all.nl> - 2016-05-21 10:01 +0000
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-20 22:15 -0400
Re: How could have I factored this better? "Elizabeth D. Rather" <erather@forth.com> - 2016-05-20 16:46 -1000
Re: How could have I factored this better? hughaguilar96@gmail.com - 2016-05-21 18:36 -0700
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-21 22:51 -0400
Re: How could have I factored this better? hughaguilar96@gmail.com - 2016-05-21 22:23 -0700
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-20 22:43 -0400
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-20 22:19 -0400
Re: How could have I factored this better? "WJ" <w_a_x_man@yahoo.com> - 2016-05-21 22:02 +0000
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-21 22:30 -0400
Re: How could have I factored this better? humptydumpty <ouatubi@gmail.com> - 2016-05-21 19:40 -0700
Re: How could have I factored this better? humptydumpty <ouatubi@gmail.com> - 2016-05-21 19:38 -0700
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-21 23:06 -0400
Re: How could have I factored this better? Paul Rubin <no.email@nospam.invalid> - 2016-05-21 20:59 -0700
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-22 03:30 -0400
Re: How could have I factored this better? "Elizabeth D. Rather" <erather@forth.com> - 2016-05-21 23:14 -1000
Re: How could have I factored this better? humptydumpty <ouatubi@gmail.com> - 2016-05-27 03:54 -0700
csiph-web