Mixed Naming Conventions, Best Practices?... Mixing Elixir With Js, Vuejs

I’m using VueJS for the front-end of this project. File conventions are CamelCase, Elixir, snake_case.

Variable conventions differ too.

I’ve been following conventions, depending on language, but now code looks Frankenstein as a result, with inconsistent filenames & variable naming.

I can see this becoming a big problem when sharing variables between languages. How is the problem generally handled? What are the best practices here?

Do I mix & match conventions according to language? Or keep 1 universal convention for all modules in the project, regardless of language?

And if its the former, how is this problem handled when sharing variables between 2 languages?

3 Likes

i’m following conventions in both parts. i use camel case variables in javascript and snake case in elixir.

to share data between elixir and javascript, you are going to use some form of api. this is the point where many transform then between camel case and snake case. if you’re going for absinthe/graphql for example, you will write your schema in elixir with camel case (field :first_name) and your queries from javascript can use camel case (firstName) and it gets automatically matched.

3 Likes

@Emily @manukall Absinthe has an adapter to convert snake_case to camelCase ( absinthe/guides/adapters.md at main · absinthe-graphql/absinthe · GitHub ). I’m using this adapter and it works very well

.

The schema has to be snake_case to adapter works.

My project is a phoenix (version 1.4.) framework using absinthe (version 1.4.13) and absinthe_plug (version 1.4.6). To set up an absithe adapter, go to config.exs file and add the line below

config :absinthe, adapter: Absinthe.Adapter.LanguageConventions
2 Likes