From: Bernhard B. <ma...@ba...> - 2003-06-27 16:46:40
|
Ok, your points are correct. I was more thinking about the implementation of the native code, which is easier with standard types. There you have to map every constant to a readline/editline variable, which should be quite simple with a lookup-table. The numeric constant (resp. the string constant after a atoi-conversion) would just be an index into an array. Bernhard > > void setVar(int which_variable, int value); > > void setVar(String which_variable, String value); > > int getVar(int which_variable); > > String getVar(String which_variable); > > Using setVar() and getVar() works for me. Using string constants for > variable names does seem a little unclean though, simply because string > comparisons aren't as clean as integer or pointer comparisons. > > The suggestion of IntVar and StrVar was for cleanness and consistency. > If you're using strings then you either compare with String.equalTo() > which is inconsistent with integer comparison, or you compare with == > in which case you're doing pointer comparisons and you might as well not > assign values to the strings at all. > > Using IntVar and StrVar also avoids problems of implicit conversion if > (for instance) we later add character variables or whatever; you can > implicitly convert (char which_variable) to (int which_variable) but not > (CharVar which_variable) to (IntVar which_variable), which means it's a > little safer in the long run. > > The user of course doesn't even need to know that the IntVar and StrVar > classes exist; they simply call getVar(INHIBIT_COMPLETION) or whatever. > > Anyway, it should be relatively straightforward to change from one > implementation to the other, without affecting the use of the library at > all. > > b. |