I often see code like this:
// Approach 1
if(data != nil){
// Do this and that
}
When one could simply do the check like this:
// Approach 2
if(data){
// Do this and that
}
To me the second approach seems to be much better since it is shorter and easier to read.
So why should one use the first approach at all?
This is mostly a style preference, or some people does not know that it is possible to use first solution.
Moreover, they are languages like java where you can’t write the second solution, You must write yourVar != null