Live data from Hacker News

CSS: Our best practices are killing us

slideshare.net

21–30 of 54 posts

Re: CSS: Our best practices are killing us

#21
post #9
post #6

I hate asking to be spoon-fed, but I find it exceptionally difficult to glean anything from context-free slide decks posted to SlideShare. This deck was clearly intended to augment a presentation -- where is that archived?

Probably this one: http://www.webstock.org.nz/talks/speakers/nicole-sullivan/cs... I attended the talk and the workshop. What is interesting is that it genuinely challenges. Some CSS designers who I really respect did not 'buy in' to her theory even after spending a day with her. However, as a programmer, who has since used the OOCSS in a context 'for real' I found that it does live up to its promise in practice (unl…

Yep, it's this one.

I apologize to others for the lack of context that the slide by itself gives. I got the summary of this talk from a co-worker who actually went, so I had the context in back of my mind. The slidedeck naming is still too sensationalist though for what it's actually about: over time, css gets degraded because developers get into a firebug-hack mentality leading to overwrites by specificity until it gets too big and messy to maintain. I'm still not too clear what she's proposing as a solution to this though; she does give an example of her success at facebook, but that example is a one-time fix, not necessarily a practice that stands on its own over time.

Re: CSS: Our best practices are killing us

#22

per the slideshow, 3 "best practice myths": - don't add any extra elements - don't add classes - use descendent selectors exclusively the second two i've never heard in my life, and i'm quite sure the first is not a myth.

she's referring to "classitis": http://www.sitekin.com/blogdetail/avoid_CSS_Classitis

in that example, classitis is when you give a class "item" to every li element, the using .item to style it while the alternate way to do it is using the descendent selector (.parentcontainer li). Nicole Sullivan is saying this can lead to specificity war over time.

Re: CSS: Our best practices are killing us

#23
post #11

My main rule is: Never write a class that you can't use again. I've other rules too, such as "padding is top, margin is bottom". CSS must be modular, not exception-based.

That's interesting. I've always wondered if some people had conventions on when to use padding and when to use margin, since you can almost always accomplish the desired effect either way.

Re: CSS: Our best practices are killing us

#24

per the slideshow, 3 "best practice myths": - don't add any extra elements - don't add classes - use descendent selectors exclusively the second two i've never heard in my life, and i'm quite sure the first is not a myth.

By "don't add classes", she means "avoid using redundant or non-semantic classes in the HTML", which makes sense, because unless you're generating the HTML on request or compensating with jQuery (and therefore adding another dependency to your layout), the repetition becomes a maintenance issue.

Avoiding non-semantic elements and non-semantic classes, however, restricts you to using descendant selectors (and multiple declarations), which, as she points out, creates another maintenance issue in the form inheritance conflict resolution (specificity).

Re: CSS: Our best practices are killing us

