What about adding best practices for file naming? I have recently been struggling with it a bit and went with all lower-case for my recent projects.
The most common practice I think is to have the name of the file reflect the javascript function or class name that is being exported. But I believe the filesystem should be seen as a separate domain from code. Especially since some OS implementations are case insensitive by default, like Mac OS.
This can lead to problems because code executing fine on Mac OS might break on Linux or Windows systems, because there is a mistake in some casing. Then when you try to correct it, git (by default) doesn't see the change in filename. So you end up renaming it twice.
I went with kebab-case-naming and I am very happy that I never have to think about a filename anymore, but I still have a bit of a hard time convincing other people that it is a good idea. The kebab style seems to be the standard in NPM module imports, so to me it makes sense to keep it consistent across the whole codebase.
The only downside I can think of is that it is now not always apparent from a filename if it contains a class or a function. But by structuring files in components (like the guide suggests) and choosing names carefully, this hasn't been any issue for me so far. Also I work a lot with React and Typescript, and then the jsx/tsx and js/ts file extension already gives you a better idea what kind of thing your are looking at.
In any case, I think file naming should have best practices defined, because I believe it's not just a matter of taste, like some people think of semi-colons.
Important topic, thanks.
What do you mean by "standard in NPM module"? what about including the file role in its name, angular-style - e.g. user-service, user-api, user-dal, user-cold-testing, etc?
We try to avoid topics that are highly subjective/aesthetic, I'm not sure we can reach a definitive BP here but lets try!
With "standard in NPM module" I meant the name of modules. So your imports of NPM modules and "local" modules would look similar.
If you have your files grouped wouldn't user-service and user-api then already live under /user ? I always leave the context out of the file name if it is apparent from the location. Same for class or function names. You then might have multiple files with the same filename living in different folders, but I am never too bothered by that. I find the redundancy in names more annoying than the possible confusion.
I always leave the context out of the file name
Agree. Pulling back my suggestion.
My concern about this topic is that there is simply no best practice. We strive to keep this guide 'opinionated just enough' and avoid being decisive where things are not that clear or critical. Do you suggest that kebab-case-naming pass through this filter? maybe separate/tag best practices that are more controversial?
Yes it might be difficult to define a best practice for this, since a lot of people will label it as opinionated.
I started this topic because I am curious what others use, if they gave it much thought at all, and if there are convincing arguments against using an all kebab file naming scheme.
I alone have spent quite a bit of time thinking about this, and I can't find any good resources on the topic. I find it odd that there is so little info on the topic, and even a niche community like Node.js wouldn't have a recommended way of naming files.
I don't want to rethink or debate this every time I start a new project with other developers. It feels to me like there should be best-practice guidelines, just like we all agree on function and class names. We don't specify __how__ to choose a good name. Just that the format must be camel- and pascal-cased.
Similarly you can't have a definite rule on file structure and naming. So user-registration-service.js, user/registration/service.js, user/registration-service.js and user/registration/registration-service.js could all be valid depending on what structure makes sense for your project.
But if you state that all file and folder names are best kept kebab-cased (for the reasons mentioned earlier), than that is an easy and clear rule to go by.
I so much agree with the necessity for practice on this matter. At the same time, we must keep our reliability and suggest items that score high on at least two dimensions: (a) undoubtedly correct, (b) critical and (c) conventional.
I believe we should sadly drop this in the name of content curation and not technical correction.
Unless we can prove that most people think the same, maybe reddit/FB discussion? keep this issue open and tag 'help needed'? I'd be glad if you lead it, we need more evidence :)
@i0natan Fair enough. I agree with you. I'll think about starting a topic on reddit (or hackernews maybe?) about this.
Most helpful comment
I so much agree with the necessity for practice on this matter. At the same time, we must keep our reliability and suggest items that score high on at least two dimensions: (a) undoubtedly correct, (b) critical and (c) conventional.
I believe we should sadly drop this in the name of content curation and not technical correction.
Unless we can prove that most people think the same, maybe reddit/FB discussion? keep this issue open and tag 'help needed'? I'd be glad if you lead it, we need more evidence :)