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

🐦 Improving Boids Code #41

Open
dpshelio opened this issue Dec 2, 2024 · 4 comments
Open

🐦 Improving Boids Code #41

dpshelio opened this issue Dec 2, 2024 · 4 comments
Labels
week09 Structure and design

Comments

@dpshelio
Copy link
Contributor

dpshelio commented Dec 2, 2024

Open the repository for this exercise. You will find a brief description of each example in its README.md file.

  1. Discuss the code with your group. What problems do you see with it? Why?
  2. Write below your comments mentioning your group number. For now, focus on the
    problems, and don't make any changes yet!
@dpshelio dpshelio added the week09 Structure and design label Dec 2, 2024
@gozherie
Copy link

gozherie commented Dec 2, 2024

Group 23

  1. Variable names are inefficient.
  2. Multiple identical for loops.
  3. No documentation or comments for functions.

@WucxinChina
Copy link

Group 22

  1. Poor Readability:
    • Variable names are unclear (e.g., xs, ys, xvs, yvs).
    • Lack of comments and logical separation makes it hard to follow.
  2. Inefficient Performance:
    • Nested loops result in O(n²) complexity. This can be optimized using vectorized operations or spatial partitioning techniques (e.g., grids or quadtrees).
  3. Hardcoded Parameters:
    • Values like 0.01, 100, and 10000 are hardcoded without explanation. These should be replaced with constants or configurable parameters.
  4. Duplicate Logic:
    • Repeated code blocks for similar operations (e.g., velocity adjustments) should be refactored into reusable functions.
  5. Lack of Modular Design:
    • The behavior (e.g., movement, collision avoidance) is not encapsulated in separate functions or classes, making the code hard to extend or test.
  6. Global State Mismanagement:
    • The boids tuple is used as a global variable, which makes the code less maintainable and harder to test.

@charlotteesavage
Copy link

charlotteesavage commented Dec 2, 2024

Group 19's comments:

  1. Need to collect and define variables - eg use of len(xs) over and over is redundant
  2. Repetition in code of for loops - could be collected into a function for efficiency, or use fewer for loops
  3. Remove unused imports
  4. Use if __name__ == " __main__" to protect the script
  5. use numpy random functions for better efficiency than random over a range
  6. change fixed numbers to default parameters, so they can be changed if needed
  7. Add docstrings, and add more comments for better communication about what the code is meant to do
  8. instead of for i in range(len(xs)) + indexing, use for element in xs to access list elements directly in for loop
  9. too much happening in a single function - would be better to expand and divide function update_boids for better clarity and maintainability

@hskinhikar
Copy link

Working in mixed groups.

  • Multiple Nested loops - drives up time complexity O(n^2) * 4 because of 4 nested loops
  • Poor commenting/documentation - no clear explanations of the big chunk of code initially, no idea what is meant by 'flying to the middle', flying to middle of coordinate system or middle of other boids etc.
  • Incredibly hard to follow code, needs to have explanation of all the formulas so it's reproducible

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

No branches or pull requests

5 participants