Is it really necessary to validate the code?

It’s the mania of those who tend to perfection and write the code with almost a maniacal accuracy, to see the green check mark that indicates that the code of the web page newly developed passed the validation control. But what does validating a code mean? And why is convenient validate the code? And yet, is it always necessary to pass the validation or there can be some exceptions?
First things first, in this article we’ll try to answer to all the interrogatives posted and with which many developers find themselves facing everyday.
What does writing a valid or standard code mean?
Let’s starting saying what is meant for “writing a valid or standard code“.
A bit of history
There’s an international no-profit organization, composed of a group of experts that have been working years on standardizing the languages and technologies for the web. Such organization is called World Wide Web Consortium (or W3C).
The web standards
The W3C in the course of the years has established the standards that have the task to define the syntax and the markers (tag) to use in the creation of any kind of web document. Therefore following these standards web contents are more usable to all the users regardless the type of browser used and in some cases (if even the accessibility guidelines are respected) also by the interpreter in use (for example, normal browsers, browsers based on devices of vocal syntax, mobile phones, personal computers for auto, etc.)
How can one write a valid code?
We just said that writing a valid code means to respect the standards defined by W3C. But how can one write a valid code?
When a web page gets developed, the first thing that is indicated in the document is the Doctype (Document Type Definition) that is necessary to inform the browser the language with which the document is edited.
To write a valid code it’s necessary to check that the markers (tag) and the attributes used fully respect the syntax defined in the Doctype declared at the beginning of the document.
Once our web document is created, how can we verify that we have written a standard code?
How to be sure that a valid code has been written?
To control the validity of one’s code, we can use several softwares – like the Markup Validation Service offered by the W3C - that automatically controls the correctness and the respect of the standards of the document you want to test.

The validator provided by the W3C, besides indicating eventually the errors made during the creation of the web document, provides a valid help in the correction of such errors, reporting the code line where the error is and describing also the kind of error. Obviously to understand and correct such errors it’s necessary to comprehend the code in order to modify at the occurrence the source code of the document.
A Firefox extension for the validation of the code in real time
Validating the code of your web document on the validator’s site provided by W3C involves some complications, for example it’s not possible to monitor the validation during the development of the code, unless one uploads the web document on the W3C ‘s valuator at every new code line edited, with a great lost of time.
If you want you can resolve this problem by installing HTML Validator, an extension for the Firefox Open Souce browser which provides all the tools necessary for the validation of the web pages directly in the window of the browser. The plugin is based on two algorithms developed by the W3C, Tidy and OpenSP.

Using this extension every time you surf any kind of web document, the result of the validation of the document is shown directly in the window of the browser, on the bottom right, as shown in the picture above.
What does writing a valid code involve?
Obviously writing a standard code involves some advantages, among the other things, the web document will be easily usable by all users, regardless of the browser and it shouldn’t be overlooked also the “indexation” factor as the search engine spiders could have problems properly indexing web documents containing certain markup errors.
Is a validated code always synonymous of a good code?
Attention of being fooled by the word “validated” and the positive result returned by the W3C valuator.
The code of a web document can also be validated but this doesn’t mean that this code is a good code as there’re several factors that a valuator, since we’re talking about a software, may not assess correctly.
For example web documents affected by “classness” or “divness” can also be valuated if the markers used for the creation of the web document have been used correctly, the valuator will however return a valid code. But this doesn’t mean that it’s a good code.
Let’s immediately do an example to try to better understand what we’re saying:
<div id="big-title">
<h2>Title</h2>
</div>
<div id="navigation">
<ul>
<li>item 1</li>
</ul>
</div>
<div class="red-paragraph">
<p>This paragraph is red</p>
</div>
The code above if it was under the verification of the valuator, would be valid as all the markers (tag) defined by the W3C guidelines have been properly used. But as we said, this code cannot be considered as an optimized code because it uses several elements that can easily do without.
Here’s an example of an optimized code that produces the same result of the previous one:
<h2 id="big-title">Title</h2>
<ul id="navigation">
<li>item 1</li>
</ul>
<p class="red-paragraph">
This paragraph is red
</p>
As you can see in this very banal example to write only three elements (title, list and a paragraph) of an hypothetic web document, the first one uses eleven code lines while the second one only seven. This is a typical error committed by visual editors, which fill the code of a web document with many useless elements.
With this example we have demonstrated that writing a valid code is not always synonymous of a good code.
Validate the code: Is it always necessary to pass the validation?
Assuming that for a developer being able to validate the code he’s creating usually represents a personal satisfaction as well as a challenge with himself, is it always necessary to pass the validation?
The green check mark that indicates a validated code is generated by a software in accordance with the result provided by an algorithm developed to verify the correctness of the code under exam. Considering that a software has some very strict rules, it can happen that the code of a Web document, even if perfectly developed, for whatever kind of banality not foreseen by the validation algorithm, may not be validated
Let’s do an example: by default the API of Twitter are based on a simple div- to add to your HTML code- containing an unordered list (<ul></ul>) where afterwards differen tweets will be inserted uploaded via a javascript function.
<div>
<ul id="twitter_update_list"></ul>
</div>
If we try to integrate our Twitter account inside a web document using these API, when the time comes to validate the code, we’ll receive an error message as the unordered list doesn’t contain any elements (<li>…</li>). Even in case we have perfectly developed the entire code of the web document, this would not be valid.
Can such an error compromise the validity of the entire work?
Paradoxically we can find ourselves in a situation like this:
- a Web document is validated although it has been developed with big problems of “divness” and “classness” or paged with tables;
- a Web document that – even if perfectly developed – with the integration of an element of third parties (as Google Maps or the fan box of Facebook might be) is found to have an invalid code.
Which of the two documents would you consider as more valid?
Validate the code: Extreme cases
I end this article with a final consideration: I happened to see people who, despite having chosen a Strict type doctype for the development of their web document and then spending hours of time searching for alternative methods in the attempt to validate the code that has attributes no longer permitted, like for example the target attribute.
If we need to use the target attribute, where’s the reason to choose a strict type doctype?
Now it’s your turn: I would like to hear your opinion on the many questions raised in the last part of this article.
P.S. Twitter’s API problem has been reported only for educational purposes , in reality it can be resolved just adding an element of the list containing an empty space: <li> </li>.
*****************************************
L'immagine principale dell'articolo è stata fornita da @Fotolia
12 comments
Trackback e pingback
-
Is it really necessary to validate the code?
[...] Is it really necessary to validate the code? [...] -
Is it really necessary to validate the code? « Codingbird
[...] Read More by: http://www.yourinspirationweb.com/ [...] -
Tweet-Parade (no.17 Apr 2011) | gonzoblog.nl
[...] Is it really necessary to validate the code? – It’s the mania of those who tend to perfection and ...

Great resource, this helped alot. Retweeted!
Great article!
I think validation is important if you want to stick to web standards and follow the “write once, publish everywhere” principle. Certainly, there still are plenty of discrepancies between browsers and how they display content, but I think developers can do their parts by validating their code and making sure it’s written correctly.
Google’s homepage have 36 Errors, 2 warning(s). Is that really important?
http://validator.w3.org/check?uri=www.google.com&charset=%28detect+automatically%29&doctype=Inline&group=0
since when do users online search for google though??
It’s just to make sure it works and looks the same within every single browser.
Both valid and semantic code are as important to SEO as is the content itself, I try and make sure every site I code is both valid and semantic, with some progressive enhancement for older browsers.
I look at the term ”valid code” as something to try to chieve but not something I absolutely must do in order to create a website. At the end of the day, nobody really cares if your html is valid or not, it’s more important that the website has no functional errors and it looks (as much as possible) the same in every browser. And since we still have to use different hacks to achieve that, validation is not too important, of course I’m not talking about obvious errors that could be fixed easily
To be honest, it is 100% important to try to have your code validated. Just as with any programming language, if you don’t write it properly, bugs start to seep through the cracks you are leaving behind – particularly when you go back to modifying prior work. It is a case of “saying what you mean”. Just because some browsers will let you get away with, for example, missing the end tag of a or using upper case to define your tag doesn’t mean it’s OK to do it. Missing an alt attribute in an tag may not affect the display to you and I, but caters for those people who don’t have a visual interpretation of the site such as old mobile phones or those with screen readers. Every standard has a reason, even if it’s not important to us as individuals.
One of the most important reasons for getting it right is SEO. Google’s bots are rather primitive and will ignore parts of the code it doesn’t understand. This can have detrimental effects to your search rankings. I agree that not having any s in a might not be fatal to your website, but the fact remains that it is outside the standards set for XHTML.
I am aware that Google has errors on their own site, and this is pretty poor considering just how simple their landing page is, especially when you take a look at the actual errors, they are basic and they are WAY outside the standards like not encasing the id of a in quote marks. Bad Google!!
Wanted to add that I really like the idea of HTML5, finally something to make our work less complicated so we can concentrate more on actually creating something instead of trying to match sometimes questionable rules.
The right write, praise a.
good post,thank you share it,i like it very much