Qqwy / elixir-type_check

TypeCheck: Fast and flexible runtime type-checking for your Elixir projects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeCheck without `use`

baldwindavid opened this issue · comments

Now that TypeCheck achieves near parity with regular Elixir typespecs might it be theoretically possible to compile everything effectively use-ing TypeCheck (i.e. injecting it into all the modules)?

It would be really nice to just be able to include TypeCheck as a dependency, maybe set a compilation configuration setting, and have it work out of the box.

The problem is that the only way to add checks to a module, is if we have access to the module at compile-time (because we need to register a @before_compile hook to inject the new code.)

This means that, at least as far as I am aware, there is no way to add TypeCheck-based checks to modules that live outside of your project (like your dependencies or the standard library.)

And even for your own modules, there is no way to include external code except for use (or writing it out manually). This is a design decision made by the Elixir team to make it easier to trace the origin of what is happening at any place of the codebase, but it does mean that even for your own modules I am not aware of a possibility to include TypeCheck without use.

commented

Aside from the technical challenges of what you're asking, removing the use TypeCheck would remove an important message to any developer looking at the code. Whilst it may seem "nice" to remove clutter, this would be like removing "use ExUnit.Case" from all files ending in "_test.exs" and have them magically inject that code. It's generally considered idiomatic elixir to avoid hidden magic.

For sure. The difference is that I wouldn't want ExUnit.Case everywhere whereas I DO want type checking everywhere. This is more about my sadness that we don't have type checking built into the language than anything lacking in this library. :)

This is more about my sadness that we don't have type checking built into the language than anything lacking in this library. :)

You might not have been aware yet, but José announced during ElixirConf.EU that there is a research project starting to try to add some kind of static type-checking to Elixir. This might still take a long time (and maybe will not progress beyond a research project) but it definitely is something that is being worked on!

I did see that and am very curious to see that keynote along with your presentation!