Is this code well made? Good enough? Anything to improve? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Is this code well made? Good enough? Anything to improve?

https://code.sololearn.com/c3wz48zz7bV0/?ref=app

17th Jan 2021, 5:59 PM
Yahel
Yahel - avatar
4 Answers
0
Your setter 'set_cage' is here totally useless, so you should remove it. Since all is public in Python, we only define getters and setters (with 'property') when it is worth creating them. Here, in your code, it brings nothing, so you should remove your method 'set_cage' and use the 'cage' attribute directly.
17th Jan 2021, 7:57 PM
Théophile
Théophile - avatar
0
Théophile ok, thanks. And about the classmethod: is what I did correct? The part when I used the class method in the constructor (__init__) ?
17th Jan 2021, 9:27 PM
Yahel
Yahel - avatar
0
I think it is relevant to use a classmethod in that case, so yes, I find it correct. However, I had named the class method '_add_animal' instead of 'add_animal'. The reason is that this method should be considered as a private method (I'm not sure that you want a user to call this method from outside your class ;) ). !warning! It will not make your method effectively private, but the user will have to consider it as private. Regarding the '__init__' method, I have only one thing to say : rename the parameter 'type'. Indeed, the name 'type' is the name of a built-in function, so it is better not to shadow it! Anyway, good job! 👍
17th Jan 2021, 9:44 PM
Théophile
Théophile - avatar
0
Théophile Thanks! 👌🏻
18th Jan 2021, 5:59 AM
Yahel
Yahel - avatar