Passa al contingut principal

Judging CSS / Spotting Bad Code

Judging CSS / Spotting Bad Code:
In a recent Q&A article on Smashing Magazine, a question was asked about how to tell if a developer has written bad CSS. Specifically:
What are the signs that the CSS is sub-optimal, or that the developer hasn’t done a good job? What do you look for in CSS to determine how good or bad it is?
I thought that was an interesting question and I'd expound upon my answer a bit.




Why?

Perhaps you've hired someone to write CSS for you and you want to have a gauge of how good they did. Perhaps you're looking through someone's CSS that you may potentially hire. Perhaps you want to gauge your own CSS somehow.

The Obvious Test

Look at the website. If it looks all messed up, then they did a bad job.
Taking that a step further, check it against the browsers you agreed on would be supported. The design should be workable in all of them.
If the design is supposed to be responsive, resize your browser window to ensure the design works no matter what width or height it is.
If everything looks good, that's a good (and required) first step. But it's not absolute proof the CSS is good.

The Formatting Test

Take a look through the authored CSS file. Remember that it's best practice to serve the live website minified CSS (all non-important whitespace removed), so don't look at that.

That's not intended to be read by humans. Look at the file that they actually created.

If you have an established style guide that was expected to be followed, was it followed?
If not, does it look consistent - as if they had a style guide of their own that they adhere to? Or is it a bit sloppy? Sloppy meaning sometimes there is one space after selectors and sometimes there is none. Some blocks of code are indented and others aren't. Single line CSS is mixed with multi-line CSS with no rhyme or reason.
Clean code is the sign of a respectful developer. One who has a respect for the craft and the work they do.

From Nicolas Gallagher's Idomatic CSS

If these first two test pass, that's great. But still not quite proof the CSS is good.

The Selector Test

Those first two tests could be done by just about anybody, but from here out you'll need to have familiarity with CSS yourself. Start reading the CSS and see if what you're seeing makes sense to you.
Do the selectors look rational? If you see a selector like
.article #comments ul > li > a.button {
  /* Crazy town */
}
I'd worry. That is a developer fighting themselves with specificity problems, something good CSS doesn't do.
How are the class names? Understandable? Hopefully you don't find anything like "bigGray" or "left50" as the accuracy of those will be surely be short lived making for confusing future development.
How repetitive is it? For example, if you see the exact same box-shadow applied in 20 disparate places that's probably a sign of lack of refactoring. Good CSS developers sense patterns like that and accomodate them better.

The Size Test

How is the file size of the deployed CSS? 100k would be absolutely enormous for a CSS file. Small is good. Even (especially) on complex sites. Huge files is often a sign of lack of consistency.

The Editing Test

Come up with a style you'd like to change on the site and attempt to change it yourself. For instance, swap the all the fonts in use with other fonts. Were you able to familiarize yourself with the code quickly? Did it feel like there was a plan for how fonts were handled in place? How quickly were you able to do it? Faster or slower than that kind of thing normally takes you?

How do you do it?

Have you ever been in the position to judge other's CSS? Did you use simliar tests? Did you have more defined metrics?
Judging CSS / Spotting Bad Code is a post from CSS-Tricks

Comentaris

Entrades populars d'aquest blog

10 alternativas a Cuevana para ver películas online

10 alternativas a Cuevana para ver películas online : Durante este último tiempo, en Cuevana se sucedieron varios “problemas” por los cuales hubo que ajustar algunas cosas antes de tiempo (como el rediseño del sitio), que dejaron a algunos usuarios ciertos problemas para acceder a las películas o series del portal. Pero realmente esto es algo que no incumbe a los usuarios y, como sabemos, existen muchas otras alternativas a Cuevana dando vueltas por Internet, que intentaremos presentar aquí mismo. Los sitios que repasaremos funcionan del mismo modo que Cuevana, mediante la instalación de un plugin que permite visualizar los videos de Megaupload o WUShare, entre otros servicios, en una calidad de imágen realmente excelente. Tal como sucede con el más popular servicio, todos ellos tienen publicidad que en algunos casos resulta insoportable, pero como dice Federico en DotPod “a caballo regalado no se le miran los dientes”. Alternativas a Cuevana 1. Moviezet Posiblemente el mejor clon d...

Learn Composition from the Photography of Henri Cartier-Bresson

“Do you see it?” This question is a photographic mantra. Myron Barnstone , my mentor, repeats this question every day with the hopes that we do “see it.” This obvious question reminds me that even though I have seen Cartier-Bresson’s prints and read his books, there are major parts of his work which remain hidden from public view. Beneath the surface of perfectly timed snap shots is a design sensibility that is rarely challenged by contemporary photographers. Henri Cartier-Bresson. © Martine Franck Words To Know 1:1.5 Ratio: The 35mm negative measures 36mm x 24mm. Mathematically it can be reduced to a 3:2 ratio. Reduced even further it will be referred to as the 1:1.5 Ratio or the 1.5 Rectangle. Eyes: The frame of an image is created by two vertical lines and two horizontal lines. The intersection of these lines is called an eye. The four corners of a negative can be called the “eyes.” This is extremely important because the diagonals connecting these lines will form the breakdown ...

Más de 50 de las mejores herramientas online para profesores

No es una exageración afirmar que hay ciento de aplicaciones educativas por ahí por la red, para todos los gustos y de todos los colores, por lo que es difícil tratar de recogerlas todas en un listado. Sin embargo, algunas destacan más que otras por su innovación y por su capacidad para conseguir adeptos, y esas son las que protagonizan la presente recopilación. Son 50 interesantes herramientas online basadas en las recopilaciones de EduArea , las muchas ya tratadas en Wwwhat’s new y las destacadas por la experiencia. 1. Dropbox : Un disco duro virtual con varios GB gratuitos y al que se accede desde casi cualquier dispositivo. Sin embargo, es muchísimo más que eso, de hecho ya comentamos 20 razones . 2. Google Drive : La evolución de Google Docs que suma a sus múltiples herramientas de creación de documentos, un considerable espacio virtual gratuito. 3. CloudMagic : Una extensión y una app multidispositivo para buscar información simultáneamente en Gmail, Twitter, Facebook, Evernote ...