How to write Error Free Code?

Recently my staff member asked me, “How can I write a Error Free Code?”. hmm.. interesting question.

I always ask them to write a error free code and I found that I don’t have any answer that fit in all situation and in cases. Even the biggest of programmer has done error in their code. So shall we understand a Code cannot be written Error free? Techincally I would say, we can write a Error free code.

But to answer above question, I first like to define an Error.

  • If your script runs, and procduce a “SCRIPT SYNTAX” error, that is what I call error.
  • If your script runs and halt on some situation that is not properly handle is what I call an error
  • If your script runs for one condition but fails for second is what I call an error

But I don’t see an error, if script doesn’t fulfill a business logic, if it was not mentioned at time of writing script. It is not an error, if your script get hacked but to some newly discovered Method of hacking. It is not an error, if your script fail to run on Upgraded server.

Error, in general can be define as anything that goes wrong from ones prespective. But it can have specific definiation as well. You can write an Error free code only, if you apply your knowledge. If anything that is beyond your imagination cause the error is not an error. However you have to decide what is your level? If you have 3 yrs of experince and your script produce an error in say simple Select Query, then ofcourse your level is not yet reached. So, I would say next time one ask that question, should first answer, What is your Level? Are you coding that level of programming. If yes, then you already are writing an ERROR FREE CODE.

Techincally programming is different from commerical Programming, I will try to define that in future. But you have to decide if programming is your passion or profession.

, ,