On Sep 7, 2007, at 2:44 AM, Rainer User wrote:
Hi Folks, i am new at the webobjects-dev maillist and new to webobjects too. I am reading the white printed book "Webobjects 5, Web Applications", from Apple, it was included in the Webobjects Package of my Webobject-Box. On Page 84 i found an example where a funktion trys to detect if a variable named "personName" [type of it is "String"] is empty or not.
The substantial Code says: if (personName==null || personName.equals("")) { return(true); } else { return(false); }
In my opinion it would be the same if i write only: if (personName==null) { return(true); } else { return(false); }
Where is my misunderstanding? Why i have to use personName.equals("") +and+ personName==null to detect if personName is empty or not?
Maybe someone can help me ore give me a hint?
Thanks from Germany,
Thomas
There are reasons for these things, though they are sometimes historical.
Any framework has to make decisions about this kind of thing and try to be consistent. I am finding the same thing in _javascript_ where it is not clear if a function is returning an object. Sometimes one needs to check for "" (the empty string), null, and undefined.
If you are getting something back from a method in WebObjects and it is null and you think it should be guaranteed to be a non-null object, you could file a bug and try to make that case. It might be more productive to do this in the Project Wonder code, as it is open-source, you can see the code, and they already do a lot of wrapping of WebObjects APIs.
You will probably find it just as bothersome to get back an array and have to check if it is a null or an empty array.
Back in the day, during the port of WebObjects from ObjC to java, there were lots and lots of arguments about this. The fact that ObjC allows you to send a message to null and get back something made some interesting hoops to jump through during the port. It is nice that in ObjC, you can just say:
foo = [[ec registeredObjects] count];
or:
bar = [[eo firstName] description];
You would just literally be able to spend 0 brain cycles worrying about these calls. But this is java.
- ray
|