Live data from Hacker News

CSS: Our best practices are killing us

slideshare.net

41–50 of 54 posts

Re: CSS: Our best practices are killing us

#41
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?

I much prefer reading an essay or watching a presentation to reading a slide deck. I suspect I'm not the only one.

Re: CSS: Our best practices are killing us

#42
post #38

Earlier quoted context omitted.

I liked the presentation, she clearly knows CSS well, but do count me amongst those that did not buy in to her theory. I've seen plenty of horrific stylesheets and seen some that over time turn into incomprehensible messes, but I didn't see in this presentation any real connection from follow best practices, result in unmaintainable CSS. It just doesn't follow. That some coder come-lately can get in there and instead…

I think it comes down to a workflow thing - the reason the coder-come-lately comes in and messes with css in such an annoying way is because its just scary as heck to 'refactor' css in a way that you can be confident about (ie the exact opposite of working with good application level code, with good test coverage).. So, let's say you (or your team) is tasked with 'add a new calendar widget to the right column'. What…

I agree with you for the most part, with one exception. Your workflow is modelled on a hypothetical developer who does markup and backend code, and a CSS guru who does the styling. This approach doesn’t work for the reasons you give, but everything becomes a lot easier if you rejig the responsibilities into:

a) back-end developer who provides the controller, model and a shell view (this could be anything from a basic HTML structure through to raw JSON)

b) front-end developer who has responsibility for building sane markup and clean CSS. It’s in their best interests to keep the styles maintainable: a little extra time writing markup that integrates into the existing styles and refactoring existing CSS to cope with the new modules is worth it in the long run.

Re: CSS: Our best practices are killing us

#43
post #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…

CSS3+HTML apparently is Turing complete: http://lambda-the-ultimate.org/node/4222

Re: CSS: Our best practices are killing us

#44
It's at times like this when I think that we should seriously reconsider the current browser model. We've reached a point where there's a lot of complexity in the system and we're mostly paying lip service to the original idea of presentation-independent content. And the vestiges of that idea are keeping us back.

If you want something accessible with a "modern" JavaScript-based web application, you're almost bound to rewrite most parts of the interface for a pure HTML version, if at all possible and/or desirable. Quite often less effort than jumping through hoops to have something that degrades gracefully.

Now I think this will only get worse. At one point in time, it might be better to regard HTML as the Gopher of its time and consider a next step. Probably won't ever happen, as the sheer ginormous size of the "legacy" web makes any endeavors in this direction almost futile.

Does anybody remember PostScript-based GUIs? We're throwing a lot of barely-connected ideas and syntaxes into a browser to emulate NeWS/DPS -- poorly.

Re: CSS: Our best practices are killing us

#45
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.

If you want to be modular, you must have conventions. This is to prevent double spacing when you put two elements one next to another without additional styling. I also use to have ELEMENT > *:first-child {padding-top: 0} on containers, so that I can control the padding of the container and without having to consider what element I place into it. There's a lot of best practices I made part of my workflow, perhaps I should write a blog post about it.

Re: CSS: Our best practices are killing us

#46
post #28

Earlier quoted context omitted.

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.

Ok, I was talking about transparent elements, where in fact you have complete choice (at least if you have no borders too).

Re: CSS: Our best practices are killing us

#47
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.

Another best practice I have is to place a comment on each closing element, referring to the opening one. So,I have: CONTENTCONTENTCONTENT

When you have complex pages, with several nesting levels, this can save much, much time.

Re: CSS: Our best practices are killing us

#48
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?

We have a page for it on Lanyrd: http://lanyrd.com/2011/codeconf/sdmwx/ which links to these notes: http://jeffremer.com/codeconf2011/codeconf2011-day2/2011/04/...

Re: CSS: Our best practices are killing us

#49
post #38

Earlier quoted context omitted.

I liked the presentation, she clearly knows CSS well, but do count me amongst those that did not buy in to her theory. I've seen plenty of horrific stylesheets and seen some that over time turn into incomprehensible messes, but I didn't see in this presentation any real connection from follow best practices, result in unmaintainable CSS. It just doesn't follow. That some coder come-lately can get in there and instead…

I think it comes down to a workflow thing - the reason the coder-come-lately comes in and messes with css in such an annoying way is because its just scary as heck to 'refactor' css in a way that you can be confident about (ie the exact opposite of working with good application level code, with good test coverage).. So, let's say you (or your team) is tasked with 'add a new calendar widget to the right column'. What…

Are you, basically, referring to CSS grid frameworks ?

Even if you are not - dont they accomplish the same thing ?

Re: CSS: Our best practices are killing us

#50
post #47
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.

Another best practice I have is to place a comment on each closing element, referring to the opening one. So,I have: CONTENTCONTENTCONTENT When you have complex pages, with several nesting levels, this can save much, much time.

Isnt there a danger that someone else working on your code might not respect that rule (or dare I say it, but maybe you're in a rush one day) and you don't update the comment when you update the class.

Now you've got comments saying in correct things, and you risk all sorts of confusion.

The same rule applies to commenting methods in code really, you don't comment what the code does exactly - just what the intention of the code is.

Post reply on HN