Firstly AST
is not extremely low level if we are talking about Elixir
.
Well … I have one really good example from my experience …
My first job … I have worked with Ruby/Rails. I saw really small monkey patching usage from someone who was more experienced than me. I liked how it’s simple (so there was no need to change existing code) and I have stupidly changed file with just few lines of monkey patching into weird file with hundreds of lines with monkey patching.
If something is supported it does not mean that it should be always used. Especially when we are talking about evals. Look … I believe that Joomla!
and Wordpress
developers are not stupid. Same goes to developers of (at least most popular) extensions for those projects. The problem is that lots of sites was trivially hacked by adding PHP
code into image files - just because they used eval.
Sure, one module looks safe, but can you guarantee that this will be still safe after few rotations in dev
team? Can you guarantee that it will be still safe after somebody in team decides to move such generator (with eval
call) to open source library? Software is changing really rapidly.
If we are going always with easiest solution then we will end with something like Windows
in few weeks/months. Windows
was created by definitely good developers, but looking how it changes in years we see that something is definitely wrong. For example compare modern (with rewritten code) Plasma 5
features and requirements with what offers Windows
’s builtin window manager. I can’t do even as good job as that made in both projects, but still I (being not experienced in OS programming) see huge differences.
Also my solution is not about only “low level”. We have here typical pattern matching which prevents to add data of any type. We can always add simple guard to check if module have Schema
part in list too without bigger problem.
Summary:
- It’s safe - no matter who will use it and no matter if you made mistake
- It’s at least as simple as with eval (in implementation)
- It’s definitely faster solution
Therefore I’m not sure what’s wrong with my hint.