refactoring  

My project this week has been a refactoring of a massive CSS file, which has to override a mountain of inherited garbage in a CMS that can’t be touched. More precisely, something like 3000 lines of CSS in no less than seven stylesheets are coming at every page and I’m cleaning up nearly two thousand more lines of code that are inline overrides. On every page.

Where to start?

Can’t change any of the source of the page, nor anything in the inherited stylesheets. So that means rolling with inheriting things like #id > .class .class:hover and just having to fight fire with fire. It’s a great puzzle, no? Did I mention that this definitely hits the invisible walls with IE of maxiumum number of declarations?

While thinking this through, the most radical approach I considered was this: taking every selector that, for example, sets a margin to zero and making a mega comma-delimited list of those. Doing CSS backwards. Making lists of selectors for each and every style. I dismissed that idea, for now, but want to try doing something awful like that. for fun.

What I did was this: I pasted all those inherited stylesheets into a single .SCSS stylesheet. (Did I mention they’re all formatted and minimized differently?) And then I made a .SCSS file with the whole of the inline styles I can refactor and included the inherited .SCSS — in the compiled output CSS file, I could at least start to search the whole thing to figure out what the overrides were actually overriding, and whether they were at all redundant.

Another big benefit to doing this as SCSS instead of CSS was the two types of commenting: /* ... */ (which carries through to the compiled CSS) and // ... (which doesn’t) — being able to make internal notes about what might be changed before making those changes.

In that first major file, it looked like the earlier styles were mostly redeclaring basic resets and resetting some custom formatting classes (.n3, .n3, .n5 ??), so I pulled those out into their own 1-KNOCKOUTS.SCSS file and included that with SASS.

Geologically speaking, it also looked like the big stylesheet had two major chunks of work followed by a bunch of small patches. I pulled those three areas into their own .SCSS files which left my main .SCSS file with five includes and a bunch of visual commenting blocks to separate them: 0-INHERITED, 1-KNOCKOUT, 2-INITIAL-LAYOUT, 3-LAYOUT-UPDATES, 4-SPECIAL-FIXES.

Something like:


/**********************************************/
/* 0. INHERITED STYLES FROM CMS               */
/**********************************************/
@import "0-INHERITED";

/**/
/ 1. KNOCKOUT STYLES TO OVERRIDE INHERITED /
/**/
@import "1-KNOCKOUT";

Doing a CSS Lint, I found some bugs in the inherited styles, so I made corrections as new declarations in the 1-KNOCKOUT file, before the resets and overrides. For example, if a semi-colon had been missing on a .class { font-weight: 7px border: none; } then I added a .class { font-weight: 7px; border: none; } chunk before the html,body {} part of the reset, just to be safe. Also it frankly felt good to spike the ball on some inherited bugs.

Anyway, with those SCSS containers, I bulked up the visual style of the comments in 2- & 3- and made them more consistent, combining the two into one 2-LAYOUT.SCSS file. How? By changing the SASS compilation format from “Expanded” to “Compact” it was much easier to see the /* ... */ formatted comments and decide on a style that was legible: lines of dashes above and below breadcrumbs that explain what types of modules the styles modify. Fortunately the author of the styles to be refactored left solid comments and organized the files well.

For the later 4-SPECIAL-FIXES file, I first looked in the project history for the bugs they were addressing and the test pages. I added those test pages with //-style comments like

 // cf: /section/page123

Then, I looked for places they could be better folded into the LAYOUT styles, swapping in the new styles and testing on the test pages. Given the options, I was surprised to find so much benefit from cleaning up the overall formatting and commenting, but the code feels more approachable and more likely that subsequent patches will be added in the upper-middle of the stylesheet instead of tacked on at the end.

CSS is, for real, my favorite fun.

Ads Topics  

