The idea of “code generation” is to precompute stuff at compile time rather than runtime.
So instead of reading a lookup map from a JSON file each time, it can only be done once when compiling.
@h4cc have you done or are you thinking about doing a simple tutorial about Code Generation in Elixir? I think it’s very interesting and a possible solution to a problem I must solve in my project, so I’m really interested in learning this.
I’m not sure if you and @h4cc are doing the same thing? But what I was asking about was if is this a way to load code from files given a certain match.
Let’s say I have a system variable and if this value is A then lode code A if the var is B then load code B, BUT I if code A loads I do not want code B to be loaded and I don’t want it to be inside any of the project’s files. What I’m trying to do is akin to a Software Product Line. where I can make different versions of the same program without having the respective features/code of the other version.
If I do understand you correctly, there is done a very similar thing when using mix. Depending on your current setting of the environment variable MIX_ENV one of multiple config files is loaded. Something similar should also be possible for the project itself.
But I am not sure what you mean by “I don’t want it to be inside any of the project’s files”. If its not in the projects files, you can’t choose it among others at compile time.
@NobbZ, what I’m trying to do is pretty much Aspect-Oriented Programming in Elixir. If you have ever used AspectJ, that was the functionality I was trying to explain.