0
How to improve code readability
Hi Below code works fine but I feel it is not fully readable. Get details does not communicate what details until and unless someone read through function code. C++ has pass by reference and I could have passed last to argument as id and type to make function signature more readable. But python do not have this provision. Is there any other option to make this code more readable? https://sololearn.com/compiler-playground/cPzD3ojnzq96/?ref=app
6 Antworten
+ 4
It reads quite ok to me. Maybe some comments could help?
+ 3
Your code is quite readable and quite easy to understand.
There is such a weird trend today about constantly making code more clean, but sometimes making code more clean only makes it more complex and unreadable.
You are doing just fine with your small example.
+ 3
coming from C++, you have the instinct to just mutate your data. You end up using list all over your code.
what you want is to make the intent of your data more obvious.
if you want mutable named properties, @dataclass is a decorator for classes used primarily to encapsulate data.
Other options are dictionaries, or namedtuples, if you feel lists are too generic ...
https://sololearn.com/compiler-playground/ckSWiO6Mc1qa/?ref=app
+ 3
+ 2
I think you followed the pep convention for writing source codes. The only thing that goes off is the space between : and their respective annotations
x : str (makes ugly code)
x: str (pep 8)
x:str, (frown at but okay)