Proposal: Use UErrorCode& rather than UErrorCode* in C++ API

Alan S Liu <[email protected]> Thu, 25 Mar 2004 00:03:01 -0800
Newsgroups gmane.comp.lib.icu.general
Message-ID <OF9D374447.C8D53FF3-ON88256E62.002B89BC-88256E62.002C3F0F@us.ibm.com>
Affects ICU4C 3.0

Background:  C++ API, by convention, takes a UErrorCode& parameter.  C API 
takes a UErrorCode*.

  class Foo {
    int32_t getBar(UErrorCode& ec);
  };

  int32_t ufoo_getBar(UErrorCode* ec);

Problem:  Some C++ API has been written to take a UErrorCode* parameter. 
This is probably unintentional.  While this works, it makes the API 
inconsistent and makes C++ client code less idiomatic.  Real example, in 
Formattable:

    /**
     * Gets the double value of this object.
     * @draft ICU 2.8
     */ 
    double getDouble(UErrorCode* status) const;

Proposal:  Fix such API, if it is @draft, by making the UErrorCode 
parameter a *reference*.  For example:

    /**
     * Gets the double value of this object.
     * @draft ICU 3.0
     */ 
    double getDouble(UErrorCode& status) const;

If the API in question is @stable, add a parallel API, and deprecate the 
existing API:

    /**
     * @stable ICU 2.0
     */ 
    int32_t         getLong(UErrorCode* status) const;

Becomes:

    /**
     * @deprecated ICU 3.0 use getLong(UErrorCode&)
     */ 
    int32_t         getLong(UErrorCode* status) const;

    /**
     * @draft ICU 3.0
     */ 
    int32_t         getLong(UErrorCode& status) const;

ALTERNATIVE:  If the API in question is @draft, fix it.  But for @stable 
API, throw up our hands and let it be -- "not worth it."

[Alan S Liu/San Jose/IBM@IBMUS; [email protected];; IBM Globalization; 
5600 Cottle Road; San Jose, CA 95193;; (408) 256-3155]