#26
The solution is not to codify best practices; the solution is to use a better language! (This coincides with PG's argument for lisp/macros)

Although the slides do mention sass an lesscss at the last side, I think 'stylus' is a much better css language.

http://learnboost.github.com/stylus

IT has powerful abstraction facilities in the form of functions and mixins.

Here's an example of how powerful it can be:

  vendor(prop, args)
    -webkit-{prop} args
    -moz-{prop} args
    {prop} args

  border-radius()
    vendor('border-radius', arguments)
Having this abstraction, we can:

  button
    border-radius 1px 2px / 3px 4px
And the output will be:

  button {
    -webkit-border-radius: 1px 2px / 3px 4px;
    -moz-border-radius: 1px 2px / 3px 4px;
    border-radius: 1px 2px / 3px 4px;
  }

Re: CSS: Our best practices are killing us

#27
After watching the presentation I agree that CSS has major issues with reusability and code cleanliness. Though I don't think it's as bad as she makes out; I don't know any developer who refuses to use classes.

I think the approach she takes to solve the problem is wrong though. HTML and CSS like her OOCSS approach promotes is just nasty.

    
    
How is coding the layout into the HTML any different from the table based layouts we were doing ten years ago? This is going back to tying your styling directly to your HTML.

Bringing mixins into CSS would solve this in a much nicer way. Define your fonts and columns in a couple of reusable mixins, and then define your site-specific content mixing and matching your reusable components.

Re: CSS: Our best practices are killing us

#28
post #11

My main rule is: Never write a class that you can't use again. I've other rules too, such as "padding is top, margin is bottom". CSS must be modular, not exception-based.

That's interesting. I've always wondered if some people had conventions on when to use padding and when to use margin, since you can almost always accomplish the desired effect either way.

You can't really. CSS backgrounds are the main reason you need to use padding (instead of margin): margins exist outside an element, while padding expands within the box itself (beyond the content, but permitting the background to remain visible).

To visualize it, http://hicksdesign.co.uk/boxmodel/ is probably the most oft-cited example - certainly the one I find most helpful.

Re: CSS: Our best practices are killing us

#29

The points brought up in these slides directly reflect my experiences over the past 3 years of doing my own CSS. If you're familiar with the CSS precedence rule, these slides might read like blog post; they did for me. Strangely, I rarely see the precedence rule brought up in CSS documentation or tutorials. Not until I read "The Ultimate CSS Reference", by Tommy Olsson & Paul O'Brien. I highly recommend this book. "C…

The problem with having repetition in your compiled CSS files is that they become bigger as a result. Depending on how much you care about page load speed, this can be an issue.

I'm not entirely sure what she's suggesting since I'm reading the slides without any context, but it seems, given the thing about cutting down css file size for Facebook, the method she's suggesting reduces duplication in the actual css file.

Re: CSS: Our best practices are killing us

#30
post #10

She says we shouldn't blame the language, but how much of this is because CSS eschews Composition for (incomplete) Multiple Inheritance? And how much of the extra code is an effort to avoid bugs because layout properties are non-orthogonal? At what point do we decide that it's not that "you're doing it wrong", but that there were actually some design choices that, in retrospect, maybe weren't such a good idea? I'd sa…

"much of this is because CSS eschews Composition for (incomplete) Multiple Inheritance?"

Pretty much all of it. I remember being a bit surprised when they first released CSS at just how impotent it was. Over a decade later, I now realize my younger self would have gotten himself stuck in a morass of Turing completeness, but CSS goes too far the other direction.

Decoupling styles (which may contain several rules) from matchers, then allowing a match to apply multiple styles, and permitting simple variables (which I would be OK with restricting to simply "either a single variable or a single string" and not permitting concatenation or anything complicated) would have not significantly increased the complexity, avoids the Turing Tarpit [1], and would have been powerful enough that while the other languages would still have inevitably have emerged eventually they wouldn't have been necessary.

HTML had enough pragmatism in it from day one to survive being academicked. CSS is a classic example of how a beautiful theory can back you into a corner and everyone's too busy chanting the beautiful theory's mantra to notice they're doing it in a terrible way.

("You Must Decouple Content From Presentation." "That's a great idea, but don't you think that we should have something like a variable that represents a color?" "You Question The Value Of Decoupling Content From Presentation." "No, it's just that anybody with a couple of years of experience programming knows that you shouldn't hard-code constants into your files, let alone do it fifty times in a single file." "This Is Declaration, Not Code." "There's no difference; spend some time with Lisp." "You Will Burn For Doubting The Decoupling Of Content From Presentation, Heretic. A Thousand Curses On Your Websites." I've had this conversation a few times, though mercifully it has been a long time now.)

(Oh, and if you want to blow someone's mind, ask them why it's so important to decouple content from presentation. I'm sure some people here can at least articulate a reason but in general people can't, it's just a mantra. Then the mantra answer became "Semantic Web", but then try to get a definition of Semantic Web out of them... and if you get that far, ask where the semantics come from. There's been a staggering amount of what is nearly religion surrounding CSS and it shows in the engineering. Oh, and don't suggest that as long as your content is stored cleanly somewhere, it's OK to apply styles in another layer on the server... if it's not CSS, it's not Semantic and it's not Decoupled. Regardless of the actual architecture behind it.)

[1]: http://en.wikipedia.org/wiki/Turing_tarpit

Post reply on HN