How 'child proof' should I write code as a solo programmer? [duplicate]

In our company there once were multiple programmers, now I am the last man standing. I have inherited all the code and I maintain, rewrite, extend (,fix) it. I always run into this behavior that I try to make stuff foolproof so that a incompetent co-worker couldn't mess up the code. But there are limits to what I can do. I cannot prevent that someone holds a reference to an object. Even java/android system classes give you an object that you are not supposed to hold on to but just use it locally and thats it. In our company a lot went wrong and I am kind of a burned child, I see possibilities how someone could do the wrong thing and the code keeps crashing and I am asked "why do you write stuff like that"... Right now I am the only programmer but in the future maybe we have more (again), but right now I kinda restrain myself by spending too much time on trying to figure out how I could write my stuff so that the least amount of mistakes can be made with it. Even though I would be the one who had to make the mistake. Like everyone I do make mistakes ofc. So I null-check etc and write limits into the java-docs to remind myself what values I may pass etc. Those simple checks are not what I'm talking about. I am talking about that often I could write a method in a simple and good way but some voice in my head says "oh no, what if SOMEONE would pass a wrong parameter or did this and that with it" and suddenly I find myself encapsulating logic and making stuff more complicated only to add some sort of protection against... incompetent programmers with me being the only one possible. I am NOT working on any open API or shared stuff. There will (most likely) never be any code audits etc. I am the only one using the code and it will stay like that for a long time. So how do I stop myself from doing this foolproof coding that costs me too much time and brainpower? EDIT: I read the other question + answers. I understand the whole 'defensive programming' but I wonder when am I taking it too far? And that's more my problem.

Jan 26, 2025 - 19:14
 0
How 'child proof' should I write code as a solo programmer? [duplicate]

In our company there once were multiple programmers, now I am the last man standing. I have inherited all the code and I maintain, rewrite, extend (,fix) it.

I always run into this behavior that I try to make stuff foolproof so that a incompetent co-worker couldn't mess up the code. But there are limits to what I can do. I cannot prevent that someone holds a reference to an object. Even java/android system classes give you an object that you are not supposed to hold on to but just use it locally and thats it.

In our company a lot went wrong and I am kind of a burned child, I see possibilities how someone could do the wrong thing and the code keeps crashing and I am asked "why do you write stuff like that"...

Right now I am the only programmer but in the future maybe we have more (again), but right now I kinda restrain myself by spending too much time on trying to figure out how I could write my stuff so that the least amount of mistakes can be made with it. Even though I would be the one who had to make the mistake.

Like everyone I do make mistakes ofc. So I null-check etc and write limits into the java-docs to remind myself what values I may pass etc. Those simple checks are not what I'm talking about. I am talking about that often I could write a method in a simple and good way but some voice in my head says "oh no, what if SOMEONE would pass a wrong parameter or did this and that with it" and suddenly I find myself encapsulating logic and making stuff more complicated only to add some sort of protection against... incompetent programmers with me being the only one possible.

I am NOT working on any open API or shared stuff. There will (most likely) never be any code audits etc. I am the only one using the code and it will stay like that for a long time.

So how do I stop myself from doing this foolproof coding that costs me too much time and brainpower?

EDIT: I read the other question + answers. I understand the whole 'defensive programming' but I wonder when am I taking it too far? And that's more my problem.