3 ms·
I am definitly for names, and good names at that! Names are placeholders for a bunch of logic that you might not want to care about in the moment. Without read
by nicbou 2y ago
I am definitly for names, and good names at that! Names are placeholders for a bunch of logic that you might not want to care about in the moment.
Without reading any code, you can tell what "inputToFocus", "postalCodeIsValid" and "daysToEarliestAppointment" mean. Then you know what this variable represents in the real world, and also what your code is operating on.
I also prefer CSS class names that describe what the object is (".alert-box.warning" or ".button.primary"), and not what it should look like. I don't like updating dozens of templates because I want to change how some things look across the website. I know that I won't forget to update one and create a hard-to-find bug.
- cxr 2y agoThe class attribute from HTML has about as much to do with CSS as the id attribute. Those "CSS class names" are just HTML classes. They were invented for HTML, you write them in HTML, and they're part of the HTML spec. It's become evident from comments on HN recently that people apparently think they're a CSS thing (because that's how they're taught CSS) but they're just an ordinary fixture of markup; they're for describing the class of something. Accordingly, stuff like class="alert-box warning" is the correct way to use classes (rather than e.g. class="3px-red-border" or whatever).
- nicbou 2y agoDo they have any other purpose besides CSS though? They were even hard to use as selectors in JS until querySelector appeared.
- cxr 2y agoI'm not sure you're grokking what I'm saying. The answer to your question is "yes, of course". The class attribute has _nothing_ to do with CSS (or JS). The CSS people didn't give us the class attribute (and the HTML people didn't put it in so that we could use CSS better). HTML had class attributes before CSS or JS ever existed.