I just tried to change the application name in a trivial Phoenix project. The name of the project is embedded into the source code 48 times. I have one controller, one view, and a channel.
My suggestion: assume anything created using mix will be build using mix. For these builds, add the definition __APP__
, set to the application name (in module-name form) from the mix.exs file.
Then generate all the underlying files using
defmodule __APP__.EndPoint do
...
This could apply to both mix new
and mix phoenix.new
, as well as anything else that comes along.
Dave
How would a module know what __APP__ is? What would the rules be?
Cheers,
Louis
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAK-y3CvsXJTp4sfcjC4iA61NF-509Keato7_bDacSTJ9_3_MJg%40mail.gmail.com.
How would a module know what __APP__ is? What would the rules be?
Cheers,
Louis
On Wed, 30 Nov 2016, 17:11 Allen Madsen, <allen.c...@gmail.com> wrote:
What happens when you have your app and a dependency that both use __APP__?
Allen Madsen
On Wed, Nov 30, 2016 at 11:40 AM, Dave Thomas <da...@pragdave.me> wrote:
> I just tried to change the application name in a trivial Phoenix project.
> The name of the project is embedded into the source code 48 times. I have
> one controller, one view, and a channel.
>
> My suggestion: assume anything created using mix will be build using mix.
> For these builds, add the definition __APP__, set to the application name
> (in module-name form) from the mix.exs file.
>
> Then generate all the underlying files using
>
> defmodule __APP__.EndPoint do
> ...
>
> This could apply to both mix new and mix phoenix.new, as well as anything
> else that comes along.
>
> Dave
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elixir-lang-core+unsubscribe@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/fe291b67-82f9-411e-ae3a-a1821867ebc6%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAK-y3CvsXJTp4sfcjC4iA61NF-509Keato7_bDacSTJ9_3_MJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAM-pwt5n5eGKfNbfQyCoTX_0Cq8Fu%3DyXSA98EAMOtey_tchS%2Bg%40mail.gmail.com.To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/e4f74bee-a85f-4910-a4b9-e1aa4fa9bfdd%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/5f1dbac8-a94e-4104-bd49-bf1e0248264a%40googlegroups.com.
While I get your point, there's also the common use case of logging messages; that is, I usually include the app name in case someone decides to log everything to the same log. There's also message displayed to the end user. I mean I usually put something in the message about exactly which app it is in case the end-user decides to capture a screen shot or something like that. For whatever it's worth, having a standardized variable like __APP__ would help with those use cases and make it a little easier to maintain.
config :logger, :console, metadata: [:application]
--
You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-core/jX9Pm2dTa-c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4K5EvZvRumjHQrDQ9cOHjuL8J6MgmxiXDgOj492QwA2aA%40mail.gmail.com.
def project do
[constants: [APP: MyApp]]
end
defmodule __APP__.Foo do
end
erlc -Dapp=MyApp
defmodule Module.concat(Application.fetch_env!(:my_app, :app), Foo) do
1. Use @APP for compiler attributes (in contrast to @foo as module attributes). Pros: it is concise, can be made compile time. Cons: slightly new syntax, conflicts with __MODULE__ (which could arguably be @MODULE)
2. Use @app for compiler attributes. Compiler attributes could be overridden inside modules by a module attribute. Pros: it is concise, can be made to warn at compile time. Cons: overloads existing syntax.
3. Introduce a new syntax, such as $app. Pros: it is concise, can be made compile time. Cons: introduce completely new syntax, conflicts with __MODULE__ (which could arguable be $MODULE)
How often one needs to rename the application? I had to do this only once, and it was a simple find & replace.
While __APP__ would simplify it, I find it a bit ugly to have every module defined like this. And if there was an __APP__ variable, I would certainly expect it to be the OTP application name, not some mutated module name. As of now there's no place in mix.exs that defines the "base" module for an application, and it's nor reliable to inflect it automatically from the OTP application name, some examples:
mongodb uses Mongo, mongodb_ecto uses Mongo.Ecto, phoenix_html uses Phpenix.HTML, phoenix_pubsub uses Phoenix.PubSub, cors_plug uses CORSPlug, plug_cors uses PlugCors.
I don't see a way how we can inflect those automatically.
Michał.
> On 30 Nov 2016, at 17:40, Dave Thomas <da...@pragdave.me> wrote:
>
> I just tried to change the application name in a trivial Phoenix project. The name of the project is embedded into the source code 48 times. I have one controller, one view, and a channel.
>
> My suggestion: assume anything created using mix will be build using mix. For these builds, add the definition __APP__, set to the application name (in module-name form) from the mix.exs file.
>
> Then generate all the underlying files using
>
> defmodule __APP__.EndPoint do
>
> ...
>
> This could apply to both mix new and mix phoenix.new, as well as anything else that comes along.
>
> Dave
>
>
> --
> You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/fe291b67-82f9-411e-ae3a-a1821867ebc6%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/64EDFB02-CE5A-42F5-B690-716E419E689A%40muskala.eu.To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2BwQoC6mggL1QiU1auT27krVEcWcsNiQqcJTj7J9kU3bw%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CABqbXnuEd6gbBhv_Xop4%2BJARU%2BZt0w3%2BM-TaswjBvi2L_xVpng%40mail.gmail.com.
======================================================= I welcome VSRE emails. Learn more at http://vsre.info/ =======================================================
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CABqbXnuEd6gbBhv_Xop4%2BJARU%2BZt0w3%2BM-TaswjBvi2L_xVpng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/7F4EC61D-8366-4074-92BD-85228D897F3B%40chrismccord.com.