manhvu

manhvu

Proposal: Add support namespace for module

In a large repo, working with module need to add alias too much is quite annoyed and not good for organizing code.

I think better add support for namespace can bring more convenient for dev.

This is a basic example for namespace cross multi modules.

Example:

defmodule MyApp.A do
  namespace MyApp.DataProcessing

  def a do
  # do somethings
  end

  defmacro macroA(name, opts) do
    #...
  end
end

defmodule MyApp.B do
 namespace MyApp.DataProcessing

 def b do
  # somethings
 end
end

defmodule MyApp.C do
  namespace MyApp.DataProcessing

  def do_something(data) do
    data
    |> A.a()
    |> B.b()
  end

 A.macroA :wrapper, type: :json
end

LS can easily to suggest dev in a namespace.

Pros:

  • Less typo like add alias for module.
  • Make code clean than before.
  • Better for LS suggest in case work in namespace.

Cons:

  • Make complicated if bring support for import, require or use.
  • Can make dev confused.

Most Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

This idea is essentially implemented in the library Boundary GitHub - sasa1977/boundary: Manage and restrain cross-module dependencies in Elixir projects · GitHub

Do you have any thoughts on how this proposal differs, beyond basically the implicit aliasing?

FlyingNoodle

FlyingNoodle

Please don’t. I know this isn’t a democracy but I vote against it.

BartOtten

BartOtten

At mobile so in short:

defmodule DataProcessingAliases do
  defmacro __using__(opts) do
    quote do
       alias MyApp.A
       alias MyApp.B
       alias MyApp.C
     end
   end
end

Now you can use DataProcessingAliases in the modules. Mixed ground between explicit and implicit…?

Last Post!

BartOtten

BartOtten

Ah, forgot about that. Need to expand it before passing it as function argument. Small change but then you can just use module names.

Where Next?

Popular in Proposals: Ideas Top

knoebber
I started a new phoenix project with --no-tailwind and found friction: delete tailwind classes from core components delete tailwind cla...
New
PJUllrich
Hey folks, I have the unique problem that I need to ignore all “change” and “input” events for one specific input element in a LiveView F...
New
bartblast
This could resolve to {[a: 1, b: 2]}. Was it ever considered to allow such syntax? Notice this: {:abc, a: 1, b: 2} and this: my_fun(:abc,...
New
byhemechi
Many web frameworks (e.g. Remix, Gatsby) have an option for their link components that begins the navigation request on hover so that whe...
New
zachdaniel
One thing I find is that I typically “start” with a LiveView even for static pages (in cases where I know I’m likely to add interactivity...
New
GregPhx
Greetings Everyone!!! A little bit of my background so it could be easier to understand where my comments are coming from, and to take t...
New
woylie
We are seeing a lot of warning logs like this: navigate event to "https://someurl" failed because you are redirecting across live_sessio...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54006 488
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement