DEV Community

Discussion on: Do you still use IDs for unique elements?

Collapse
 
urielbitton profile image
Uriel Bitton

So use what? just tag names and pseudo-selectors? It makes it much harder though

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Did I say you shouldn't ever use class- and id-selectors?

Most CSS I see has things like .some-wrapper-class and then .some-wrapper-class-child. My point is that you should write .come-wrapper-class>* instead, which is both more readable and more maintainable.

I'm not against naming. I'm just saying if you can, you should prefer describing.

Thread Thread
 
urielbitton profile image
Uriel Bitton
  • operation is a very costly operation in terms of performance, so i would refrain from using it. ALso its not very friendly, what if you want to target only certain children? I dont agree with this approach at all. I think naming is very good and not going away any time soon.
Thread Thread
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️ • Edited

Found a nice article that confirms what you said. The best part is the conclusion:

Is all this really necessary? — The short answer is; probably not.

Or, to throw a very well-known quote at the wall

We should forget about small efficiencies, say about 97% of the time: premature optimisation is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.

We live in 2020. Browsers have magnificent benchmark tools that can help us find bottlenecks, and yes, of course we should give up good style if we can significantly improve performance. But that doesn't make it a good "default style" to start coding.

When I write some code to handle data I don't do manual CSE or Loop Fusion either, because it creates an unreadable mess. When a bit of hot code runs too slow, I then optimise it. Same with CSS, except I don't usually even write nearly enough CSS for it to start slowing down a site.