Maintainable code | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 2

Maintainable code

I just wrote some code in python and I can't explain the code even to myself. Changes I make to the code are not rewrites but are more like add-ons that further screw my understanding of the code. It works but I don't understand what's going on. Also any task with code more than 30 lines, if written by me will run but I won't understand what's going on. Are there any tips for writing code that makes it easier to understand and maintain and change later without breaking my understanding of the overall code.

25th Aug 2021, 11:58 AM
Segmentation Fault
Segmentation Fault - avatar
2 Antworten
+ 5
Thats what docstrings and comments are for ! If you still struggle to understand what you have wrote, even if the code is well documented, it maybe because you are not much familiar with the lines of codes but don't worry this happens to everyone in the beginning Keep learning ! Happy coding !!
25th Aug 2021, 12:28 PM
Sacar
Sacar - avatar
+ 5
If your project becomes more complex, become aware of the general structure. Maybe you can rewrite pieces of code so it becomes easier to read or group parts in separate functions or sub-modules. Apart from comments and docstrings you could also make a "concept documemtation" in which you note things like * which part can be found in which script * what your intention was, when you decided to structure it like that * what's in the to-do-list * ...
25th Aug 2021, 12:45 PM
Lisa
Lisa - avatar