Hacker News new | ask | show | jobs
by iamben 3732 days ago
You're arguing for the sake of it- it was just a bad example. If $red was $leadcolor or something similar, you can define it at the top, comment it to explain what it is, then change it across the whole site in 10 seconds (including the borders which are defined as variables 5% darker and lighter) when the client says "I like it, but the red needs to 'pop' more, do you know what I mean?"
1 comments

I'm not, I have seen code like this where a variable is named after its value when created and then colours swapped out later.
So you are arguing against variables in any programming language.

    int one = 2;
You can write bad code in any language, as the saying goes.

However, I've seen projects with a few CSS variables defining the base colours for their scheme and perhaps some tints and shades, and then a second layer of variables defined in terms of the base ones but with more role-based names like heading text colours and focused primary button backgrounds and so on. It's a simple, practical model that has proved very easy to work with and in some cases has stood the test of time for quite a few years now.