User talk:Chunes

From Rosetta Code
Revision as of 23:02, 26 January 2021 by GordonCharlton (talk | contribs) (→‎Quackery Bug Report: new section)

"Code review" for Plain English

Hello Chunes, would you please take a look at my implementation of factorial? I'm not quite happy with it, and I hope could suggest some improvements. For example, I don't like the phrase To put a number's factorial into another number, but don't know how else to make it work. Same with Put the number's factorial into the number, which seems quite an unnatural thing to say in plain English. I would like to keep the recursive approach however, just make it more "idiomatic" if there's such thing as idiomatic Plain English. Thanks for help! --Dick de Bill (talk) 14:48, 25 September 2020 (UTC)

I've been struggling a bit myself with naming routines. I think I would go one of two ways with this. The first is
<lang plainenglish>A factorial is a number.

To compute a factorial of a number: ...

\Calling the routine Compute a factorial of 5. Write "" then the factorial on the console.</lang>

Declaring type aliases to make routines sound more natural is commonplace in the noodle, so I think it's idiomatic. The downside here is the indefinite article a sounds a bit off. You could also use some, but it still sounds strange, like there could be more than one result.
The second is
<lang plainenglish>To compute the factorial of a number giving another number:

...

\Calling the routine Compute the factorial of 5 giving a number. Write "" then the number on the console.</lang>

I've seen this "giving" phrasing in the noodle as well, and I think it's a fairly elegant solution.
Another (weird?) way you could go with it is just embrace mutating a single argument.
<lang plainenglish>To factorialize a number:

If the number is 0, bump the number; exit. Put the number minus 1 into another number. Factorialize the other number. Multiply the number by the other number.

\Calling the routine Put 5 into a number. Factorialize the number. Write "" then the number on the console.</lang>

Regarding the input stuff, I would refactor it slightly so you don't need any global state.
<lang plainenglish>To run:
 Start up.
 Demonstrate input.
 Write "Bye-bye!" to the console.
 Wait for 1 second.
 Shut down.

To demonstrate input:

 Write "Enter a number: " to the console without advancing.
 Read a string from the console.
 If the string is empty, exit.
 Convert the string to a number.
 If the number is negative, repeat.
 Put the number's factorial into another number.
 Write "Factorial of the number: " then the other number then the return byte to the console.
 Repeat.</lang>
The idea is putting the loop entirely inside the To demonstrate input: routine so that you don't need any global flags. This can be done concisely with Repeat. by itself at the end of the routine. The loop will begin again from the top of the routine. I also used repeat when a negative number is encountered to act like a continue does in most other languages. --Chunes (talk) 17:03, 25 September 2020 (UTC)
Thanks for your suggestions; they all seem much more natural than my original implementation. I decided to go with the first approach and updated the factorial entry accordingly. --Dick de Bill (talk) 22:02, 25 September 2020 (UTC)

Loop Downward - off by one start value?

Hi, first of all: I love Plain English, great stuff. Thanks!

When reading Loops/Downward, Loops Downward, I stumbled over the initial value being 11. Should be 10, I guess. Or do I miss something? Best regards. Cg (talk) 13:39, 10 Dec 2020 (CET)

If a counter is below a number is a decider (boolean function) that looks like this:
<lang plainenglish>To decide if a counter is below a number:

Subtract 1 from the counter. If the counter is less than the number, say yes. Say no.</lang>

So it subtracts 1 from the counter before performing the comparison. This often works out nicely but it can make some things awkward. One could just as easily make a version that performs the comparison first and then adds one to the counter on the way out, or avoid using a routine like this altogether.
When reading a routine like this, it's important to keep in mind that all values are passed by reference (by default) in Plain English. --Chunes (talk) 13:57, 10 December 2020 (UTC)

Quackery Bug Report

FYI, rational numbers are off the menu until I fix "round" in bigrat.qky. Guess my testing wasn't as thorough as I thought. It may be a while, mediant rounding is complicated. I'll let you know.--GordonCharlton (talk) 23:02, 26 January 2021 (UTC)