Sunday 29 July 2012

A Discussion About CSS Reusability



Jul 23 2012
Look at this website layout:
You've probably coded up something like that, right? How many times? A lot? Did you do it from scratch each time?
I think more discussion about front end code reusability is worth having. Theoretically I would think CSS would be some of the most reusable code we have available, but that doesn't seem to be true in practice.
I have more thoughts, but I'll save them for the comment thread.

Subscribe to The Thread

  1. I do reuse some css, but not something as fully-formed as an entire layout. Mostly that’s because I find I can build it better and better each time I do it, as I learn more… but also I feel there’s the trap you can get into of reusing so much code that your sites end up being too similar down in their bones. Each design should be unique, even if they’re made from the same building blocks. I do reuse components all the time.
    • sam.web.dev();
      I agree completely. If I want to make something like a really quick site that will only be in use for a week, I may use Bootstrap or a similar framework. However, if it’s something more important, I will design completely from scratch, maybe implementing past ideas, but never just changing the content.
      About getting better at site design: just for fun, I recently opened up my first website; back then I was so proud of it, but… it is terrible. It has dull colors, isn’t responsive or in any way cool, and it is based entirely on tables, using font tags and outdated standards. Now my sites are better, but I wonder what I’ll think in ten years looking back on them.
    • Same here. Specially the part where you said ” I can build it better and better each time I do it, as I learn more” is exactly my insight into the matter of reusability. although I do maintain some basic structural approach everytime but I prone to write each line from scratch. and this gives me a peripheral concept from the begining to the finishing up codes!
    • Walsh
      OK ! I Have to say that the Discission is Great ! Thank you are.
  2. Beyond normalize.css and a couple of bootstrap attempts, I haven’t reused more then one class at a time. Boy do I wish I could reuse CSS more often, but it never seems to work out that way.
    • Hannes
      Same here.
    • It would be silly not to reuse some components if you are working on a fixed-price project with unreasonable timelines. I keep a library of commonly-used assets, such as a horizontal nav bar with drop downs or a CSS-based table – these can take time to build from scratch so why bother when you can cut, paste and tweak from another project? Of course I am always looking for better ways to do things so I replace those components when I find better options.
  3. I don’t reuse css. I remember practices that I liked from my previous work and implement them in the project i’m working on. Every project I work on usually is different from the one before. I do however find myself reusing JavaScript.
  4. When I know that I’ll be reusing styles (large project, lots of modules), I usually create a Compass plugin so that I can more easily use the styles in multiple projects/workspaces.
    I very rarely copy whole stylesheets, as my Computer Science professors insist that duplicate code is a disaster (and for good reason).
  5. I like to reuse code, but not just blindly as CSS develops and my skills do over time. So I may not always attack a problem the same way each time. But I try not to reinvent the wheel over and over again. But it’s just not reusing CSS, its also JS and backend code as well.
  6. If a developer needs a login function for a website, do they write it from scratch? I bet very rarely. They use an existing project (e.g. a CMS like WordPress) or a modular component to a framework (e.g. a Rails gem).
    What makes back-end so code much more reusable?



No comments:

Post a Comment