VeljkoMaksimovic
Is there a way to have multiple aliases, but to use as: acronym for one of them, something like this, but that actually works ![]()
alias Guard.Rbac.{Cache, RoleBindingIdentification, as: RBI}
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Eiji
What you show in best case could work as:
That’s because
optsare on same level as other aliases.Alternatively
Elixircould support this:However this looks just ugly and I guess that’s why it would be not supported at all. If you have an interesting idea how to improve that then feel free to create a proposal, but so far I do not see either a use case nor how it could look good at all.
Also keep in mind that even if such ugly-looking feature would be supported then it would be still formatted into multiple lines, so it would look like:
I believe that keeping aliases work as it’s now is best.
VeljkoMaksimovic
This is exactly what I meant
I dont agree that this is ‘ugly looking’. Elixir already supports this notation:
and I don’t see how this is any prettier (or less ‘ugly-looking’) then the example above where abbreviations are supported.
True, situations where something like this would be needed are rare, but option 1:
IMO looks cleaner then option 2:
bmitc
I don’t understand what that’s trying to specify. In this case, one is able to guess, though.
For me personally, I enforce the
Credo.Check.Readability.AliasAsandCredo.Check.Readability.MultiAliasCredo checks foralias, among others. So thealias ___.{___}syntax andalias ___, as: ___are not allowed.Mutli aliasing is really only useful in very specific scenarios. It makes copying module names harder (impossible rather), and it starts to look ugly and busy when you have a lot of modules that aren’t just under a single “namespace”. Simply typing out the shared “namespace” is really not difficult.
I personally feel that
alias ___, as: ___should be used extremely sparingly if not removed from the language. It’s use is usually an indication that the module it isasing is poorly named. And I have certainly seen it heavily abused where the module was essentially renamed withas.For the proposed:
it requires a fair amount of tracing to understand. I would suggest renaming the longer modules.
RoleBindingIdentificationcould beRoleBindingIdor even justRBIif you documented it with@moduledocand the abbreviation is clear in the context.OrgRoleToProjRoleMappingshould probably just be renamed.NobbZ
Using rarely, yes. Removing? No!
We have a codebase with more than 600 modules at work.
There are several modules ending in
Product, withinSchema,Dataloader, and what not prefixes. We do not want to repeat the type in the module name itself, therefore we are happy to be able to use:asin analias.bmitc
Removed was a bit of a hyperbole.
I know it won’t and probably shouldn’t happen in Elixir. Although, certainly several other languages, such as F#, do not have that feature, and I personally don’t miss it there. I’m not aware of it being in Erlang. Is that correct?
For Elixir, I got a bad taste for it at my previous company, where its use was definitely a symptom of poorly named modules. So many modules had such extremely similar names that
as: ___was used to mitigate this in modules and in tests. The moral of the story is that people will often take conveniences and turn them into hazards.eksperimental
And how do you deal with external librarie modules?
ityonemo
Erlang doesn’t have module aliasing at all.
I’d say the biggest reason why
as:is bad because if you wanted to do a global search and replace during refactoring, it makes it much more difficult.Same with alias Module.{…}
I use neither in my codebases.
sodapopcan
Ya, I’m not a huge fan of
{}(though it has its uses though wouldn’t miss them if they were gone) and never use:as. I even avoid just plain oldaliasa lot of the time unless it provides significant noise-reduction.One of the big things that drew me to Elixir was the high level of locality that is encouraged through official examples. I’m even just talking things like,
Enum.mapas opposed toimport Enum, only: [:map, 2]. Jumping into a function to gain a bit of context on its caller and being able to see all its dependencies without having to jump any further is a really nice feeling. Of course, it’s a balance, but I feel that often there is a subconscious emphasis put on writeability or even “prettiness” over readability and, more importantly, “scannability”.And of course the other thing I really like about Elixir is how relatively small it is and how much thought is put into backwards incompatible changes. Just by that alone, I don’t see something like nested
:ases ever making it in (not that you were necessarily suggesting they would be). Take this really well-thought-out proposal for field punning—a featured loved by many in other languages (not me)—that was rejected, for example.hst337
Yes, there is!
Behold the dark art of context magic in Elixir
Please do not try this at home
VeljkoMaksimovic
If I understand correctly, in your example
RBI.Cachewould ‘expand’ toGuard.Rbac.Cache, and same go forRBI.RoleBindingIdentificationwhich would expand toGuard.Rbac.RoleBindingIdentification, right?