Before deactivating my Facebook account, I downloaded my archive from them. Under the Ads tab was a list of the keywords by which—if I understand correctly—I’m targeted.

  • #Antony and the Johnsons
  • #Joseph Campbell
  • #CocoRosie
  • #Hamburger
  • #Depth of field
  • #Recording studio
  • #Saturn
  • #Wood
  • #Siddhi
  • #Hawthorne, California
  • #Male prostitution
  • #Screaming (music)
  • #Zebra
  • #Madagascar
  • #Pirates of the Caribbean: At World’s End
  • #Explosions in the Sky
  • #Digital Public Library of America
  • #Steve Blank
  • #Jonny (band)
  • #(Le) Poisson Rouge
  • #Teen Wolf
  • #Northern Spy
  • #RSS
  • #Multiverse
  • #Limited liability company
  • #Farrar, Straus and Giroux
  • #Flux
  • #Joseph Gordon-Levitt
  • #A List Apart
  • #Joe Biden
  • #Pussy Riot
  • #Flux (software)
  • #Daniel Handler
  • #University of Virginia
  • #Digg
  • #IFTTT
  • #Lady Lamb the Beekeeper
  • #Random House
  • #Quilt
  • #Stephen Elliott (author)
  • #The New York Review of Books
  • #Mary Birdsong
  • #Lemony Snicket
  • #Light industry
  • #F.lux
  • #Jeffrey Zeldman
  • #Cabinet (government)
  • #Hacker (computer security)
  • #Canopy (biology)
  • #Metropolitan Museum of Art
  • #Stephen Colbert
  • #Mansion
  • #Mary Harris Jones
  • #Broadcasting
  • #ROFLCon
  • #Sarah White
  • #City
  • #Structure
  • #Gigantic (magazine)
  • #Brynocki
  • #Electric guitar
  • #Creative Commons license
  • #Photography
  • #Housing Works
  • #Anthology Film Archives
  • #Antony Hegarty
  • #Devon Sproule
  • #Coloring book
  • #Book series
  • #Barack Obama presidential campaign, 2008
  • #Funk
  • #Pencil
  • #Walid Raad
  • #Wholphin (DVD)
  • #Mörel
  • #Maker Faire
  • #Oral history
  • #Caravaggio
  • #The Metamorphosis
  • #CASH Music
  • #Gregor Samsa (band)
  • #Brian Viglione
  • #Application software
  • #Drawn and Quarterly
  • #Tibetan art
  • #Island Records
  • #Oregon
  • #The Garage (nightclub)
  • #George Washington (film)
  • #SPECTRE
  • #Book
  • #Eyebeam Art and Technology Center
  • #Casey Dienel
  • #Open City (magazine)
  • #New York City
  • #Robot
  • #Photographic fixer
  • #Talking Heads
  • #Boing Boing
  • #David Byrne
  • #Safari Books Online
  • #WTJU
  • #National Lawyers Guild
  • #Clothing
  • #Novel
  • #Harper’s Magazine
  • #Nicanor Parra
  • #Art
  • #Literature
  • #Motel
  • #Reading (process)
  • #Adama
  • #Brooklyn
  • #Harvest
  • #Marcel Duchamp
  • #Invisible hand
  • #Make (magazine)
  • #Kora (instrument)
  • #Paul Hanley (tennis)
  • #Postcard
  • #Chaos magic
  • #Triple Canopy (online magazine)
  • #Syzygy (astronomy)
  • #Jem Cohen
  • #House
  • #Qualia
  • #Xeni Jardin
  • #Maru (cat)
  • #Tunde Adebimpe
  • #Sharon Van Etten
  • #Coffee
  • #ITF Men’s Circuit
  • #Creative Time
  • #Nervous system
  • #Julian Assange
  • #Film
  • #Creative Commons
  • #Flipboard
  • #Radiohead
  • #Dharma Mittra
  • #Graffiti
  • #Shea Stadium
  • #Facebook
  • #Event horizon
  • #The Spirit of the Beehive
  • #The Georgia Review
  • #Impossible Project
  • #Lawrence Weschler
  • #White
  • #Columbidae
  • #Magic (paranormal)
  • #Record label
  • #Cooper Union
  • #Ian MacKaye
  • #Talent agent
  • #Duke Riley
  • #Renegade (TV series)
  • #Dungeon Keeper
  • #My Drunk Kitchen
  • #Rookie
  • #Benjamin Smoke
  • #Buckminster Fuller
  • #Harbor
  • #Word
  • #Goodiepal
  • #Smoke signal
  • #Mercedes-Benz
  • #Medicine
  • #Music
  • #DVD
  • #Mister Lonely
  • #Sub rosa
  • #Buenaventura Press
  • #Sigur Rós
  • #Dalkey Archive Press
  • #Naturopathy
  • #Temporary Residence Limited
  • #Sugar
  • #Jewellery
  • #News
  • #The Morning News (online magazine)
  • #J&L Books
  • #The Brooklyn Rail
  • #Ploughshares
  • #Cowbell (instrument)
  • #Harry Everett Smith
  • #Great White
  • #Neil Gaiman
  • #Bushwick, Brooklyn
  • #Trouble (band)
  • #Esopus (magazine)
  • #Electronic Frontier Foundation
  • #Lungfish (band)
  • #Sewing
  • #IPhone
  • #Gaia (mythology)
  • #Big Freedia
  • #Blog
  • #Aperture Foundation
  • #Culture
  • #Miranda July
  • #Zebulon, North Carolina
  • #Kill Rock Stars
  • #Drum
  • #Lightning Bolt (band)
  • #Acre
  • #Jack Gilbert
  • #Traditional Chinese medicine
  • #Ben Lerner
  • #Brendan Fowler
  • #Mike Brodie
  • #Gummo
  • #Jen Bekman Gallery
  • #Archive
  • #Jónsi
  • #Extraterrestrial life
  • #Youth Lagoon
  • #Blue Velvet (film)
  • #Cult image
  • #I Break Horses
  • #Type system
  • #Dark Dark Dark
  • #Eardrum
  • #Social Networks
  • #Dropbox (service)
  • #Bill Daniel (filmmaker)
  • #New Directions Publishing
  • #Restrepo (film)
  • #K Records
  • #Lemony Snicket’s A Series of Unfortunate Events
  • #Riffle
  • #Dalai Lama
  • #Infant
  • #Long Now Foundation
  • #Jolie Holland
  • #Virginia Center for the Creative Arts
  • #Fantagraphics Books
  • #Zine
  • #Alejandro Jodorowsky
  • #Artist’s proof
  • #UbuWeb
  • #New York
  • #School
  • #Hurray for the Riff Raff
  • #Movie theater
  • #Virginia
  • #MIT Press
  • #The So So Glos
  • #Readercon
  • #Aperture (magazine)
  • #Team Gallery
  • #Awareness
  • #Lucky Dragons
  • #Social order
  • #Experiment
  • #Art museum
  • #Woman
  • #Atoms for Peace (band)
  • #Museum of Jurassic Technology
  • #Barack Obama
  • #Magazine
  • #Austra (band)
  • #Jerry Saltz
  • #Sukiyaki Western Django
  • #Swoon (artist)
  • #Amanda Palmer
  • #Art history
  • #Future of the Left
  • #New Orleans
  • #Lapham’s Quarterly
  • #Lauren Hoffman
  • #McNally Robinson
  • #Paper
  • #McSweeney’s
  • #Chicken John
  • #Lemonade
  • #Bowing
  • #Drum machine
  • #Bookselling
  • #Fight Club
  • #Rubin Museum of Art
  • #Dischord Records
  • #Frick Collection
  • #Futures contract
  • #Public university
  • #Wax
  • #The Believer (magazine)
  • #Cheryl Strayed
  • #Oyster
  • #3D printing
  • #Café-chantant
  • #Sheila Heti
  • #Hauschka
  • #Illustration
  • #14th Dalai Lama
  • #Studio
  • #Publishing
  • #Video Data Bank
  • #A Series of Unfortunate Events
  • #Arthur (magazine)
  • #Internet Archive
  • #Laughing Squid
  • #Conspicuous Service Cross (Australia)
  • #Mother Jones (magazine)
  • #Rush Limbaugh
  • #Desert island
  • #New York Foundation for the Arts
  • #WikiLeaks
  • #Musical ensemble
  • #Kickstarter
  • #Caravaggio (film)
  • #ScholarMatch
  • #Light Asylum