Should I compare pointers with is of == ?

Justin Johansson no at
Wed Oct 14 11:20:24 PDT 2009

#ponce Wrote:

> It's a bit unclear to me. 
> I know I must compare references with is but pointers ?

Thanks for asking this question ponce; I've been getting into the habit of using 'is' for both pointers
and classes, so in similar vein to ponce's question, I'd like to ask if the following (where foo is
eother a pointer of class ref) is being overly pendantic in the case of null if tests:

if (foo !is null) {
  // can do something with foo

as opposed to the shorter form, but possibly incorrect or less safe

if (foo) {
  // can do somthing with foo

I think I would prefer the shorter form if its 100% good.

Thanks all.

More information about the Digitalmars-d-learn mailing list