Hi all!

I increasingly find myself writing more or less exactly same logic as in 
@type/@spec in body of the function to check incoming arguments.

Would it be helpful if Elixir compiler could wrap function into assert 
check for incoming arguments and also result generated based on typespec?

I think it would be very useful for 

- while running unit tests immediately see where components interaction 
breaks
- keeping unit tests data in sync while developing - creates more crashes 
when some stub/test data does not comply with changed logic in function
- running system and checking where it breaks the contracts between 
components in run-time/while debugging (dyalizer does a great job to 
extract information during static analysis phase, but runtime can provide 
more incorrect data :)
- encourage writing more typespecs because benefits of doing so will be 
visible immediately and not when (occasionally) dyalizer will be run. So 
make it type specification first class citizen that is not just for 
documenting code, but also to enforce constraints.

I personally would also love to have possibility for extended typespec that 
would allow also specify relation between arguments too. Like assert(arg1 + 
arg2 > 0).

It seems that it may be achieved mostly by rewriting def/defp macros and 
embedding asserts code generated from @spec around function body.

This will slow down the execution of code and should be compiler option to 
turn it on/off for production/dev/testing environment separately with on 
setting in development/testing by default.

What do you think? 

/Gaspar

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/638bb1fe-5276-49a3-9013-a784625226ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to