Common Web Programming Mistakes
Published On :29 October,2012
Websites today are a strong advertising tool used by firms to endorse their products and services. Websites can also be considered as a combined effort of web programmers who work day and night to make things presentable for the viewers.
“To err is human, to forgive, divine.”
Sadly, the harsh truth is that your target audiences do not care how a web programmer makes a contact form, nor he is interested in knowing how a web programmer makes a link clickable on a website. What they want is a website that is user-friendly, information oriented and powered with latest tools that can offer hassle-free shopping.
Some days back, I received a mail from my colleague asking me to verify code written by his programmer. I pointed out several mistakes that were too common for a programmer to commit. This motivated me to write an article covering certain common programming mistakes that programmers do and ways to avoid them. Let us take a closer look at some common web programming mistakes:
Excluding opening or closing parenthesis
Well, this is a very common mistake and a very findable too if a programmer commits this only once, as the PHP parser will display an error message due to the uneven number of brackets. However, things become much difficult if you have made the same mistake more than once, as you may not get any error message. Spacing your codes uniformly can be a good option to avoid such silly mistakes.
Declaring functions and classes more than once
Another mistake that a web programmer often commits is of declaring a class or a function more than once with script execution. An obvious solution to this problem is to use require_once() or include_once(), which will ensure that such declarations are encountered only once. However, one should also keep in mind that this will not work if the same class or function is found in separate files while scripting.
The same problem occurs when a programmer includes a third party library, in which a class or a function collides with another third party library, or with one of your libraries. The best way to sort this out will be to prefix class names and function with a unique identifier. For example, the ‘CodeIgnitor’ framework uses the prefix of ‘ci’ in front of its classes, which is why as a user you should avoid using the same prefix while naming your classes.
Misspelling variable name
This one, my friend is one of the most common (a silly one too) programming mistakes we have today. In languages like Java, there is hardly a chance of such mistakes as compiler instantly detects unrecognized variables, thereby issuing an error message. On the otherhand, in languages such as PHP mistakes like these can go unnoticed, since PHP most of the times is not set up to warn a programmer about uninitialized variables.
Redirecting the user after sending output to the browser
If a programmer wishes to redirect a user then he/she will have to send a header to the browser, given the condition that all the headers are sent before other outputs. PHP’s output buffering functions will allows a programmer to control the point at which he is willing to send the output to the browser. The best thing to do for a web programmer in such cases is to structure his statements, so that no output is sent before all headers has been sent.
Using an access modifier to declare a class
In programming languages like PHP, a programmer cannot declare a class as private, public or even be specified as protected. However, a class is always public, which is why adding an access modifier while declaring a class will cause error.
Here are some more common web programming mistakes:
- Not using functions for making multiple changes
- Not using ‘Strip Slashes’ functions to remove special characters
- Not using ‘Trim’ functions for removing blank spaces
- Avoiding the use of minified J-Query
- Not validating inputs
- Cross-site scripting
- Poor formatting and Improper comments
- User Authorization errors
- Complexly coded passwords
- Unexpected T_String>
- Failure to preserve SQL Query
- Failure to preserve Web page query
- Failure to preserve OS Command Structure
Conclusion
We are currently living in the fast-forward era of dynamic web development wherein hardly you will be getting an opportunity to correct such common mistakes and excuses. Therefore, I hope this article will assist you in overcoming such mistakes.
Author Profile
Maneet Puri is the Managing Director of Lexolution IT Services; a professional Web Development Company. He is also an experienced Web Consultant, who offers professional assistance and advice to his clients located all round the world. Attention to minute web development details has been one of the primary reasons behind Maneet’s success. Apart from all this, he is also an enthusiastic writer, who interacts with his audience through articles and blogs on upcoming web technologies and design concepts.