5 ms·
Why "We use hyphen delimited, lowercase selectors: .thisIsBad{}, .this_is_also_bad{} but .this-is-correct{}"? I understand if the point is about the styles itse
by iaskwhy 15y ago
Why "We use hyphen delimited, lowercase selectors: .thisIsBad{}, .this_is_also_bad{} but .this-is-correct{}"? I understand if the point is about the styles itself having hyphens, like padding-bottom, but it breaks the complete expression selection with ctrl+arrows (or even with the double mouse click) which I find much more annoying than using underscores instead of hyphens. I'm biased though, I prefer underscores to camelCase anytime (I do obey whatever is the rule on any project).
- csswizardry 15y agoNo reason other than that is what I started off with and I’d rather keep things consistent. Had I started off with underscores then I’d be asking the team to stick with that. I guess that section is more about ‘keep everything the same’ rather than ‘we must specifically use hyphens’ :) Cheers, H
- bung 15y agoI recently brought this up with my own team after updating a 4-language piece on a project. It was originally pieced together at different times and was inconsistent. However, I was testing the waters with them trying to sell them on underscores. We've all been using dashes in CSS for so long, but nowadays I personally feel like I'm writing so much JS that I'm longing for underscores. Downsides: 1. You have to press shift a lot more when writing css 2. ??? Upsides: 1. You can use the "same_name" in CSS and JS 2. You can double-click easily Feel free to expand on this, we haven't made the change, it's just something that crossed my mind recently :)
- MatthewPhillips 15y agoUnderscores in JavaScript are non-standard too.
- edd 15y agoThe reason I would advocate using hyphens is you should do what the language (standard libraries) do. For example: css: margin-left, border-bottom (hyphenate) javascript: getElementById, documentNode (lower camel case) ruby: each_index, has_key? (underscore)
- iaskwhy 15y agoThis would be an interesting discussion. I prefer to use the same coding style for the whole project without caring how the original authors of each language did it. I do however understand that the language API follows the original convention so one would eventually break it by following by reasoning. Ex in js: make_element_slide(getElementById('box')).