I have been researching AutoIt naming conventions and have been wondering about the leading underscore on function names. I've been trying to make my code adhere to established conventions but I'm not sure what those conventions are. All I have found is this in the UDF standards:
"All function names must start with an underscore (“_”). *" (but there's no footnote text associated with that asterisk providing an explanation for this convention)
If all UDF names have a leading underscore, then why do some internal functions in the examples also have them? For instance, there is "_MyWindowProc" in the "_WinAPI_CallWindowProc" help-file example and "_KeyProc" in the "_WinAPI_SetWindowsHookEx" example.
An exhaustive search has turned up little. Others are also wondering about the style in general:
----------------------------
In a lot of languages with simple OO capability (PHP 4), or misunderstood OO capabilities (Javascript, C using function pointers, etc.), you'll end up with a function naming convention that uses leading underscores to to indicate privilege level.
//ex.
function _myPrivateFunction(){
}
While individual teams are always going to come up with their own naming conventions like this, the underscore convention seems so prevalent that it made me curious about:
1. Where the technique first came from
2. If there was ever any standardized systems (sort of like hungarian notation) developed around the convention
Beyond pure curiosity, I'm seeing this in a few codebases I'm dealing with right now, and I'd like to understand the possible headspaces of the developers who originally came up with it.
----------------------------
While looking over various PHP libraries I've noticed that a lot of people choose to prefix some class methods with a single underscore, such as
public function _foo()
...instead of...
public function foo()
I realize that ultimately this comes down to personal preference, but I was wondering if anyone had some insight into where this habit comes from.
My thought is that it's probably being carried over from PHP 4, before class methods could be marked as protected or private, as a way of implying "do not call this method from outside the class". However, it also occurred to me that maybe it originates somewhere (a language) I'm not familiar with or that there may be good reasoning behind it that I would benefit from knowing.
----------------------------
Answers include the following:
----------------------------
In Python, prefixing names with an underscore is more than just a convention: Symbols starting with an underscore are not imported by default when importing "everything" from a module, therefore the underscore indicates "private" / "internal usage".
----------------------------
underscore ( _ ) stands for a private / protected function or variable.
Don't know WHO actually came up with it, but I know it is "supported" by Zend ( and the Zend coding standards ).
----------------------------
I've seen underscore used as private functions and I've seen seen underscore as global functions. Also underscore is used to denote global variables within PHP itself.
----------------------------
And Wikipedia has this:
A common programming convention is to use a leading underscore in a name (for example _name) to indicate that the name is intended for internal use within a library (computing) or a header file and does not appear in an API.
The general consensus is that it's a means of identifying an object as protected or private, but this doesn't seem to match the AutoIt philosophy. I think it would be helpful to shed some light on this topic.