Code cleaning
human readable and SEO-compliant
Table of Contents
perché?Why?
Il codice (sorgente) è ciò che, in una pagina web, non si vede. La stessa "apparenza visibile" può provenire da diversi codici-sorgente. Perché allora preoccuparsene? Per vari motiviThe source code is what, on a web page, you don't see. The same 'visible appearance' can come from different source-codes. So why worry about it? For various reasons:
- perché un codice non corretto è in genere un codice ridondante, che appesantisce, talora di molto o di moltissimo, una pagina (quindi ne rende lento il caricamento da parte dei vostri lettori, che giustamente considerano anche questo come un fattore di scadente qualità del vostro sito)because an incorrect code is generally a redundant code, which sometimes weighs down a page (therefore it makes it slow to load by your readers, who rightly consider this as a factor of poor quality of your site);
- perché un codice non corretto può creare difficoltà di interpretazione per i browsers e i motori di ricercabecause an incorrect code can create difficulties of interpretation for the browsers and for Search Engineers;
- perché certe non correttezze del codice, come l'assenza dell'attributo "alt" nel tag <img>, o dell'attributo "summary" nel tag <table> possono impedire a persone in situazione di handicap di accedere alla vostra pagina, ledendo così il valore della accessibilitàbecause certain incorrectness of the code, such as the absence of the 'alt' attribute in the img tag, or of the 'summary' attribute in the table tag can prevent people with disabilities from accessing your page, damaging the value of accessibility;
- ma anche perché utilitaristicamente, voi stessi potreste trovarvi nelle condizioni di dover lavorare sul codice; e lavorare su un codice disordinato e ridondante è decisamente più disperante, che avere a che fare con un codice pulito e ordinato, tale da consentirvi un facile orientamento in ciò che avete scrittobut also from an utilitarian point of view, you yourself could have to work with the code. And working on a messy, redundant code is far more difficult than dealing with clean, tidied code that allows you to easily navigate what you've written..
codice sovrabbondanteOverabundant code
Un esempio di codice pulito e ordinato è quello che, nel caso di identico tipo di formattazione (ad esempio paragrafo con allineamento a destra e in carattere corsivo e di colore grigio) invece di ripetere ogni voltaAn example of clean, tidied code is one that, in the case of the same type of formatting (e.g., right-aligned paragraph, and italic and gray font) instead of repeating each time:
<p style="font-style: italic; text-align: right; color: gray;"></p>
posso creare unayou can set a class (.rightcorsive) e appplicarla tutti i paragrafi che voglio siano formattati in tal modo. È abbastanza sempliceand apply it as many paragraphs as I want to be formatted that way. It's quite simple.
In questo modo risparmio un bel po' di codice e rendo più facile la correzione di qualche fattore che non andasse beneThis saves me a lot of code and makes it easier to fix some factors that don't fit.
Se poi ho molte pagine a cui voglio applicare la medesima formattazione, è ancora più conveniente: creo un unico foglio foglio di stile che collego a tali molte pagine, e quando vario uno stile, tale variazione si applica a tutte le pagineAnd if I have many pages to which I want to apply the same formatting, it's even more useful: I create a single stylesheet that I link to those many pages, and when I vary one style, that variation applies to all pages.