General naming conventions
Now, let's discuss how we approach naming conventions. As was mentioned in Learning guidelines - Domain Driven Development, all is based on common vocabulary that is shared among our programmers.
Shared conventions between projects
The shared vocabulary is also shared between projects, as much as possible. User in one project, means the same thing in all other projects.
Of course, every project has a unique set of words, but we try to share as many of these as possible, with other projects of similar type.
Singular vs Plural
We use singular and plural forms in natural form, for example, if we have a database provider working with users, the name of that provider would be UsersProvider, because it works with all users, and not just a single user.
Same conventions through the system
Few more examples:
- REST endpoint would be /api/users
- Javascript provider calling that endpoint would be usersProvider
- Svelte component would be stored in folder Users and it's name would be Users.svelte
- ASP.NET controller handling /api/users endpoint would be called UsersController
- manager handling users would be called UsersManager
- provider handling users would be called UsersProvider
- database table would be called _user_info_, because user is a keyword, but names of tables are in singular form
- database view joining users' data to complete view would be called users, names of views are in plural form
- database stored function to create a user would be called create_user, to retrieve user would be called get_user and to retrieve all users would be called get_users
As you can see in the example above, we keep the same naming convention for all the way through all layers of application, from client side, to database.
Used verbs
This is a list of standard verbs we use to describe an action:
- Create
- Update
- Delete
- Get - get functions return object(s) as they are, in a complete set
- Search - search functions return object(s) based on criteria and paging settings (page size, page number)
- Process - process functions are used for mass processing of data, for example, when you import data to a stage table and then run a function that process them to final data stored in public table
- Map - map functions are used for mapping objects from one type to another, generally speaking, for data transformations
There are also some specific verbs we use to describe specific actions:
- Generate - generate functions generate data based on inputs
- Parse - parse functions parse input data, usually, CSV files, Excel sheets, text files, and others
- (Bulk)Copy - copy functions are special functions that, usually, copy data in big chunks to database with COPY command
- Send - send methods are used for actions related to email, SMS or other notification service, for example, SendEmail, SendNotification, and so on
Name structure
Names in our framework follow these simple rules:
- For object names: [noun in plural form] + [object type name], for example, UsersController, UsersHelper, UsersManager, and so on
- For endpoints: [noun in plural form], for example, /api/users, /api/groups, and so on
- For data tables: [noun in singular form], for example, user, user_group, user_group_member, user_setting, and so on
- For object methods and stored functions in database: [verb]+[noun, usually in singular form], for example, CreateUser, DeleteUser, CopyUsers, ParseUserGroupMembersCSV
There are also rules that specify hierarchy of names:
- For example, User group member is divided in to primary object, and secondary object. Primary is User group, secondary Member
- When you name a method that creates a secondary object, use both names, for example, CreateUserGroupMember, do not omit primary object, be specific
- If you create a provider named UserGroupsProvider, you can name the method CreateMember, because the primary object is defined by the provider name
- Do not use abbreviations, for example, CreateUGMember, use full primary and secondary object names
- If you create a database view, primary object name is in singular, secondary in plural, for example, user_group_members
- If you create a database function, primary object name is in singular, secondary in plural, for example, search_user_group_members
Language specific conventions
There are language/framework specific naming conventions for every language/framework we use.