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

Implementation list vs yield #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bbelderbos
Copy link

we had fun :)
thanks

we tried list and yield, latter being much faster

(fizzbuzz) [bbelderb@macbook pycones2016 (vio_bob)]$ python2.7 -m timeit -s "from fizzbuzz import fizzbuzz_yield" "fizzbuzz_yield()"
1000000 loops, best of 3: 0.522 usec per loop
(fizzbuzz) [bbelderb@macbook pycones2016 (vio_bob)]$ python2.7 -m timeit -s "from fizzbuzz import fizzbuzz" "fizzbuzz()"
10000 loops, best of 3: 35 usec per loop
Copy link
Contributor

@islomar islomar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5: "Buzz",
15: "FizzBuzz",
}

with describe('Fizzbuzz'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello and thanks for the interest :-)

The problem that I personally see to this kind of test, it's that you don't see which is the business logic applied, which are the requirements being solved: why 3 is "Fizz", why 5 is "Buzz"? The tests should be a main part of your documentation.

IMHO, this kind of tests (something like a parametrized tests) might be good for a final stage, where you don't want to have 100 tests, one for each use case: once you have already discovered and solved the business logic, then it might be good to have a kind of "overall" test to complement it, where you see many other cases.

Indeed, I tried that approach (it's one of the repos that we include in the README) :-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thans for your feedback, appreciated

for i in range(1, limit + 1):
if not i % 3 and not i % 5:
res.append("FizzBuzz")
elif not i % 3:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some duplication (e.g. i % 3)

Copy link
Author

@bbelderbos bbelderbos Oct 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, should put that in a method of its own

pass
def fizzbuzz(limit=100):
res = []
for i in range(1, limit + 1):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to split responsibilities into different components/functions/whatever, so that the responsibility to solve the 100 numbers would be different to the responsibility to decide which answer to be given.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, this was a quick implementation for the workshop, but now with the tests in place we can 'safely' refactor to make it more maintainable

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.

2 participants