« first day (3530 days earlier)      last day (1475 days later) » 

8:52 AM
Hello everyone! I have a question
I feel like whenever i write code and come back to it later even if happened to change or add whatever i needed i feel the need to read all the code
what should i do to avoid that feeling?
commenting?
 
 
2 hours later…
nwp
11:17 AM
Commenting doesn't help much. You'll just read comments instead of code. Sometimes comments can be clearer and express what cannot be expressed in code, but you get into issues of duplicating the logic in code and comments, causing maintenance hell.
What generally helps is having good abstractions. Mainly functions with clear names that do exactly what they are named so you can just use them without caring for how they work.
For example unit.die(); should just work and do the right things under the hood, like removing itself at the correct time from the correct places. If you need to know how to safely remove a unit then that is bad as you forget that and also it can change, leaving you with maintenance hell again.
 
 
8 hours later…
6:59 PM
@nwp sorry i dont quite understood the last part. In short: i need to write functions that clearly define what that specific function does right?
 
nwp
And that it does so without needing to know much about it. Having a unit.die(); function that you can only call in certain situations is more complicated than one you can call whenever you need to.
 
user92578
Good guards, assertions, typesafety etc. play a big part in here, so that you can simply write code that from the method calls seems correct, and that the runtime/compiler will quickly let you know if it actually is not correct
 

« first day (3530 days earlier)      last day (1475 days later) »