References and Pointers.
Copyable values such as built-in types, strings, and vectors are passed in to functions by const reference, and returned by value.
Reference-counted objects required to be on the heap are standardly passed as pointers.
If a function or method will modify one of its parameters (in CORBA terms, if the parameter is an "out" or "inout" parameter), a pointer to the parameter is passed. This makes it clear the parameter is being modified. From the method call obj->frobate (blah) there is no way to know whether blah is a const reference that will remain unmodified, or a non-const reference that will be changed. In Inti, it's always a const reference; if blah will be modified, the call looks like this: obj->frobate (&blah).
When a string is expected as an argument, the parameter should be a const string &. Often, the code overloads these functions and methods to also accept a const char *, mostly because constructing and destructing string objects from string literals bloats your code unbelievably. It's safe to pass a Inti::ustring (UTF8 string) in to functions that take a const string &, and it should even be pretty efficient, since strings are copy-on-write in this STL implementation. The idea here is "be liberal in what you accept", I want the code to interoperate with other libraries that use plain stringq instead of Inti::ustring. (There is an implicit conversion from string to ustring, but why not avoid the overhead.)
When returning a string, a Inti::ustring is returned by value; this allows you to invoke Inti::ustring methods on the temporary:
ustring foo (); foo ().method_on_ustring (); |