Skip to content

Boids: Add a class, rename variables, merge for loop, replace numbers with variables#7

Open
myx2021 wants to merge 2 commits intoUCL-MPHY0021-21-22:mainfrom
myx2021:main
Open

Boids: Add a class, rename variables, merge for loop, replace numbers with variables#7
myx2021 wants to merge 2 commits intoUCL-MPHY0021-21-22:mainfrom
myx2021:main

Conversation

@myx2021
Copy link

@myx2021 myx2021 commented Dec 9, 2021

No description provided.

Copy link
Contributor

@ageorgou ageorgou left a comment

Choose a reason for hiding this comment

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

Good start, and creating a class can open more possibilities! You could have also created a class for each individual boid, rather than for the whole flock (as in, for example, #8).

You could shorten your attribute names a bit by removing the boid_ prefix, since they all belong to the object anyway.

The constructor of the class takes quite a few arguments. This is not a problem necessarily, but functions with lots of arguments can be confusing when you call them, which tends to lead to errors (not to mention long lines). Can you think of any other way to write this that would require fewer arguments all at once?

boid_x_velocities=[random.uniform(0,10.0) for x in range(50)]
boid_y_velocities=[random.uniform(-20.0,20.0) for x in range(50)]
boids=(boids_x,boids_y,boid_x_velocities,boid_y_velocities)
class boid:
Copy link
Contributor

Choose a reason for hiding this comment

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

Conventionally, class names start with a capital letter, e.g. Boid. Also, since this contains many of them, I would call it Boids to make that clear.

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