Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the basic summation example with a simple simulation of coin-… #637

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

augeas
Copy link

@augeas augeas commented May 4, 2023

Issue #636:Examples / exercises encourage anti-patterns in 12-for-loops.md

Replace the example somewhat heavy-handed summation over a loop variable with a simulation of coin tosses:

  1. It's entirely valid for an accumulator to not depend on the loop variable, c.f. Monte-Carlo integration.
  2. We shouldn't solve the problem of range starting from zero with spurious additions in a loop, just use range properly. 3) A trivial summation over the loop variable should be done with the built-in sum function.
  3. The later exercise with a cumulative sum is a far better example.

Imports have been introduced previously, so it's probably okay to use random.random()
Other examples in the episode use if statements, but this is just more justification to switch the conditionals and loops episodes; conditionals are more fundamental than loops, if you don't have conditional branches, you're not Turing-Complete, and you don't really have a language.

Delete the string revering exercise.

  1. Strings, and other sequences are more idiomatically reversed with slice operators.
  2. The other exercises with string accumulators are much better.

On branch loops_grg
modified: episodes/12-for-loops.md

…tosses:

1) It's *entirely* valid for an accumulator to not depend on the loop varaible, c.f. Monte-Carlo integration.
2) We shouldn't solve the problem of `range` starting from zero with spurious additions in a loop, just use `range` properly.
3) A trvial summation over the loop variable should be done with the built-in `sum` function.
4) The later excercise with a cumulative sum is a far better example.

Delete the string revering excercise.
1) Strings, and other sequences are more idiomatically reversed with slice operators.
2) The other exercises with string accumulators are much better.
 On branch loops_grg
	modified:   episodes/12-for-loops.md
@github-actions
Copy link

github-actions bot commented May 4, 2023

🆗 Pre-flight checks passed 😃

This pull request has been checked and contains no modified workflow files, spoofing, or invalid commits.

It should be safe to Approve and Run the workflows that need maintainer approval.

@alee
Copy link
Member

alee commented May 11, 2023

Thanks for the PR! I like this change personally but would like to gather feedback from the rest of the community as well before moving forward.

I believe the original intent of re-implementing sum was to show a novice with minimal programming languages experience how something like creating a summation from 0-N could be implemented. That said, if it were to remain as is I definitely agree a followup with the built-in sum as the clearly better solution should be included.

I don't think we introduce format strings in the lesson so there should be some explanation of this either now or earlier.

Please keep in mind that this is not a foundational computer science course and so statements of Turing-completeness as to whether conditionals should be introduced before loops may not track with the intended audience. There have been multiple suggestions to reorder the episodes and ordering and I don't know that we've ever found true consensus yet...

e.g.,

#294
#113
#548

(etc)

@martinosorb
Copy link
Contributor

I generally agree on that exercise being not great. I taught it before and left some students puzzled, even though the majority are ok with it. However I would like to point out that your example has a random.random() < 0.5 line that is not necessarily intuitive. I imagine if I taught that, I would have to stop and explain for quite a while what that is for. Perhaps np.random.choice((0, 1)) could be an option?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants