为什么是-compile(export_all)不好的做法? [英] Why is -compile(export_all) bad practice?

查看:316
本文介绍了为什么是-compile(export_all)不好的做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有的erlang书似乎都说export_all是不好的做法,但不给出理由。最后,大多数模块花费大部分时间来编译(export_all),因为不断更新模块列表以删除帮助函数是一个麻烦。这是不好的做法,因为我应该关心我向其他开发人员公开的功能?或者是不好的做法,因为模块具有的功能数量有某种性能成本,因为可能是热代码加载的东西。如果填充一个具有很多功能的模块的性能受到打击,那么它有多糟糕?

解决方案

由于几个原因:




  • 清晰度:更容易看出在模块之外使用哪些功能。



    当您在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