Definition of "!"

 

Hello people!!

Why some programmers put the "!" before a function ??

example:

!isPositionOpen() and isPositionOpen()

What do the different "!" ??

 

thanks for help! =]

 
bool SampleFunction()
{
    return(true);
}

// The "!" operator is used to negate the value of a function. If a function returns "true", it will make it "false" and vice-versa.
// Example

if(SampleFunction() == true)
{
    Alert("TRUE");
} else {
    Alert("FALSE");
}
// Alerts "TRUE".

if(!SampleFunction() == true)
{
    Alert("TRUE");
} else {
    Alert("FALSE");
}
// Alerts "False".


 
KeepMarcos: Why some programmers put the "!" before a function ??
You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.
 
WHRoeder:
KeepMarcos: Why some programmers put the "!" before a function ??
You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.
Since the OP did not know what the "!" meant, I used the example above to make the point extra clear and obvious, however, your clarification is correct. Hopefully the OP now understands what the "!" operator does and is not further confused by your clarification which does not answer OP's question. Cheers
Reason: