[Development] [Qt5-feedback] A micro API review: for V3(md5) and V5(sha1) in QUuid

João Abecasis joao.abecasis at nokia.com
Fri Dec 9 17:23:27 CET 2011


On 9. des. 2011, at 13.27, João Abecasis wrote:
> Lars wrote:
>> On 12/9/11 12:28 PM, "ext liang.qi at nokia.com" <liang.qi at nokia.com> wrote:
>>> 
>>> The original task is:
>>> http://bugreports.qt.nokia.com/browse/QTBUG-23071
>>> 
>>> And the change is:
>>> http://codereview.qt-project.org/10803
>>> 
>>> For the API name, we need a micro API review:
>>> Set 1:
>>> createUuidMd5()
>>> createUuidSha1()
>>> 
>>> or
>>> 
>>> createUuidMd5OrSha1()
>>> 
>>> Set2:
>>> createUuidV3()
>>> createUuidV5()
>>> 
>>> or
>>> 
>>> createUuidV3OrV5()
>>> 
>>> Any other suggestion is also welcome.
>> 
>> These names look ugly. Why not simply QUuid::createUuid(const QUuid &ns,
>> const QByteArray &baseData, Version v); ?
> 
> I don't like that one since the namespace and name version only makes sense for v3(Md5) and v5(Sha1), making all other options useless. I would prefer one name that makes explicit either the version (v3/v5), the approach (fromName) or the hash function (Md5, Sha1).
> 
> This has my vote:
> 
>    QUuid QUuid::createFromNameV3(const QUuid &, const QByteArray &);
>    QUuid QUuid::createFromNameV5(const QUuid &, const QByteArray &);

Thinking over it some more, the two function names above could instead be createUuidV3 and createUuidV5.

In that vein, we could introduce overloads for v1, v2 and v4 taking no arguments. We currently have an implementation for v4, with QUuid::createUuid(), making that trivial to implement:

    static inline QUuid createUuidV4()
    {
        return QUuid::createUuid();
    }

The other overloads,

>    inline QUuid QUuid::createFromName(const QUuid &ns, const QByteArray &name)
>    {
>        // SHA1 (v5) is recommended
>        return createFromNameV5(ns, name);
>    }
> 
>    inline QUuid QUuid::createFromName(const QUuid &ns, const QString &name)
>    {
>        return createFromName(ns, name.toUtf8());
>    }

would only be updated to call the right implementations, as appropriate.

Cheers,


João




More information about the Development mailing list