How to name 2 different types of Roles?

This is not so much an Ash question, but more looking for your advice in naming things / code organization.

I’ve got 2 domains:

  • Workspaces
  • Meetings

Each of those will have a resource Role. What should I name those resources?

  • Workspaces.WorkspaceRole + Meetings.MeetingRole
  • Workspaces.Role + Meetings.Role

option1: more concise

# lib/defacto/workspaces/role.ex
  defmodule Defacto.Workspaces.Role do
    ...
    postgres do
      table "workspace_roles"
    end
  end

  # lib/defacto/meetings/role.ex
  defmodule Defacto.Meetings.Role do
    ...
    postgres do
      table "meeting_roles"
    end
  end

option2: more explicit with the name

# lib/defacto/workspaces/workspace_role.ex
  defmodule Defacto.Workspaces.WorkspaceRole do
    ...
    postgres do
      table "workspace_roles"
    end
  end

  # lib/defacto/meetings/meeting_role.ex
  defmodule Defacto.Meetings.MeetingRole do
    ...
    postgres do
      table "meeting_roles"
    end
  end

option3: … ?

1 Like

Option 3..?

  • Roles.WorkspaceRole + Roles.MeetingRole
2 Likes

I would go with option 1.

  1. The module namespace already tells you what kind of role it is.
  2. Workspaces.WorkspaceRole is redundant. You’re saying “workspace” twice.
  3. You can still do alias Defacto.Workspaces.Role, as: WorkspaceRole if needed
1 Like