2
msdsk
2y

How do you guys like to name things, do you prefer being specific/verbose or generic? Say, we have a vue component to which we need to pass props. Would you prefer:

<todo-list todo-model="TodoModel" />

or rather:

<todo-list model="TodoModel" />

For me, the first is easier to search for, the other is more elegant and decouples what is happening from why is it happening.

Comments
  • 3
    Naming things depends on whether it’s possible to have namespaces or other context for that name.

    In general, don’t repeat the name of the context. It’s redundant.

    Yes, it may help with searching but only if you are using a dumb text search.
    Your IDE should provide to you tools to search with context, which is better anyway and will keep your code clean.
  • 0
    You can just go with named models in Vue. In given context, I don't see such need though: TodoList is supposed to accept a list of todo as primary two-way binding, and duplicating name for it would be redundant, especially if you don't plan to add more models to component.
  • 1
    +1 vote for the last alternative.
  • 1
    Some random opinons

    * For views with 1 input I do like it if that input is called the same thing everywhere. model or viewModel or whatever.

    * If it comes up multiple times that devs are confused due to the generic nature of a name, I'll gladly change it to something verbose and specific

    * I dislike multiple files with the same name. I think opening article.js and talking about "I edited article.js" is way simpler than having 50 components that all have an index.js file and having to refer to "article/index.js" or seeing multiple tabs in your editor named index.js and having to look at the folder names.
  • 1
    To expand: I really think it's faster if you have a standard for what you name your view data,

    When you're working inside of a view it's really nice to just know that you can write "model.something" no matter what, and there's rarely any confusion as to what the model is.

    Makes copy-paste view files so much faster when you don't have to find-and-replace and change stuff from "todoModel.date" to "articleModel.date" or "todoModel.title" to "articleModel.title"
Add Comment