Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Well I found at least one good use for them.

I'm writing a book and I use nothing but the CSS color names in all of the examples. I think it makes the code snippets easier to parse and visualize as a human when you're reading through the text. For example:

  // Create a vertical gradient going from the top of the canvas to the bottom
  var gradient = ctx.createLinearGradient(0, 0, 0, can.height);
  gradient.addColorStop(0, 'Black');
  gradient.addColorStop(0.15, 'Black');
  gradient.addColorStop(0.2, 'DarkSeaGreen');
  gradient.addColorStop(0.4, 'DarkSeaGreen');
  gradient.addColorStop(0.7, 'Goldenrod');
  gradient.addColorStop(0.8, 'DarkOrange');
  gradient.addColorStop(1, 'GhostWhite');
Then, as I spend a paragraph talking about color stops, I can refer to real color names and not #00000, #8FBC8F, etc. I think the humans reading the text will appreciate it, but we'll see!


If you’re referring to these by strings, wouldn’t you be just as well off spending a few lines of code somewhere above setting up some variables for hex colors? This seems like a pretty trivial kind of advantage.


What if he were writing straight CSS, though? No possibility for variables there. (Not yet, at least.)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: