[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

snmpconf Policy MIB: Strings and other data types



The C string is so tied to the C language that it does not belong in any 
other language, especially one that doesn't have pointers and runs in an 
interpretive environment. One of the attributes of a text string is that it 
has a length. The fact that the length may be computed by searching for a 
null terminator is irrelevant to the concept of a string. A number of the 
functions defined in the Policy MIB have variants for NUL-terminated 
strings and non-NUL-terminated strings. Yet these concepts do not have 
meaning within SNMP. A string just exists and has a length. It is not 
null-terminated or non-null-terminated. Although we are modeling the 
language after C, we must also remember that we are working in a specific 
problem domain. The C string simply adds too much complexity to what is 
supposed to be a simple language.

The C string is represented as a char*. But what is a char* if there are no 
pointers?  Someone who does not program in C every day might easily write:

char* a, b;

expecting that a and b would be strings. But that is not what is written. 
In the above declaration, a is a string and b is a single char. Oops!  Try 
to explain that to somebody without bringing in the concept of 
pointers.  Also try to explain to them why, if string a contains binary 
data, you cannot determine its length and, therefore, you must pass the 
length in to a function as a separate parameter. Then, what happens if you 
pass the wrong length into a function? Does the agent crash? What happens 
if we pass a char* to a function without initializing it first? Do we 
really want to inherit all of these problems from C?

If we replace "char*" with a new, intrinsic, "string" type, we solve all of 
these problems. A string would have a built-in length that would be 
returned by strlen() (for C compatibility).  Functions could have string 
parameters and return strings without artificially introducing separate 
integer arguments. Also, strings could be assigned without aliasing and 
compared using ==, !=, <, >, etc. (yielding the correct results, not the 
bogus results of comparing pointers). For people that know C, we could 
still have functions like strcmp() and strcat(), although operators < and + 
would also do the job.


- Pablo
---------------------------------------------------------------------
Pablo Halpern                                    phalpern@newview.org
http://www.halpernwightsoftware.com