• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: TUTORIAL: Generating Unique ID Strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TUTORIAL: Generating Unique ID Strings


  • Subject: Re: TUTORIAL: Generating Unique ID Strings
  • From: Jens Alfke <email@hidden>
  • Date: Fri, 14 May 2010 11:09:16 -0700


On May 14, 2010, at 10:30 AM, Thomas Wetmore wrote:

I must say that I am constantly amused by the nanniness of the Apple discussion lists, telling people what is safe and what is dangerous.

I'm trying to help people out, many of whom are newbies at Cocoa or at app programming in general. It's often helpful to go beyond the immediate question.


There is nothing dangerous about bit-twiddling code. You test it til it works and then it works forever. It doesn't develop bugs later. ... This is good, honest, easy to write, easy to debug software.

I didn't see any unit tests in the code you provided ;-) And I'd want to see tests for all input lengths modulo four, as well as every length up to 8, with different bit patterns to test the carries.


Speaking of 'developing bugs later', there was plenty of code (at Apple and outside) similar to this that worked just great for years and years … until the transition to x86. Because no one had ever tested it on little-endian CPUs. Have you tested your code on both, including encoding on one architecture and decoding on the other?

Seriously, if I tried to check this in here at Google, it wouldn't pass code review. The response would be to use an existing library routine instead of re-inventing the wheel.

I'm not at all accusing you of not being smart enough to implement this! The same thing happens to me — a few months ago I wrote a cut- and-dried binary-search routine that I managed to introduce enough subtle mistakes into that it wasted most of an afternoon of debugging. In retrospect I should have just used bsearch instead. There have been plenty of dormant mistakes in 'simple' algorithms (like the unit converter in a failed Mars probe, or the insecure random-number generator in Debian's OpenSSL library) that caused huge problems later on.

In my application databases can be very large, having millions if not billions of records. The goal is that every instance of the application, wherever it is being run, will generate record ids that are not only unique to itself, but to every other instance of the application.

That's reasonable; I think 128 bits is large enough that you're not going to have any trouble with birthday-paradox collisions. But why not use a blob column for the UUID instead of converting it to ASCII?


—Jens_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >TUTORIAL: Generating Unique ID Strings (From: Bill Hernandez <email@hidden>)
 >Re: TUTORIAL: Generating Unique ID Strings (From: Jens Alfke <email@hidden>)
 >Re: TUTORIAL: Generating Unique ID Strings (From: Thomas Wetmore <email@hidden>)

  • Prev by Date: Re: NSArrayController Undo
  • Next by Date: Re: Image from WebView is sometimes blank
  • Previous by thread: Re: TUTORIAL: Generating Unique ID Strings
  • Next by thread: Re: TUTORIAL: Generating Unique ID Strings
  • Index(es):
    • Date
    • Thread