DEV Community

Cover image for Naming things is hard. Agree or disagree?

Naming things is hard. Agree or disagree?

James Thomson on May 01, 2019

I've been a web developer for 10+ years now, mostly on the front-end, and I still find it difficult to name CSS classes, especially as a project gr...
Collapse
 
juanfrank77 profile image
Juan F Gonzalez

I'd say that naming things, regardless of the language, has to be one of the hardest things in computer science.

Collapse
 
gabrieltoma profile image
Gabriel Toma

I'll break the pattern and I'd say that naming things isn't that hard at all. Yes, sometimes it may be hard to find the right name for a CSS class, for example, but I always figured it out like this:

Ask these 3 questions:

"What is this class for?"
"What is its purpose?"
"Why I made it?"

Now find out the core answer and voila, you made it!

Collapse
 
eavichay profile image
Avichay Eyal

Get rid of bem. Naming would be easier when using aria tags with css. Bem is overestimated and an overweight for both bundle and runtime.

Collapse
 
jamesthomson profile image
James Thomson

Naming would be easier when using aria tags with css.

Care to expand on this?

Collapse
 
eavichay profile image
Avichay Eyal

Sure.
I tend to use semantics and autotags for automation. Meaning I have maximum 3 nesting rules to define an element style and it does not break when I change the structure or doesn't break hard when replacing css framework.

Example css:
[settings-view] [role=submit-button] { width: 3rem; }

This replaces the bem part and overrides default rule set including framework values

Collapse
 
eavichay profile image
Avichay Eyal

Soon I will publish a post about this approach, meanwhile you can view the draft here eavichay.svbtle.com/preview/rfmQb8...

Thread Thread
 
jamesthomson profile image
James Thomson

That's great Avichay 👍 be sure to let us know once the final version is published.

Collapse
 
sanidz profile image
sanidz

As you stated yourself, problem is not that common in Frontend because of Feature Modules approach and narower scope, but if you ever open complex backend codebase that deals with CQRS and other patterns or implement Custom Framework than big problems arise with and from naming.
Custom Frameworks tend to use generics and interfaces a lot and rather sooner than later Keywords such as Implementation, Mapper, Reader, Action, Model, Factory, Subscriber, ServiceChannel, Set, Result... (name it based on domain and technical usage) will become useless and not clear.

How to avoid it, define your domain (DDD) early on and stick with it. PERIOD.
Make everyone use agreed upon names and even if your names are long they will make sense and will be uniformed.
Discouss names for new classes with your team regularly and pick best options :)

Collapse
 
inkdeep profile image
Jeremy Kleindl
Collapse
 
jamesthomson profile image
James Thomson

haha. yep! I often think of that quote when I get stuck naming something

Collapse
 
iamschulz profile image
Daniel Schulz

I like BEM for it's structure and still use it in combination with scoped CSS in Vue, but it works without scoping as well.
Think of your component as the block, then structure down from there and keep it as simple as possible. If you run into naming problems, your component might be getting too big.
Do you use a design system or build your app from scratch?

Collapse
 
jamesthomson profile image
James Thomson

That’s pretty much how I work as well, except for the scoped css in Vue. My components stay small, but the issue becomes that I have the need for so many components I run out of names for the various types. I should note that I don’t really work on your standard Dashboard UI, those components are easier to name. I work on quite creatively driven mockups (think games) that the components aren’t immediately obvious as to what they are. To give insight my current project has over 100 unique Vue components (though a handful are HOCs).

App(s) are built from scratch.