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

8th Mar 2025, 5:33 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
6 ответов
+ 4
It reads quite ok to me. Maybe some comments could help?
8th Mar 2025, 7:54 AM
Ausgrindtube
Ausgrindtube - avatar
+ 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.
8th Mar 2025, 9:30 AM
Jan
Jan - avatar
+ 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
8th Mar 2025, 9:39 AM
Bob_Li
Bob_Li - avatar
+ 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)
8th Mar 2025, 11:44 AM
Badgirl MIRI
Badgirl MIRI - avatar
8th Mar 2025, 5:42 PM
Ketan Lalcheta
Ketan Lalcheta - avatar