Struct namespacing

Hi there…

After parsing my JSON to structs, I have ended up with some pretty basic modules which are purely just struct definitions… e.g.

defmodule MyApp.Modifier do
    defstruct [:type, :params]
end

Thats it! As I start parsing the rest of my JSON structure, I feel that I might be left with a few more of these floating in my /lib/my_app folder…

Is there a particular convention that anyone has found useful when namespacing these? I can’t seem to think of anything that makes sense to me yet and I “feel” like they are just floating there in my lib but should be somewhere else…

If its just that you do not want to have thousands of files floatisng around, just have them in a single file:

defmodule MyApp.A do
  # stuff
end

defmodule MyApp.b do
  # other stuff
end

Or if its more the steady repetition of a common prefix in the Alias, you can also define “inner” modules:

defmodule MyApp do
  defmodule A do
    # stuff
  end

  defmodule B do
    # other stuff
  end
end
1 Like

:slight_smile: … Of course, not sure why I thought I was locked down to a single module per file…

Cheers…