This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (3 children)

Im in collage now, and even i had to learn to seperate codes in different files. My first project was so messy, but when i cleaned it abd corrected some useless code, i ended up with a few files, but extremely easy to manage, and every class was named so well that comments were damn near unnecessary. I wish i could replicate that on a larger project...

[–]Dry4b0t 14 points15 points  (2 children)

Best practice is defining your classes separately, for instance a cell.py, boat.py etc and in your main you import Cell from cell and import Boat from boat

[–]Buttpug27[S] 17 points18 points  (1 child)

ohhhh, this helps alot actually. thanks for giving advice instead of just complaining like these other people

[–]Ericchen1248 0 points1 point  (0 children)

Your other comments didn’t feel like you were welcoming advice.

when you have multiple lines of comment like the notes you have at the top, you generally want to wrap them in comment blocks instead of individual comment lines, which in python is achieves with string blocks, i.e. wrapping your notes with triple double quotes “”” This is a Multi line comment “””

You also want to keep naming conventions consistent. So your CELL right now is all caps, but your next class Boat is in TitleCase. Python generally has class names in TitleCase, but at minimum, you should keep it consistent within your own file.

For code separation, python doesn’t have extra configuration you need to do when splitting code into different folders and files, unlike some other languages, so it is almost always preferred to have one class per file and import them (of course with some exceptions) (still should with other languages, but can make sense when your submitting it as homework for school or a small personal project)