小白问个问题,我想实现一些功能,比如定义一些复合类型,变量等等,我只想让别人通过我指定的函数去访问,但是我发现import这个模块后都能通过点来访问,那怎么做才能私有化呢,像是java中的 private这种性质,仅供模块或者类自己内部使用
这个我没见过, 好像没有啊
我只想让别人通过我指定的函数去访问
你可以写readme文档啊
如果工程发布的话文档是给正常人约定的,一些参数直接暴漏,很不安全啊,我翻了翻julia自己的源码,写的实在是太扎实了,很难啃透,但是看看本身的数据结构实现也应该能有启发
这功能跟安全无关吧
这个还是防君子用的,getfield
依旧挡不住,你把 getfield
也给重载了估计自己都用不了了。
说到底 Julia 就没这功能,我记得你不能给其他模块的全局变量赋值,有这个约束。
再就差不多都能看都能改。
Those who are doing more exploratory programming are going to have completely different priorities to those building a banking system in a large team. As Julia is aimed at the former, it generally takes a “consenting adults” approach and opts for flexibility.
看起来是故意这样的。
It turns out that high-productivity, high-performance numerical computing is a gold mine for problems that have not been well addressed by traditional computer science programming language designs.
Once we’ve satisfactorily allowed people to do all the things we want to, we can start thinking about features that prevent people from doing things.
—— @StefanKarpinski post #19
早着呢。
我找到一句Julia最初的四位开发者之一 Stefan Karpinski 对于私有化的看法:
Up to and including Julia 1.0, the language is very much in a “can do” design phase: we’re focused on allowing people to do difficult things, not preventing them from doing stupid things. It turns out that high-productivity, high-performance numerical computing is a gold mine for problems that have not been well addressed by traditional computer science programming language designs. Once we’ve satisfactorily allowed people to do all the things we want to, we can start thinking about features that prevent people from doing things.
作为一门新生语言,这个观点我是同意的。在实际使用中,类似Python一样,当你使用了.
这样的操作,就默认你知道这是一个内部函数或者结构体,怎么使用完全看自己。但目前似乎没有完全私有化的定义。从语言发展的角度,限制你能做什么的确会减少一些可能性。
详情请参看https://discourse.julialang.org/t/private-states-in-julia-modules/1312/17
感谢各位大佬的意见,涨姿势了
以前写java,所以有点惯性