f4b6a3 / uuid-creator

UUID Creator is a Java library for generating Universally Unique Identifiers.
MIT License
432 stars 44 forks source link

Deprecation of name-based methods with a UUID name parameter #91

Closed ahjohannessen closed 1 year ago

ahjohannessen commented 1 year ago

Hi @fabiolimace

I wondered why the name-based methods with a UUID name parameter are being deprecated?

We use it to derive deterministic UUIDs.

fabiolimace commented 1 year ago

Hi @ahjohannessen

Apologies for the delay.

The methods were deprecated for three reasons:

I thought no one was using these methods because they were so unusual. I couldn't find any use of these methods here on Github.

However, now that I know someone is using them, I no longer intend to deprecate them. On the contrary, I'm happy that this library is being useful. Thanks for keeping me from breaking the golden rule of public interfaces!

Soon, I will release a patch version that undoes deprecation.

P.S. The GUID.v8() method will continue deprecated and will be removed when the new RFC is finally published.

ahjohannessen commented 1 year ago

Thanks for your answer :) We changed our code to use uuid.toString, but good to know the reasoning behind the deprecation.

fabiolimace commented 1 year ago

Hi @ahjohannessen !

I just want to let you know that I changed my mind again.

The methods with UUID as the name parameter will continue deprecated.

Before the removal, UUIDs can be used as the name parameter like this:

UUID hashed = UuidCreator.getNameBasedMd5(uuid);

In the future, after the removal, you'll have to add a statement using ByteBuffer to convert the UUID into a byte array:

byte[] name = ByteBuffer.allocate(16)
                .putLong(uuid.getMostSignificantBits())
                .putLong(uuid.getLeastSignificantBits())
                .array();
UUID hashed = UuidCreator.getNameBasedMd5(name);

Alternatively, you can add a single line using BinaryCodec which is as efficient as the current method implementation, doing the same as ByteBuffer:

byte[] name = BinaryCodec.INSTANCE.encode(uuid);
UUID hashed = UuidCreator.getNameBasedMd5(name);

I know that it wont affect your project anymore as you changed to uuid.toString(). But I want to express the change in my opinion due to other developers who might think that the deprecation will be undone.

The objective is to fix a ~dumb~ mistake of mine while designing and implementing the hash-based generators. Today they only exist to confuse the users of the library by adding lots of methods which are basically the same.

Best regards.