Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #47392
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: fizzbuzz problem in forth |
| Date | 2016-05-20 21:55 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <87futcc8mp.fsf@jester.gateway.pace.com> (permalink) |
| References | (3 earlier) <2016May13.145248@mips.complang.tuwien.ac.at> <8760udodtl.fsf@jester.gateway.pace.com> <2016May17.154948@mips.complang.tuwien.ac.at> <87k2ismu0z.fsf@jester.gateway.pace.com> <2016May18.143614@mips.complang.tuwien.ac.at> |
anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
>>The trouble is that the specified string might be the empty string.
> Not in the original task and not in the extended versions suggested by
> <http://dave.fayr.am/posts/2012-10-4-finding-fizzbuzz.html> nor those
> discussed in other postings I found, either.
The original task was just 3->Fizz, 5->Buzz. The extended versions
suggested additional numbers like 7, and additional strings like Bazz.
I don't remember it mentioning the empty string specifically, but the
empty string is a perfectly good string just like 0 is a perfectly good
number. Neither should make programs misbehave.
> So, ok, your solution, my "more Forth-like solution" and the Haskell
> Maybe variant are prepared for the case when the extended task says:
> "In some cases, print nothing."
Well here there's again a code smell, or maybe a specification smell,
where the word "nothing" is overloaded. It's cleaner to say that the
empty string is not nothing. It's a string, whose length happens to be
zero. That is something rather than nothing.
> But is it worth complicating the solution with Maybe and (up-to-now)
> redundant flags in order to be prepared for this?
The extra flags in the Forth examples do complicate the code, but I
think one point of the blog post is that Maybe doesn't complicate things
as much, because of how Maybe's monoid instance lifts the string
concatenation operation into the Maybe String type. That is, the post
is a bit of Haskell advocacy, saying Haskell's built-in abstractions
make this stuff work automatically. The Maybe type also makes the
difference between "the empty string" and "nothing" explicit, which
helps clear thinking.
> Anyway, one of Chuck Moore's principles is "Do what is needed, don't
> generalize", and this discussion is a good example for that.
OTOH, one of the principles from "The Elements of Programming Style"
from the same era was
33. Make sure your code does "nothing" gracefully.
( https://en.wikipedia.org/wiki/The_Elements_of_Programming_Style )
If my system has a word INCREASE-FOO:
VARIABLE foo
: INCREASE-FOO ( n -- ) ... ; \ make foo larger by n
and it somehow doesn't work when n=0, that's broken code even if none of
the examples in the specification had n=0. Making it work properly for
n=0 is not overgeneralization by any means.
> Whatever solution you write, the interviewer (or, in real life, the
> customer) can give you a change request for which it does not work
> well. And you can "smell" that, so every solution will have a smell
> if you are thinking in terms of what-ifs.
There's a big enough body of experience in programming by now that we
have identified lots of valuable practices, re-usable abstractions, etc.
Handling do-nothing cases properly is so basic good practice that even
the the Programming Style book from the 1970's documented it explicitly.
"Maybe" values might have originated in ML in the 1980s, but are finally
catching on in the wider world.
> Back to the >STRING-EXECUTE implementation. I thought about a simpler
> way (as far as implementation is concerned). Fig-Forth has a user
> variable OUT ...
IMHO this is still way ugly compared with remembering whether any of the
tests succeeded, or alternatively, remembering whether the string
printer has been called (possibly with the empty string as argument).
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
fizzbuzz problem in forth murphy.darin@gmail.com - 2016-05-12 16:17 -0700
Re: fizzbuzz problem in forth Paul Rubin <no.email@nospam.invalid> - 2016-05-12 16:43 -0700
Re: fizzbuzz problem in forth murphy.darin@gmail.com - 2016-05-12 17:22 -0700
Re: fizzbuzz problem in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-05-13 12:52 +0000
Re: fizzbuzz problem in forth Paul Rubin <no.email@nospam.invalid> - 2016-05-16 15:09 -0700
Re: fizzbuzz problem in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-05-17 13:49 +0000
Re: fizzbuzz problem in forth Paul Rubin <no.email@nospam.invalid> - 2016-05-17 11:14 -0700
Re: fizzbuzz problem in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-05-18 12:36 +0000
Re: fizzbuzz problem in forth Paul Rubin <no.email@nospam.invalid> - 2016-05-20 21:55 -0700
Re: fizzbuzz problem in forth julian.fondren@endurance.com - 2016-06-20 20:20 -0700
Re: fizzbuzz problem in forth hughaguilar96@gmail.com - 2016-05-17 12:26 -0700
Re: fizzbuzz problem in forth Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-05-15 21:42 +0100
Re: fizzbuzz problem in forth hughaguilar96@gmail.com - 2016-05-15 14:41 -0700
Re: fizzbuzz problem in forth hughaguilar96@gmail.com - 2016-05-15 15:15 -0700
Re: fizzbuzz problem in forth hughaguilar96@gmail.com - 2016-05-15 17:38 -0700
Re: fizzbuzz problem in forth murphy.darin@gmail.com - 2016-05-15 19:01 -0700
Re: fizzbuzz problem in forth hughaguilar96@gmail.com - 2016-05-15 19:51 -0700
Re: fizzbuzz problem in forth murphy.darin@gmail.com - 2016-05-15 20:48 -0700
Re: fizzbuzz problem in forth hughaguilar96@gmail.com - 2016-05-16 07:51 -0700
Re: fizzbuzz problem in forth "WJ" <w_a_x_man@yahoo.com> - 2016-05-25 08:31 +0000
Re: fizzbuzz problem in forth "WJ" <w_a_x_man@yahoo.com> - 2016-05-27 19:06 +0000
Re: fizzbuzz problem in forth humptydumpty <ouatubi@gmail.com> - 2016-05-18 13:19 -0700
Re: fizzbuzz problem in forth hughaguilar96@gmail.com - 2016-05-18 17:49 -0700
Re: fizzbuzz problem in forth humptydumpty <ouatubi@gmail.com> - 2016-05-18 21:17 -0700
Re: fizzbuzz problem in forth hughaguilar96@gmail.com - 2016-05-19 07:38 -0700
Re: fizzbuzz problem in forth "Kerr Mudd-John" <admin@127.0.0.1> - 2016-06-20 19:24 -0100
Re: fizzbuzz problem in forth endlessboomcapitalism@gmail.com - 2016-06-20 15:03 -0700
Re: fizzbuzz problem in forth Albert van der Horst <albert@cherry.spenarnc.xs4all.nl> - 2016-05-19 13:07 +0000
Re: fizzbuzz problem in forth Paul Rubin <no.email@nospam.invalid> - 2016-05-19 12:22 -0700
Re: fizzbuzz problem in forth Albert van der Horst <albert@cherry.spenarnc.xs4all.nl> - 2016-05-20 23:51 +0000
csiph-web