为什么是-compile(export_all)不好的做法? [英] Why is -compile(export_all) bad practice?
问题描述
由于几个原因:
-
清晰度:更容易看出在模块之外使用哪些功能。
当您在Erlang shell中完成标签时,您只能获得一个列表导出的功能,没有其他。当您重构模块时,您会知道哪些功能可以安全地重命名,而不需要外部用户。
-
代码气味:您收到未使用的功能的警告。 / p>
因此,您将避免死亡代码。
-
优化:编译器可能会使更多知道不是所有功能都必须导出的积极的优化。
All the erlang books seem to say export_all is bad practice but don't give a reason. In the end most modules spend a majority of their time with compile(export_all) because constantly updating the list of modules to remove the helper functions is a hassle. Is it bad practice because I'm supposed to care about the functions I expose to other developers? Or is it bad practice because there's some kind of performance cost in the number of functions a module has, because of maybe things like hot code loading. If there is a performance hit to stuffing a module with a lot of functions, how bad is it?
For several reasons:
Clarity: it's easier to see which functions are intended to be used outside the module.
When you tab complete in the Erlang shell you get a list of only the exported functions and no others. When you refactor the module, you know which functions you can safely rename without external users depending on them.
Code smell: you get warnings for unused functions.
Therefore you'll avoid dead code.
Optimization: the compiler might be able to make more aggressive optimizations knowing that not all functions have to be exported.
这篇关于为什么是-compile(export_all)不好的做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!