Why is defensive programming needed if source code is hidden?

190 Views Asked by At

Apologies if the question isn't too good, this is my first post.

I know that in Java defensive programming is a good thing to do, as it stops values of variables being changed if they are not supposed to be. However, if a program is compiled is this needed?

An example of what I mean is the following:

For my university coursework, I had to create a web browser using Swing and AWT in Java. This web browser was created solely by me, and when it was submitted I had to send an executable JAR file, and the .java files (only so that they can be marked, they will not be edited).

From my part, programming wise, I knew that I would not be doing any of the things that defensive programming is supposed to prevent. The source code will also never go public or be edited (whether this was published for public use or not). Therefore, why would defensive programming be needed seeing as you can't get the source code from an executable file?

I feel like I would only use this as it is the accepted standards for programming.

I hope I've explained this well.

Thanks.

1

There are 1 best solutions below

0
On BEST ANSWER

Question answered brilliantly by numerous comments. Best put by an excerpt of a comment by @Carcigenicate

Once it's been compiled, it's not really an issue. It's to prevent you from messing up your own source code when you forget some aspect of it down the road.

SO won't let me mark this as answered yet.