How should I name this function?
function get_IfUnsetAlsoSet_SomeGlobalVariable() {
if someGlobalVariable is not set {
someGlobalVariable = somedata
}
return someGlobalVariable
}
Should I give a name like this? -> getSomeGlobalVariable(开发者_JAVA百科)
How do you name these getset functions?I guess a name like getSomeGlobalVariable()
should be easy with no confusion.
Basically you do not have to give your complete logic in a method name.
As I can understand, this smells a bit like the Singleton. So you could use this name:
GlobalInstance();
or something.
Pardon me if I'm missing something here, But as per your method
function get_IfUnsetAlsoSet_SomeGlobalVariable() {
if someGlobalVariable is not set {
someGlobalVariable = somedata
}
return someGlobalVariable
}
It just do one thing, will set 'somedata' to 'someGlobalVariable'. Personally I think Its not good to use names like 'somedata, someGlobalVariable' instead you may use some meaning full names like 'applicationName, loggedUser etc..'
In your case, basically you are returning a global variable value.
精彩评论