-
Notifications
You must be signed in to change notification settings - Fork 7
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
API example: Setting the table for dinner #9
Comments
While I like this approach, that requires to initialize a "Places" list first. How do you think that should look? Syntax like this
is probably harder to grasp for a beginner than
While the set_block syntax, the tuples and the coordinates are debateable, I think a procedural approach is a bit easier to grasp than a declarative one. |
I agree with you, @dbrgn, that the range(10) statement is in many ways easier for the beginner to understand. And it's certainly something that should be available,and which they should be taught. Although I think range(-10) will be a gotcha for many users. But range() won't work for setting the table for dinner, which is much harder than putting down a row of blocks. It won't work even if we the places as a tuple of (x, y, z) values given to us. With logo the turtle has three attributes
A major difficulty in teaching the computer how to lay the table for dinner, as described above, is to ensure that the knives are point in the correct direction, namely away from the person who will be using them. Hence my quote from wikipedia. We need the orientation as well, to lay the table correctly. |
places = [Place(x, 0, 0) for x in range(10)]
for place in places:
place.put(setting) While I agree this is better, it requires pointing out that places = [Place(x, 0, 0) for x in range(10)]
for place in places:
place.put(setting) |
Also how would you write the list comprehension over two or three dimensions? Comprehensions with multiple loops? Ditch for nested append? places = [Place(x, y, z) for z in range(5) for y in range(7) for x in range(10)] (I'm not even sure what order I'd put them in) Personally I'd use |
I'd do a loop. It's more explicit and easier to understand. places = []
for x in range(10):
for y in range(7):
for z in range(5):
places.append(Place(x, y, z)) |
Yeah, I'd probably suggest the same (it's |
Oops :) Of course. |
We're expecting six people for dinner. There's a rectangular table in the dining room, two on each side and one at each end. That seats six. So how do we set the table?
It's obvious really. We go to each place in turn, and at put at each place a plate, knife and fork. For a more elaborate meal there's more - glasses for drink, cutlery for additional courses. But the basis idea is the same.
Building a castle or a palace is similar. Once the walls are up we go round adding the battlements and windows. The same method works for a classical Greek temple.
I'd like the API to support this way of thinking.
This approach owes a lot to the turtle in Logo. To quote from wikipedia, using the turtle means
The text was updated successfully, but these errors were encountered: