Why function names starting with '_'?

I see many functions named like ‘_my_fun1’ in some package.

What is the purpose of such naming? I guess it is a standard practice in programing, right?

It’s just a common convention (probably borrowed from Python) to mark those functions as “very internal” or auxiliary.

See also Prepended underscore in Base functions - #3 by stevengj


so these functions are generally not exported or imported?

It’s not a formal interface, but the idea is that users should not import these functions, you’re communicating that you don’t consider them stable, or that there’s an entry-point function users should be using instead.


Right, by now Julia has a public keyword to signal a function is part of an API. You should only use such functions or exported that also mean part of API. Otherwise you are in trouble area with or without _ prefix.

1 Like

It’s also useful when you want a helper function for you interface function, e.g. foo. Instead of coming up with a new separate name, or maybe foo_helper, you just name it _foo. It’s a crutch for us with poor imaginations, and signals that it has something to do with foo.