NULL pointers vs. empty strings--preference?
If a C text processing function encounters empty or missing fields/values/sets, how do you prefer it handle them? Namely, if it returns a struct comprised of the items it extracts, do you prefer the empty or missing parts to be stored in the struct as NULL pointers or empty strings?
One Bowl. One Hundred Percent.
(By "empty strings" a mean a pointer to an empty string, of course)
If there is a difference between a string being zero-length and being completely absent, then I'd use NULL. Otherwise I'd use (char*) "";
For me it really depends on the situation. Sometimes there is no difference between a NULL string and an empty string. For example, if I'm calling some function that returns a string, and I plan on combining a bunch of these results together:
The geniuses here use a single space to represent no value in both the database and code (Perl).
They probably didn't invent that themselves; I've seen it somewhere else.
Perhaps they had to work against Oracle? Apparently in Oracle an empty string is null (i.e. violates NOT NULL fields rules). Using a single space "fixes" that - although we decided to go the more "proper" route and use NULL instead (our app doesn't rely on empty strings)
It was Oracle - ORCL never implemented NULL's right,
It is rather strange that someone would use a space for representing NULL in Perl when there is an obvious and standard way of doing it -- the undef value. It translates automatically to a NULL when using DBI.
Fog Creek Home