以_开头的函数,这是什么规范?

看别人的github公开代码,很多以_开头的函数,感觉很奇怪,很丑陋

这是通用的规范吗?是什么含义?

_ 开头的函数通常是包的私有函数,这些函数一般没有暴露给用户使用的计划。因为在Julia中并不原生支持 private 标记,所以这只能算是一种编程约定。

1 个赞

Python 的习惯:Single and Double Underscores in Python Names – Real Python

Convention Example Meaning
Single leading underscore _variable Indicates that the name is meant for internal use only
Single trailing underscore class_ Avoids naming conflicts with Python keywords and built-in names
Double leading underscore __attribute Triggers name mangling in the context of Python classes
Double leading and trailing underscore __name__ Indicates special attributes and methods that Python provides
Single underscore _ Indicates a temporary or throwaway variable
1 个赞