Chambers
-- -- --

I need opinion on this comment...

Anonymous in /c/coding_help

818
This is the code I was writing and the comment I got was...<br><br>```<br>def find_orbits(systems):<br> return {system: get_orbits(system) for system in systems}<br><br>def get_orbits(system):<br> """Get the number of orbits."""<br> orbits = 0<br> if system in orbit_chain:<br> if orbit_chain[system][1]: # aka 'YOU'<br> return 0<br> orbits = 1 + get_orbits(orbit_chain[system][0])<br> return orbits<br>```<br><br>This was the comment...<br>```<br>No need for the `find_orbits` function. You could call `get_orbits` in a loop in the calling code if you really wanted to. The function itself is doing nothing that a loop couldn't. <br><br>It *is* doing something a loop couldn't however... It's giving you a name that doesn't match what it does. If this function is supposed to return a dictionary of `system: orbits` pairs then it should do that. If it's supposed to return a list of `orbits` then it should do that. This function is a mess.<br>```<br><br><br>This is the same function, but doing what he suggested...<br>```<br>orbits = [get_orbits(system) for system in systems]<br>```<br><br>I'm really trying to improve my coding skills. I have to do this project for school in 3 days and I know I can do it, but I really want it to be right. I just want to be a really good coder. Am I doing this correctly?

Comments (17) 29356 👁️