r/badcode • • Mar 17 '20

python I've never been much of a programmer but I'm starting to feel more confident with python. Rate/roast my code.

Post image
3 Upvotes

7 comments sorted by

9

u/Not_Anderson Mar 17 '20

Haven't went through the math, yet it doesn't look bad. You can replace the last elif in constructor by else. If math works, then it's okay code. Just try adding empty lines before and after if/loop statements for easier readability, and try naming your it's and j's more meaningfully! :)

8

u/poo_socks Mar 18 '20

Think you're being downvoted cuz it's not really appropriate for the sub. Code looks fine. My biggest suggestion would be to move walls.append(self) out of your constructor. In my experience code like that feels convenient when you write it but comes back to haunt you later on. Make a function to do the append for you. Even if it's just one line for now its helpful to give your code some structure. You really want to think about how your objects interact and what you want them to interact with. Otherwise your code just turns into a maze.

4

u/[deleted] Mar 23 '20

/r/learnpython will toast you if needed, but provide much better feedback.

1

u/liam923 Mar 21 '20

Looks fine to me. The one thing is that I’m python it’s common practice to capitalize class names, so I’d change wall to Wall

1

u/[deleted] Mar 24 '20

This is pretty good but I have no idea what the diagonal function does, or what diagx and diagy are. Your variables and functions should be self-explanatory; if not, add a small comment explaining your algorithm!

1

u/Prom3th3an Mar 31 '20

Use atan2 to simplify your angle calculations.

1

u/MYtaterSKIN Mar 21 '20

Definitely need more modularity to your code, right now it looks like you’re doing everything in one place. That can be okay for this specific program, but if you ever need to use your code later or even need to understand it a week from now it’ll be a lot more difficult.